Thread: [Bprocessor-commit] gl/src/net/sourceforge/bprocessor/gl/tool FinalMoveTool.java, 1.21, 1.22
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-09-07 10:52:36
|
Update of /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv20228/src/net/sourceforge/bprocessor/gl/tool Modified Files: FinalMoveTool.java Log Message: Refactored finalmove tool Index: FinalMoveTool.java =================================================================== RCS file: /cvsroot/bprocessor/gl/src/net/sourceforge/bprocessor/gl/tool/FinalMoveTool.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** FinalMoveTool.java 6 Sep 2007 09:15:35 -0000 1.21 --- FinalMoveTool.java 7 Sep 2007 10:52:23 -0000 1.22 *************** *** 37,49 **** private Collection<Geometric> geometrics; ! private Collection<Vertex> vertices; private Collection<Geometric> affected; - private Vertex last; private boolean copy; private Mesh mesh; private Vertex direction; ! private Map<Vertex, Vertex> originals; ! private Map<Vertex, Direction> slide; --- 37,49 ---- private Collection<Geometric> geometrics; ! private Collection<Geometric> affected; private boolean copy; private Mesh mesh; private Vertex direction; ! ! private Collection<Vertex> vertices; ! private MoveHandle handle; *************** *** 57,110 **** } ! ! ! ! private Map<Vertex, Direction> computeDirectionMap(Collection<Vertex> vertices) { ! if (vertices.size() > 0) { ! Space space = vertices.iterator().next().getOwner(); ! Map<Vertex, Direction> slidemap = new HashMap(); ! Map<Vertex, Collection<Edge>> edgemap = space.edgeMap(vertices); ! ! for (Vertex current : vertices) { ! Collection<Edge> edges = edgemap.get(current); ! Direction direction; ! if (edges.size() == 0) { ! direction = new Direction(current.copy(), null); ! } else if (edges.size() == 1) { ! Edge edge = edges.iterator().next(); ! Vertex to = edge.otherVertex(current); ! Vertex v = to.minus(current); ! double length = v.length(); ! v.scale(1 / length); ! direction = new Direction(current.copy(), v, Double.NEGATIVE_INFINITY, length); ! } else { ! direction = new Direction(current.copy(), null, 0, 0); } - slidemap.put(current, direction); } - return slidemap; - } else { - return null; } ! } ! ! private void computePlanes(Collection<Vertex> vertices) { ! if (vertices.size() > 0) { ! Space space = vertices.iterator().next().getOwner(); ! Set<Vertex> mark = new HashSet(); ! Set<Edge> edges = new HashSet(); ! Set<Surface> surfaces = new HashSet(); ! mark.addAll(vertices); ! for (Edge current : space.getEdges()) { ! if (mark.contains(current.getFrom()) && mark.contains(current.getTo())) { ! edges.add(current); } } ! for (Surface current : space.getSurfaces()) { ! if (edges.containsAll(current.getEdges())) { ! surfaces.add(current); } } } } --- 57,168 ---- } ! /** ! * Move Handle ! * ! */ ! public class MoveHandle { ! private Collection<Vertex> vertices; ! private Map<Vertex, Vertex> originals; ! private Map<Vertex, Direction> slide; ! ! private void computePlanes(Collection<Vertex> vertices) { ! if (vertices.size() > 0) { ! Space space = vertices.iterator().next().getOwner(); ! Set<Vertex> mark = new HashSet(); ! Set<Edge> edges = new HashSet(); ! Set<Surface> surfaces = new HashSet(); ! mark.addAll(vertices); ! for (Edge current : space.getEdges()) { ! if (mark.contains(current.getFrom()) && mark.contains(current.getTo())) { ! edges.add(current); ! } ! } ! for (Surface current : space.getSurfaces()) { ! if (edges.containsAll(current.getEdges())) { ! surfaces.add(current); ! } } } } ! ! private Map<Vertex, Direction> computeDirectionMap(Collection<Vertex> vertices) { ! if (vertices.size() > 0) { ! Space space = vertices.iterator().next().getOwner(); ! Map<Vertex, Direction> slidemap = new HashMap(); ! Map<Vertex, Collection<Edge>> edgemap = space.edgeMap(vertices); ! ! for (Vertex current : vertices) { ! Collection<Edge> edges = edgemap.get(current); ! Direction direction; ! if (edges.size() == 0) { ! direction = new Direction(current.copy(), null); ! } else if (edges.size() == 1) { ! Edge edge = edges.iterator().next(); ! Vertex to = edge.otherVertex(current); ! Vertex v = to.minus(current); ! double length = v.length(); ! v.scale(1 / length); ! direction = new Direction(current.copy(), v, Double.NEGATIVE_INFINITY, length); ! } else { ! direction = new Direction(current.copy(), null, 0, 0); ! } ! slidemap.put(current, direction); } + return slidemap; + } else { + return null; } ! } ! ! /** ! * Constructor ! * @param vertices Collection of vertices to move ! */ ! public MoveHandle(Collection<Vertex> vertices) { ! this.vertices = vertices; ! originals = new HashMap(); ! for (Vertex current : vertices) { ! originals.put(current, current.copy()); ! } ! slide = computeDirectionMap(vertices); ! computePlanes(vertices); ! } ! /** ! * Move ! * @param delta Vector distance to move ! */ ! public void move(Vertex delta) { ! for (Vertex current : vertices) { ! Vertex original = originals.get(current); ! current.set(original.add(delta)); ! if (slide != null) { ! Direction direction = slide.get(current); ! Vertex n = direction.getDirection(); ! if (n != null) { ! Vertex v = current.minus(original); ! double t = n.dot(v); ! if (t > direction.upper()) { ! t = direction.upper(); ! } ! if (t < direction.lower()) { ! t = direction.lower(); ! } ! Vertex u = n.copy(); ! u.scale(t); ! current.set(original.add(u)); ! } } } } + + /** + * Revert to original position + */ + public void revert() { + for (Vertex current : vertices) { + Vertex original = originals.get(current); + current.set(original); + } + } } *************** *** 132,167 **** } private void move() { current = current.copy(); ! last = current.vertex(); ! move(vertices, current.vertex().minus(start.vertex())); updateFeedback(); } - - private void move(Collection<Vertex> vertices, Vertex delta) { - for (Vertex current : vertices) { - Vertex original = originals.get(current); - current.set(original.add(delta)); - if (slide != null) { - Direction direction = slide.get(current); - Vertex n = direction.getDirection(); - if (n != null) { - Vertex v = current.minus(original); - double t = n.dot(v); - if (t > direction.upper()) { - t = direction.upper(); - } - if (t < direction.lower()) { - t = direction.lower(); - } - Vertex u = n.copy(); - u.scale(t); - current.set(original.add(u)); - } - } - } - } - /** {@inheritDoc} */ @Override --- 190,204 ---- } + private void move(Vertex delta) { + handle.move(delta); + } + private void move() { current = current.copy(); ! direction = current.vertex().minus(start.vertex()); ! move(direction); updateFeedback(); } /** {@inheritDoc} */ @Override *************** *** 239,252 **** vertices = Geometry.collect(geometrics); ! originals = new HashMap(); ! for (Vertex current : vertices) { ! originals.put(current, current.copy()); ! } ! slide = computeDirectionMap(vertices); ! computePlanes(vertices); affected = getAffected(geometrics); current = findIntersection(e); start = current.copy(); - last = current.vertex(); updateFeedback(); setTip(secondClickTip()); --- 276,284 ---- vertices = Geometry.collect(geometrics); ! handle = new MoveHandle(vertices); ! affected = getAffected(geometrics); current = findIntersection(e); start = current.copy(); updateFeedback(); setTip(secondClickTip()); *************** *** 256,260 **** if (copy) { owner.removeProtected(geometrics); - direction = last.minus(start.vertex()); owner.insert(mesh); geometrics = null; --- 288,291 ---- *************** *** 306,313 **** public void cleanUp() { if (start != null) { ! for (Vertex current : vertices) { ! Vertex original = originals.get(current); ! current.set(original); ! } } super.cleanUp(); --- 337,341 ---- public void cleanUp() { if (start != null) { ! handle.revert(); } super.cleanUp(); *************** *** 320,325 **** affected = null; copy = false; ! originals = null; ! slide = null; } --- 348,352 ---- affected = null; copy = false; ! handle = null; } |