Thread: [Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Edge.java, 1.52, 1.53
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2006-08-28 14:48:35
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20236/src/net/sourceforge/bprocessor/model Modified Files: Edge.java Log Message: Added offset method to Edge and made tests for it Index: Edge.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Edge.java,v retrieving revision 1.52 retrieving revision 1.53 diff -C2 -d -r1.52 -r1.53 *** Edge.java 24 Aug 2006 11:51:10 -0000 1.52 --- Edge.java 28 Aug 2006 14:48:25 -0000 1.53 *************** *** 11,14 **** --- 11,15 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; *************** *** 70,74 **** * Extract all vertices from a collection of edges * @param edges Collection of edges ! * @return Collection of vertices */ public static Collection vertices(Collection edges) { --- 71,75 ---- * Extract all vertices from a collection of edges * @param edges Collection of edges ! * @return Collection of vertices in random order */ public static Collection vertices(Collection edges) { *************** *** 345,348 **** --- 346,357 ---- } + /** + * Give a string that works even if the edge and its vertexes are not in the model + * @return The debug string + */ + public String debugString() { + return "[" + from.toString() + " -> " + to.toString() + "]"; + } + /** * Gets all surfaces this edge is a part of. *************** *** 530,540 **** * Create a offset from a list of lines and a surface * PRECONDITION: all the edges have to be in the given surface ! * @param edges The list of edges * @param inner The surface ! * @param framewidth The offset positive inside and negative outside * @return The generated list of lines */ ! public static List offset(List edges, Surface inner, double framewidth) { ! // TODO Auto-generated method stub return null; } --- 539,663 ---- * Create a offset from a list of lines and a surface * PRECONDITION: all the edges have to be in the given surface ! * @param which The list of edges in inner that are going to be offset * @param inner The surface ! * @param offset The offset negative inside and positive outside * @return The generated list of lines */ ! public static List offset(List which, Surface inner, double offset) { ! HashSet edges = new HashSet(which); ! ArrayList res = new ArrayList(); ! HashMap directions = new HashMap(); ! HashMap to2edge = new HashMap(); ! HashMap from2edge = new HashMap(); ! HashMap v2v = new HashMap(); ! Iterator iter = inner.getEdges().iterator(); ! ! Edge prevEdge = null; ! // Find all the affected vertexes and make the edges ! while (iter.hasNext()) { ! Edge e = (Edge)iter.next(); ! if (edges.contains(e)) { ! Vertex to, from; ! if (!directions.containsKey(e.getFrom())) { ! from = e.getFrom().copy(); ! directions.put(e.getFrom(), new Direction(from, null)); ! } else { ! from = ((Direction)directions.get(e.getFrom())).getVertex(); ! } ! if (!directions.containsKey(e.getTo())) { ! to = e.getTo().copy(); ! directions.put(e.getTo(), new Direction(to, null)); ! } else { ! to = ((Direction)directions.get(e.getTo())).getVertex(); ! } ! v2v.put(to, e.getTo()); ! v2v.put(from, e.getFrom()); ! res.add(new Edge(to, from)); ! Vertex common = Edge.commonVertex(e, prevEdge); ! if (common == e.getFrom() || common == null) { ! from2edge.put(e.getFrom(), e); ! to2edge.put(e.getTo(), e); ! } else { ! from2edge.put(e.getTo(), e); ! to2edge.put(e.getFrom(), e); ! } ! } else { ! from2edge.put(e.getFrom(), e); ! to2edge.put(e.getTo(), e); ! } ! prevEdge = e; ! } ! // calculate the directions ! iter = directions.values().iterator(); ! while (iter.hasNext()) { ! Direction dir = (Direction)iter.next(); ! Vertex work = (Vertex)v2v.get(dir.getVertex()); ! Vertex normal = inner.normal(); ! Edge e1 = (Edge)to2edge.get(work); ! Edge e2 = (Edge)from2edge.get(work); ! if (edges.contains(e1)) { ! if (edges.contains(e2)) { ! // have to follow a split way ! Vertex dir1 = work.minus(e1.otherVertex(work)); ! dir1 = dir1.cross(normal); ! dir1.normalize(); ! Vertex dir2 = e2.otherVertex(work).minus(work); ! dir2 = dir2.cross(normal); ! dir2.normalize(); ! Vertex mainDir = dir1.add(dir2); ! mainDir.scale(1 / mainDir.dot(dir1)); ! dir.setDirection(mainDir); ! } else { ! // have to follow the firstEdge direction ! Vertex dir1 = work.minus(e1.otherVertex(work)); ! dir1 = dir1.cross(normal); ! dir1.normalize(); ! Vertex other = e2.otherVertex(work); ! Vertex dir2 = other.minus(work); ! dir2.normalize(); ! dir2.scale(1 / dir2.dot(dir1)); ! dir.setDirection(dir2); ! } ! } else if (edges.contains(e2)) { ! // have to follow the prevEdge direction ! Vertex dir2 = e2.otherVertex(work).minus(work); ! dir2 = dir2.cross(normal); ! dir2.normalize(); ! Vertex other = e1.otherVertex(work); ! Vertex dir1 = other.minus(work); ! dir1.normalize(); ! dir1.scale(1 / dir1.dot(dir2)); ! dir.setDirection(dir1); ! } ! } ! ! Iterator diriter = directions.values().iterator(); ! while (diriter.hasNext()) { ! Direction cur = (Direction)diriter.next(); ! Vertex dir = cur.getDirection(); ! dir.scale(offset); ! cur.getVertex().move(dir.getX(), dir.getY(), dir.getZ()); ! } ! ! return res; ! } ! ! /** ! * Find the common edge of the two given edges, if ther is one ! * otherwise it just return null ! * @param e1 The first edge ! * @param e2 The second edge ! * @return The common vertex or null if none ! */ ! private static Vertex commonVertex(Edge e1, Edge e2) { ! if (e1 == null || e2 == null) { ! return null; ! } ! if (e2.contains(e1.getFrom())) { ! return e1.getFrom(); ! } ! if (e2.contains(e1.getTo())) { ! return e1.getTo(); ! } return null; } |