Changeset 2422 in josm for trunk/src/org/openstreetmap/josm/gui
- Timestamp:
- 2009-11-09T21:32:12+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/NavigatableComponent.java
r2381 r2422 25 25 import org.openstreetmap.josm.data.osm.Way; 26 26 import org.openstreetmap.josm.data.osm.WaySegment; 27 import org.openstreetmap.josm.data.osm.QuadBuckets.BBox; 27 28 import org.openstreetmap.josm.data.projection.Projection; 28 29 import org.openstreetmap.josm.gui.help.Helpful; … … 36 37 public class NavigatableComponent extends JComponent implements Helpful { 37 38 38 public static final int snapDistance = sqr(Main.pref.getInteger("node.snap-distance", 10)); 39 public static final int snapDistance = Main.pref.getInteger("node.snap-distance", 10); 40 public static final int snapDistanceSq = sqr(snapDistance); 39 41 40 42 private static int sqr(int a) { return a*a;} … … 296 298 } 297 299 300 private BBox getSnapDistanceBBox(Point p) { 301 return new BBox(getLatLon(p.x - snapDistance / 2, p.y - snapDistance / 2), 302 getLatLon(p.x + snapDistance / 2, p.y + snapDistance / 2)); 303 } 304 298 305 /** 299 306 * Return the nearest point to the screen point given. … … 301 308 */ 302 309 public final Node getNearestNode(Point p) { 303 double minDistanceSq = snapDistance;304 Node minPrimitive = null;305 310 DataSet ds = getCurrentDataSet(); 306 311 if (ds == null) 307 312 return null; 308 for (Node n : ds.getNodes()) { 313 314 double minDistanceSq = snapDistanceSq; 315 Node minPrimitive = null; 316 for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 309 317 if (!n.isUsable()) { 310 318 continue; … … 319 327 else if (dist == minDistanceSq && minPrimitive != null 320 328 && ((n.isNew() && ds.isSelected(n)) 321 || (!ds.isSelected(minPrimitive) && (ds.isSelected(n) || n.isNew())))) {329 || (!ds.isSelected(minPrimitive) && (ds.isSelected(n) || n.isNew())))) { 322 330 minPrimitive = n; 323 331 } … … 337 345 if (ds == null) 338 346 return null; 339 for (Way w : ds.getWays()) { 347 348 for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 340 349 if (!w.isUsable()) { 341 350 continue; … … 359 368 double b = p.distanceSq(A); 360 369 double perDist = a - (a - b + c) * (a - b + c) / 4 / c; // perpendicular distance squared 361 if (perDist < snapDistance && a < c + snapDistance && b < c + snapDistance) {370 if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) { 362 371 if (ds.isSelected(w)) { 363 372 perDist -= 0.00001; … … 450 459 /** 451 460 * @return A list of all objects that are nearest to 452 * the mouse. Does a simple sequential scan on all the data.461 * the mouse. 453 462 * 454 463 * @return A collection of all items or <code>null</code> … … 461 470 if (ds == null) 462 471 return null; 463 for (Way w : ds. getWays()) {472 for (Way w : ds.searchWays(getSnapDistanceBBox(p))) { 464 473 if (!w.isUsable()) { 465 474 continue; … … 480 489 double b = p.distanceSq(A); 481 490 double perDist = a - (a - b + c) * (a - b + c) / 4 / c; // perpendicular distance squared 482 if (perDist < snapDistance && a < c + snapDistance && b < c + snapDistance) {491 if (perDist < snapDistanceSq && a < c + snapDistanceSq && b < c + snapDistanceSq) { 483 492 nearest.add(w); 484 493 break; … … 487 496 } 488 497 } 489 for (Node n : ds. getNodes()) {498 for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 490 499 if (n.isUsable() 491 && getPoint(n).distanceSq(p) < snapDistance ) {500 && getPoint(n).distanceSq(p) < snapDistanceSq) { 492 501 nearest.add(n); 493 502 } … … 498 507 /** 499 508 * @return A list of all nodes that are nearest to 500 * the mouse. Does a simple sequential scan on all the data.509 * the mouse. 501 510 * 502 511 * @return A collection of all nodes or <code>null</code> … … 509 518 if (ds == null) 510 519 return null; 511 for (Node n : ds.getNodes()) { 520 521 for (Node n : ds.searchNodes(getSnapDistanceBBox(p))) { 512 522 if (n.isUsable() 513 && getPoint(n).distanceSq(p) < snapDistance ) {523 && getPoint(n).distanceSq(p) < snapDistanceSq) { 514 524 nearest.add(n); 515 525 }
Note:
See TracChangeset
for help on using the changeset viewer.