[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Command.java, 1.49, 1.50
Status: Pre-Alpha
Brought to you by:
henryml
From: Michael L. <he...@us...> - 2007-12-09 12:10:35
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv23886/src/net/sourceforge/bprocessor/model Modified Files: Command.java Log Message: vertical net intersects with holes Index: Command.java =================================================================== RCS file: /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model/Command.java,v retrieving revision 1.49 retrieving revision 1.50 diff -C2 -d -r1.49 -r1.50 *** Command.java 9 Dec 2007 11:04:01 -0000 1.49 --- Command.java 9 Dec 2007 12:10:32 -0000 1.50 *************** *** 10,13 **** --- 10,15 ---- import java.util.ArrayList; import java.util.Collection; + import java.util.Collections; + import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; *************** *** 1643,1647 **** } ! private Space createVerticalNet(Surface surface, double xdistance) { Space net = Space.createNet("Vertical Net"); HashMap map = new HashMap(); --- 1645,1649 ---- } ! private Space createVertical(Surface surface, double dx) { Space net = Space.createNet("Vertical Net"); HashMap map = new HashMap(); *************** *** 1651,1654 **** --- 1653,1661 ---- contour.add((Edge) current.copy(map)); } + for (Surface hole : surface.getHoles()) { + for (Edge current : hole.getEdges()) { + contour.add((Edge) current.copy(map)); + } + } Vertex vertex = surface.getFirstVertex(); *************** *** 1656,1725 **** 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 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 < (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); - return net; } --- 1663,1765 ---- CoordinateSystem system = CoordinateSystem.systemFor(vertex, normal); + List<Vertex> vertices = new LinkedList(Edge.vertices(contour)); + List<Vertex> locals = system.translate(vertices); + for (int i = 0; i < vertices.size(); i++) { + Vertex current = vertices.get(i); + Vertex local = locals.get(i); + current.set(local); + } + double xmin = Double.MAX_VALUE; double xmax = Double.MIN_VALUE; double ymin = Double.MAX_VALUE; double ymax = Double.MIN_VALUE; ! for (Vertex current : locals) { ! if (current.getX() < xmin) { ! xmin = current.getX(); } ! if (current.getX() > xmax) { ! xmax = current.getX(); } ! if (current.getY() < ymin) { ! ymin = current.getY(); } ! if (current.getY() > ymax) { ! ymax = current.getY(); } } ! ! double width = xmax - xmin; ! ! int n = round(width / dx); List<Edge> verticals = new LinkedList(); ! for (int i = 0; i < n; i++) { ! double x = xmin + (i + 1) * dx; ! Vertex from = new Vertex(x, ymin, 0); ! Vertex to = new Vertex(x, ymax, 0); ! Edge edge = new Edge(from, to); ! List<Vertex> intersections = new LinkedList(); ! for (Edge current : contour) { ! double x0 = current.from.x; ! double x1 = current.to.x; ! if (x0 > x1) { ! double tmp = x1; ! x1 = x0; ! x0 = tmp; ! } ! if (x0 <= x && x < x1) { ! Edge intersect = current.intersection(edge); ! if (intersect != null) { ! if (intersect.getLength() < 0.0000001) { ! intersections.add(intersect.from); } } } ! } ! final Comparator<Vertex> comparator = new Comparator<Vertex>() { ! public int compare(Vertex v1, Vertex v2) { ! if (v1.y == v2.y) { ! return 0; ! } else if (v1.y < v2.y) { ! return -1; ! } else { ! return 1; } } + }; + + if (intersections.size() > 0) { + Collections.sort(intersections, comparator); + Iterator<Vertex> iter = intersections.iterator(); + for (int j = 0; j < (intersections.size() / 2); j++) { + Vertex f = iter.next(); + Vertex t = iter.next(); + verticals.add(new Edge(f, t)); + } } } + { + List<Vertex> verts = new ArrayList(Edge.vertices(verticals)); + List<Vertex> globals = system.unTranslate(verts); + for (int i = 0; i < verts.size(); i++) { + Vertex current = verts.get(i); + Vertex global = globals.get(i); + current.set(global); + } + } + { + List<Vertex> verts = new ArrayList(Edge.vertices(contour)); + List<Vertex> globals = system.unTranslate(verts); + for (int i = 0; i < verts.size(); i++) { + Vertex current = verts.get(i); + Vertex global = globals.get(i); + current.set(global); + } + } Geometry.insertEdges(net, contour); Geometry.insertEdges(net, verticals); return net; } *************** *** 1852,1856 **** net = createGrid(surface, xdistance, ydistance); } else { ! net = createVerticalNet(surface, xdistance); } Space owner = surface.getOwner(); --- 1892,1896 ---- net = createGrid(surface, xdistance, ydistance); } else { ! net = createVertical(surface, xdistance); } Space owner = surface.getOwner(); |