[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Command.java, 1.72, 1.73
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2008-02-27 13:49:11
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv10685/src/net/sourceforge/bprocessor/model Modified Files: Command.java Log Message: new offset operation Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** Command.java 20 Feb 2008 13:48:28 -0000 1.72 --- Command.java 27 Feb 2008 13:49:05 -0000 1.73 *************** *** 1562,1565 **** --- 1562,1601 ---- } + /** + * + * @param boundary Edges to offset + * @param distances Distances to offset + */ + public static void offsetIt(List<Edge> boundary, Map<Edge, Double> distances) { + Vertex normal = Surface.normalOf(boundary); + Map<Vertex, Vertex> offsets = new HashMap(); + + Edge previous = boundary.get(boundary.size() - 1); + for (Edge current : boundary) { + Vertex q = Edge.commonVertex(previous, current); + Vertex p = previous.otherVertex(q); + Vertex r = current.otherVertex(q); + Vertex u = q.minus(p); + u.normalize(); + Vertex v = r.minus(q); + v.normalize(); + + double a = distances.get(previous); + double b = distances.get(current); + + Vertex d = u.scale(b).add(v.scale(-a)); + d.normalize(); + Vertex m = u.cross(normal); + double t = a / m.dot(d); + d.scaleIt(t); + offsets.put(q, d); + previous = current; + } + Collection<Vertex> vertices = Edge.vertices(boundary); + for (Vertex current : vertices) { + current.set(current.add(offsets.get(current))); + } + } + /** {@inheritDoc} */ @Override *************** *** 2020,2023 **** --- 2056,2107 ---- ParameterBlock block = net.getParameters(); System.out.println("block " + block); + + Collection<Surface> surfaces = net.getSurfaces(); + Inverse inv = new Inverse(surfaces); + List<Edge> boundary = new LinkedList(); + for (Edge current : inv.edges()) { + List<Surface> adjacent = inv.surfaces(current); + if (adjacent.size() == 1) { + boundary.add(current); + } + } + boundary = Offset.order(boundary); + Map map = new HashMap(); + + List<Edge> edges = new LinkedList(); + for (Edge current : boundary) { + edges.add((Edge) current.copy(map)); + } + + Map<Edge, Double> distances = new HashMap(); + { + double distance = block.getDouble("frame-width"); + for (Edge current : boundary) { + ParameterBlock params = current.getParameters(); + double d = distance; + if (params != null) { + Double param = (Double) params.get("width"); + if (param != null) { + d = param.doubleValue(); + } + } + Edge edge = (Edge) map.get(current); + distances.put(edge, d); + } + } + Offset.offsetIt(edges, distances); + + Collection<Vertex> vertices = Edge.vertices(edges); + + Container union = new Container("Frame", Space.CONSTRUCTION, true); + union.setUnion(true); + for (Vertex current : vertices) { + union.add(current); + } + for (Edge current : edges) { + union.add(current); + } + Project.getInstance().getActiveSpace().add(union); + Project.getInstance().changed(Project.getInstance()); } } |