Mercurial > projects > dwt-addons
comparison dwtx/draw2d/graph/CollapsedEdges.d @ 98:95307ad235d9
Added Draw2d code, still work in progress
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 03 Aug 2008 00:52:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
96:b492ba44e44d | 98:95307ad235d9 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module dwtx.draw2d.graph.CollapsedEdges; | |
14 | |
15 import dwt.dwthelper.utils; | |
16 import dwtx.draw2d.graph.Edge; | |
17 | |
18 /** | |
19 * Contains the information from all edges going from a given cluster to some other | |
20 * cluster. An edge with minimal slack as chosen to maintain the link between clusters. | |
21 * The weight and any slack more than the minimal edge's slack is tracked for all other | |
22 * edges. | |
23 * @since 3.1 | |
24 */ | |
25 class CollapsedEdges { | |
26 | |
27 /** | |
28 * The total weight of the collapsed edges. | |
29 */ | |
30 int collapsedWeight; | |
31 int collapsedCount; | |
32 | |
33 /** | |
34 * The total amount of weighted difference in the collapsed edges slack and the | |
35 * tightest edge's slack. | |
36 */ | |
37 int overage; | |
38 int unOverage; | |
39 Edge tightestEdge; | |
40 | |
41 this(Edge edge) { | |
42 tightestEdge = edge; | |
43 collapsedWeight = edge.weight; | |
44 collapsedCount++; | |
45 } | |
46 | |
47 public int getWeightedPull() { | |
48 return tightestEdge.getSlack() * collapsedWeight + overage; | |
49 } | |
50 | |
51 public bool isTight() { | |
52 return tightestEdge.getSlack() is 0; | |
53 } | |
54 | |
55 /** | |
56 * Compares the given edge to the current tightest edge. If the given edge is tighter | |
57 * than the current, the current tightest is returned. Otherwise, the edge itself is | |
58 * returned. The returned edge would be the one to remove from the graph. | |
59 * @param candidate another edge | |
60 * @return the edge which is not the tightest edge | |
61 * @since 3.1 | |
62 */ | |
63 Edge processEdge(Edge candidate) { | |
64 collapsedCount++; | |
65 if (candidate.getSlack() < tightestEdge.getSlack()) { | |
66 overage += collapsedWeight * (tightestEdge.getSlack() - candidate.getSlack()); | |
67 Edge temp = tightestEdge; | |
68 tightestEdge = candidate; | |
69 collapsedWeight += candidate.weight; | |
70 return temp; | |
71 } else { | |
72 int over = candidate.getSlack() - tightestEdge.getSlack(); | |
73 unOverage += over; | |
74 overage += candidate.weight * over; | |
75 collapsedWeight += candidate.weight; | |
76 return candidate; | |
77 } | |
78 } | |
79 } |