comparison dwtx/draw2d/graph/SpanningTreeVisitor.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) 2003, 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.SpanningTreeVisitor;
14
15 import dwt.dwthelper.utils;
16 import dwtx.draw2d.graph.GraphVisitor;
17 import dwtx.draw2d.graph.Edge;
18 import dwtx.draw2d.graph.Node;
19 import dwtx.draw2d.graph.EdgeList;
20
21 /**
22 * A base class for visitors which operate on the graphs spanning tree used to induce rank
23 * assignments.
24 * @author Randy Hudson
25 * @since 2.1.2
26 */
27 abstract class SpanningTreeVisitor : GraphVisitor {
28
29 Edge getParentEdge(Node node) {
30 return cast(Edge)node.workingData[1];
31 }
32
33 EdgeList getSpanningTreeChildren(Node node) {
34 return cast(EdgeList)node.workingData[0];
35 }
36
37 protected Node getTreeHead(Edge edge) {
38 if (getParentEdge(edge.source) is edge)
39 return edge.target;
40 return edge.source;
41 }
42
43 Node getTreeParent(Node node) {
44 Edge e = getParentEdge(node);
45 if (e is null)
46 return null;
47 return e.opposite(node);
48 }
49
50 protected Node getTreeTail(Edge edge) {
51 if (getParentEdge(edge.source) is edge)
52 return edge.source;
53 return edge.target;
54 }
55
56 void setParentEdge(Node node, Edge edge) {
57 node.workingData[1] = edge;
58 }
59
60 }