Changeset 34850 in osm for applications/editors/josm/plugins/buildings_tools
- Timestamp:
- 2019-01-21T10:30:46+01:00 (6 years ago)
- Location:
- applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/AngleSnap.java
r34572 r34850 25 25 public final Double addSnap(Node[] nodes) { 26 26 if (nodes.length == 2) { 27 EastNorth p1, p2; 28 p1 = latlon2eastNorth(nodes[0].getCoor()); 29 p2 = latlon2eastNorth(nodes[1].getCoor()); 27 EastNorth p1 = latlon2eastNorth(nodes[0].getCoor()); 28 EastNorth p2 = latlon2eastNorth(nodes[1].getCoor()); 30 29 double heading = p1.heading(p2); 31 30 addSnap(heading); … … 39 38 public final void addSnap(Way way) { 40 39 for (Pair<Node, Node> pair : way.getNodePairs(false)) { 41 EastNorth a, b; 42 a = latlon2eastNorth(pair.a.getCoor()); 43 b = latlon2eastNorth(pair.b.getCoor()); 40 EastNorth a = latlon2eastNorth(pair.a.getCoor()); 41 EastNorth b = latlon2eastNorth(pair.b.getCoor()); 44 42 double heading = a.heading(b); 45 43 addSnap(heading); -
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/Building.java
r34807 r34850 44 44 private final EastNorth[] en = new EastNorth[4]; 45 45 46 double meter = 0;47 48 private double len = 0;46 double meter; 47 48 private double len; 49 49 private double width; 50 50 private double heading; 51 51 private AngleSnap angleSnap = new AngleSnap(); 52 52 private Double drawingAngle; 53 private final staticdouble EQUAL_NODE_DIST_TOLERANCE = 1e-6;53 private static final double EQUAL_NODE_DIST_TOLERANCE = 1e-6; 54 54 55 55 public void clearAngleSnap() { … … 227 227 } 228 228 229 private Node findNode(EastNorth pos) {229 private static Node findNode(EastNorth pos) { 230 230 MapView mv = MainApplication.getMap().mapView; 231 231 Node n = mv.getNearestNode(mv.getPoint(eastNorth2latlon(pos)), OsmPrimitive::isSelectable); … … 249 249 nodesloop: 250 250 for (Node n : MainApplication.getLayerManager().getEditDataSet().searchNodes(bbox)) { 251 if (!n.isUsable()) 252 continue; 253 tagcheck: do { 254 for (String key : n.getKeys().keySet()) { 255 if (key.equals("building") || key.startsWith("addr:")) 256 break tagcheck; 251 if (n.isUsable() && findUsableTag(n)) { 252 double x = projection1(latlon2eastNorth(n.getCoor())); 253 double y = projection2(latlon2eastNorth(n.getCoor())); 254 if (Math.signum(x) != Math.signum(len) || Math.signum(y) != Math.signum(width)) 255 continue; 256 if (Math.abs(x) > Math.abs(len) || Math.abs(y) > Math.abs(width)) 257 continue; 258 for (OsmPrimitive p : n.getReferrers()) { 259 // Don't use nodes if they're referenced by ways 260 if (p.getType() == OsmPrimitiveType.WAY) 261 continue nodesloop; 257 262 } 258 continue nodesloop; 259 } while (false); 260 double x = projection1(latlon2eastNorth(n.getCoor())); 261 double y = projection2(latlon2eastNorth(n.getCoor())); 262 if (Math.signum(x) != Math.signum(len) || Math.signum(y) != Math.signum(width)) 263 continue; 264 if (Math.abs(x) > Math.abs(len) || Math.abs(y) > Math.abs(width)) 265 continue; 266 for (OsmPrimitive p : n.getReferrers()) { 267 // Don't use nodes if they're referenced by ways 268 if (p.getType() == OsmPrimitiveType.WAY) 269 continue nodesloop; 270 } 271 nodes.add(n); 263 nodes.add(n); 264 } 272 265 } 273 266 if (nodes.size() != 1) 274 267 return null; 275 268 return nodes.get(0); 269 } 270 271 static boolean findUsableTag(OsmPrimitive p) { 272 for (String key : p.getKeys().keySet()) { 273 if ("building".equals(key) || key.startsWith("addr:")) { 274 return true; 275 } 276 } 277 return false; 276 278 } 277 279 … … 315 317 316 318 snapBuildings(w, nodes, addNodesCmd); 317 if ( addNodesCmd.size() > 0) {319 if (!addNodesCmd.isEmpty()) { 318 320 Command addNodes = new SequenceCommand(tr("Add nodes for building"), addNodesCmd); 319 321 UndoRedoHandler.getInstance().add(addNodes); … … 396 398 } 397 399 398 private void snapBuildings(Way w, Node[] nodes, Collection<Command> cmds) {400 private static void snapBuildings(Way w, Node[] nodes, Collection<Command> cmds) { 399 401 // calculate BBox which is slightly larger than the new building 400 402 List<Node> wayNodes = w.getNodes(); … … 435 437 */ 436 438 private static void snapToWay(List<Node> wayNodes, Collection<Node> otherNodes) { 437 for (int i = 0; i < wayNodes.size(); i++) { 439 int i = 0; 440 while (i < wayNodes.size()) { 438 441 Node n0 = wayNodes.get(i); 439 442 Node n1 = wayNodes.get(i + 1 == wayNodes.size() ? 0 : i + 1); 440 443 for (Node n2 : otherNodes) { 441 if (n2 == n0 || n2 == n1) 442 continue; 443 EastNorth x = Geometry.closestPointToSegment(n0.getEastNorth(), n1.getEastNorth(), n2.getEastNorth()); 444 if (x.distance(n2.getEastNorth()) <= EQUAL_NODE_DIST_TOLERANCE && !wayNodes.contains(n2)) { 445 wayNodes.add(i + 1, n2); 446 // we may add multiple nodes to one segment, so repeat it 447 i--; 448 break; 444 if (n2 != n0 && n2 != n1) { 445 EastNorth x = Geometry.closestPointToSegment(n0.getEastNorth(), n1.getEastNorth(), 446 n2.getEastNorth()); 447 if (x.distance(n2.getEastNorth()) <= EQUAL_NODE_DIST_TOLERANCE && !wayNodes.contains(n2)) { 448 wayNodes.add(i + 1, n2); 449 // we may add multiple nodes to one segment, so repeat 450 // it 451 i--; 452 break; 453 } 449 454 } 450 455 } 456 i++; 451 457 } 452 458 } -
applications/editors/josm/plugins/buildings_tools/src/org/openstreetmap/josm/plugins/buildings_tools/MergeAddrPointsAction.java
r34572 r34850 91 91 if (mergeNode != null) { 92 92 multi++; 93 continue buildingsLoop; // Multiple address nodes inside 94 // one building -- skipping 93 // Multiple address nodes inside one building -- 94 // skipping 95 continue buildingsLoop; 95 96 } else 96 97 mergeNode = n;
Note:
See TracChangeset
for help on using the changeset viewer.