[Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool PencilTool.java, 1.69, 1.70
Status: Pre-Alpha
Brought to you by:
henryml
|
From: Michael L. <he...@us...> - 2006-12-07 23:06:04
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv29685/src/net/sourceforge/bprocessor/gl/tool Modified Files: PencilTool.java Log Message: Moved direction(edges, system) from PencilTool to Surface Index: PencilTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/PencilTool.java,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** PencilTool.java 5 Dec 2006 15:21:13 -0000 1.69 --- PencilTool.java 7 Dec 2006 23:06:02 -0000 1.70 *************** *** 436,446 **** if (edges.size() > 2) { System.out.println("left surface:" + edges); ! int turn = direction(edges, system); ! if (turn == LEFT) { System.out.println("turns left"); Surface surface = new Surface(edges); Project.getInstance().getActiveSpace().add(surface); } ! if (turn == RIGHT) { System.out.println("turns right"); } --- 436,446 ---- if (edges.size() > 2) { System.out.println("left surface:" + edges); ! int turn = Surface.direction(edges, system); ! if (turn == Surface.LEFT) { System.out.println("turns left"); Surface surface = new Surface(edges); Project.getInstance().getActiveSpace().add(surface); } ! if (turn == Surface.RIGHT) { System.out.println("turns right"); } *************** *** 463,471 **** if (edges.size() > 2) { System.out.println("right surface:" + edges); ! int turn = direction(edges, system); ! if (turn == LEFT) { System.out.println("turns left"); } ! if (turn == RIGHT) { System.out.println("turns right"); Surface surface = new Surface(edges); --- 463,471 ---- if (edges.size() > 2) { System.out.println("right surface:" + edges); ! int turn = Surface.direction(edges, system); ! if (turn == Surface.LEFT) { System.out.println("turns left"); } ! if (turn == Surface.RIGHT) { System.out.println("turns right"); Surface surface = new Surface(edges); *************** *** 476,533 **** } - /** LEFT means counterclockwise */ - public static final int LEFT = 1; - /** RIGHT means clockwise */ - public static final int RIGHT = 2; - /** PARALLEL means not turning */ - public static final int PARALLEL = 3; - - /** - * Find the turn direction of the edges - * @param edges list of Edge - * @param system CoordinateSystem - * @return direction (LEFT or RIGHT) - */ - public int direction(List edges, CoordinateSystem system) { - double y = Double.MAX_VALUE; - Edge e1 = null; - Edge e2 = null; - Edge previous = (Edge) edges.get(edges.size() - 1); - Iterator iter = edges.iterator(); - while (iter.hasNext()) { - Edge current = (Edge) iter.next(); - Vertex v = Edge.commonVertex(previous, current); - v = system.translate(v); - if (v.getY() <= y) { - y = v.getY(); - e1 = previous; - e2 = current; - } - previous = current; - } - Vertex common = Edge.commonVertex(e1, e2); - Vertex from = e1.otherVertex(common); - Vertex to = e2.otherVertex(common); - from = system.translate(from); - common = system.translate(common); - to = system.translate(to); - Vertex u = common.minus(from); - Vertex v = to.minus(common); - Vertex cross = u.cross(v); - double determinant = cross.getZ(); - // if the cross points into the screen (along the negative z), - // the vectors are doing a right turn. Otherwise they are doing - // a left turn. If the cross are zero, they er parallel, but the - // above code should ensure that does not happen assuming the - // edges has a nonzero area. - if (determinant < 0) { - return RIGHT; - } - if (determinant > 0) { - return LEFT; - } - return PARALLEL; - } - /** * VertexNode --- 476,479 ---- |