Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv30719/src/net/sourceforge/bprocessor/model
Modified Files:
Surface.java
Log Message:
Added method to replace a segment of edges with one new edge, also an equalEps method, and some generics
Index: Surface.java
===================================================================
RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Surface.java,v
retrieving revision 1.149
retrieving revision 1.150
diff -C2 -d -r1.149 -r1.150
*** Surface.java 29 Mar 2007 12:51:05 -0000 1.149
--- Surface.java 29 Mar 2007 13:57:14 -0000 1.150
***************
*** 354,357 ****
--- 354,373 ----
}
+ /** Replaces a set of edges in this surface with a single edge
+ * @param replacedEdges Set of edges to replace
+ * @param newEdge the edge to replace with
+ */
+ public void replace(List<Edge> replacedEdges, Edge newEdge) {
+ List<Edge> currentEdges = new LinkedList<Edge>(getEdges());
+ if (!replacedEdges.isEmpty() &&
+ currentEdges.containsAll(replacedEdges)) {
+ Edge oldEdge = replacedEdges.iterator().next();
+ int index = currentEdges.indexOf(oldEdge);
+ currentEdges.set(index, newEdge);
+ currentEdges.removeAll(replacedEdges);
+ setEdges(currentEdges);
+ }
+ }
+
/**
* Replace one edge e1 and its vertices with e2's
***************
*** 489,493 ****
* class="net.sourceforge.bprocessor.model.Surface"
*/
! public Collection getHoles() {
if (holes == null) {
return Collections.EMPTY_LIST;
--- 505,509 ----
* class="net.sourceforge.bprocessor.model.Surface"
*/
! public Collection<Surface> getHoles() {
if (holes == null) {
return Collections.EMPTY_LIST;
***************
*** 1671,1674 ****
--- 1687,1717 ----
return getName() + "[" + edges.size() + "]";
}
+
+ /**
+ * Tests if all edges of this surface has the same coordinates
+ * as all those of another surface.
+ * @param s another surface
+ * @return true if all edges have same coordinates
+ */
+ public boolean equalEps(Surface s) {
+ List<Edge> thisEdgeList = this.getEdges();
+ List<Edge> otherEdgeList = new LinkedList(s.getEdges());
+ for (Edge e1 : thisEdgeList) {
+ boolean match = false;
+ for (Edge e2 : otherEdgeList) {
+ if ((e1.from.equalEps(e2.from) ||
+ e1.from.equalEps(e2.to)) &&
+ (e1.to.equalEps(e2.from) ||
+ e1.to.equalEps(e2.to))) {
+ match = true;
+ break;
+ }
+ }
+ if (!match) {
+ return false;
+ }
+ }
+ return true;
+ }
|