[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Geometry.java, 1.65, 1.66 Command.ja
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-12-03 15:01:42
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv15159/src/net/sourceforge/bprocessor/model Modified Files: Geometry.java Command.java Log Message: command to insert a net based on a surface Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** Command.java 2 Dec 2007 12:02:14 -0000 1.45 --- Command.java 3 Dec 2007 15:01:37 -0000 1.46 *************** *** 12,15 **** --- 12,16 ---- import java.util.HashMap; import java.util.HashSet; + import java.util.Iterator; import java.util.LinkedList; import java.util.List; *************** *** 1532,1534 **** --- 1533,1638 ---- } } + + /** + * + */ + public static class InsertNet extends Command { + /** + * + * @param surface Surface + */ + public InsertNet(Surface surface) { + parameters.put("surface", surface); + parameters.put("x distance", 0.5); + } + /** {@inheritDoc} */ + @Override + public void evaluate() { + Surface surface = (Surface) parameters.get("surface"); + double xdistance = parameters.getDouble("x distance"); + Space owner = surface.getOwner(); + + Space net = Space.createNet(""); + HashMap map = new HashMap(); + + List<Edge> contour = new LinkedList(); + for (Edge current : surface.getEdges()) { + contour.add((Edge) current.copy(map)); + } + + + + Vertex vertex = surface.getFirstVertex(); + Vertex normal = surface.normal(); + CoordinateSystem system = CoordinateSystem.systemFor(vertex, normal); + + double xmin = Double.MAX_VALUE; + double xmax = Double.MIN_VALUE; + double ymin = Double.MAX_VALUE; + double ymax = Double.MIN_VALUE; + for (Vertex current : Edge.vertices(contour)) { + Vertex local = system.translate(current); + if (local.getX() < xmin) { + xmin = local.getX(); + } + if (local.getX() > xmax) { + xmax = local.getX(); + } + if (local.getY() < ymin) { + ymin = local.getY(); + } + if (local.getY() > ymax) { + ymax = local.getY(); + } + } + Vertex min = system.unTranslate(new Vertex(xmin, ymin, 0)); + Vertex max = system.unTranslate(new Vertex(xmax, xmax, 0)); + Vertex origin = min; + + List<Edge> verticals = new LinkedList(); + + { + + double delta = (xmax - xmin) / xdistance; + int n = (int) Math.floor(delta); + double rest = delta - n; + if (rest < 0.0000001) { + n--; + } + origin = min; + for (int i = 0; i < n; i++) { + origin = origin.add(system.getI().scale(xdistance)); + Line line = new Line(origin, system.getJ()); + List<Vertex> intersections = new LinkedList(); + + for (Edge edge : contour) { + Edge e = system.translate(edge); + Vertex o = system.translate(origin); + double x0 = Math.min(e.from.x, e.to.x); + double x1 = Math.max(e.from.x, e.to.x); + if (x0 <= o.x && o.x < x1) { + Edge intersect = edge.intersection(line.edge(ymax - ymin)); + if (intersect != null) { + if (intersect.getLength() < 0.0000001) { + intersections.add(intersect.getFrom()); + } + } + } + } + if (intersections.size() > 0) { + for (int j = 0; j < (int) (intersections.size() / 2); j++) { + Iterator<Vertex> iter = intersections.iterator(); + Vertex from = iter.next(); + Vertex to = iter.next(); + verticals.add(new Edge(from, to)); + } + } + } + } + + Geometry.insertEdges(net, contour); + Geometry.insertEdges(net, verticals); + owner.add(net); + } + } } Index: Geometry.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Geometry.java,v retrieving revision 1.65 retrieving revision 1.66 diff -C2 -d -r1.65 -r1.66 *** Geometry.java 13 Nov 2007 12:19:29 -0000 1.65 --- Geometry.java 3 Dec 2007 15:01:37 -0000 1.66 *************** *** 425,435 **** } /** ! * Insert a number edges into the model ! * @param edges List of edges ! * @return List of the surfaces created (empty list if none) */ ! public static List<Surface> insertEdges(List<Edge> edges) { ! Space space = Project.getInstance().getActiveSpace(); List<Surface> result = new LinkedList(); --- 425,436 ---- } + /** ! * Insert a list of edges into the space ! * @param space the space ! * @param edges the list of edges ! * @return list of created surfaces */ ! public static List<Surface> insertEdges(Space space, List<Edge> edges) { List<Surface> result = new LinkedList(); *************** *** 440,443 **** --- 441,454 ---- return result; } + + /** + * Insert a number edges into the model + * @param edges List of edges + * @return List of the surfaces created (empty list if none) + */ + public static List<Surface> insertEdges(List<Edge> edges) { + Space space = Project.getInstance().getActiveSpace(); + return insertEdges(space, edges); + } /** |