Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv31204/src/net/sourceforge/bprocessor/model
Modified Files:
Edge.java
Log Message:
commit added method to find runs of parrallel and connected edges
Index: Edge.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v
retrieving revision 1.87
retrieving revision 1.88
diff -C2 -d -r1.87 -r1.88
*** Edge.java 23 Apr 2007 14:47:59 -0000 1.87
--- Edge.java 7 May 2007 15:41:35 -0000 1.88
***************
*** 11,14 ****
--- 11,15 ----
import java.util.ArrayList;
import java.util.Collection;
+ import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
***************
*** 46,50 ****
/**
* Return the first vertex in a list of edges.
! * The first vertex is defined as the a vertex
* in the first edge that are not shared with the
* second edge
--- 47,51 ----
/**
* Return the first vertex in a list of edges.
! * The first vertex is defined as the vertex
* in the first edge that are not shared with the
* second edge
***************
*** 1124,1126 ****
--- 1125,1171 ----
move(delta.getX(), delta.getY(), delta.getZ());
}
+
+ /**
+ * Finds the longest run of parrallel edges connected to this edge.
+ * @return a list of connected parrallel edges. The edges will be sorted so that
+ * the first edge is the furthest away from this edge in the to->from direction
+ */
+ public List<Edge> parrallelRun() {
+ Edge currentEdge = this;
+ Vertex currentVertex = this.getTo();
+ List<Edge> run = new LinkedList<Edge>();
+ while (currentEdge != null) {
+ run.add(currentEdge);
+ currentVertex = currentEdge.otherVertex(currentVertex);
+ Set<Edge> edges = currentVertex.getEdges();
+ Edge nextEdge = null;
+ for (Edge e : edges) {
+ if (e.parrallel(currentEdge) &&
+ e != currentEdge) {
+ nextEdge = e;
+ break;
+ }
+ }
+ currentEdge = nextEdge;
+ }
+ Collections.reverse(run);
+ run.remove(this);
+ currentEdge = this;
+ currentVertex = this.getFrom();
+ while (currentEdge != null) {
+ run.add(currentEdge);
+ currentVertex = currentEdge.otherVertex(currentVertex);
+ Set<Edge> edges = currentVertex.getEdges();
+ Edge nextEdge = null;
+ for (Edge e : edges) {
+ if (e.parrallel(currentEdge) &&
+ e != currentEdge) {
+ nextEdge = e;
+ break;
+ }
+ }
+ currentEdge = nextEdge;
+ }
+ return run;
+ }
}
|