Changeset 10827 in josm for trunk/src/org/openstreetmap/josm/gui/MapViewState.java
- Timestamp:
- 2016-08-17T20:14:58+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapViewState.java
r10806 r10827 4 4 import java.awt.Container; 5 5 import java.awt.Point; 6 import java.awt.Rectangle;7 6 import java.awt.geom.AffineTransform; 8 7 import java.awt.geom.Area; … … 19 18 import org.openstreetmap.josm.data.coor.EastNorth; 20 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.data.osm.Node; 21 21 import org.openstreetmap.josm.data.projection.Projecting; 22 22 import org.openstreetmap.josm.data.projection.Projection; … … 30 30 */ 31 31 public final class MapViewState { 32 33 /** 34 * A flag indicating that the point is outside to the top of the map view. 35 * @since 10826 36 */ 37 public static final int OUTSIDE_TOP = 1; 38 39 /** 40 * A flag indicating that the point is outside to the bottom of the map view. 41 * @since 10826 42 */ 43 public static final int OUTSIDE_BOTTOM = 2; 44 45 /** 46 * A flag indicating that the point is outside to the left of the map view. 47 * @since 10826 48 */ 49 public static final int OUTSIDE_LEFT = 3; 50 51 /** 52 * A flag indicating that the point is outside to the right of the map view. 53 * @since 10826 54 */ 55 public static final int OUTSIDE_RIGHT = 4; 32 56 33 57 private final Projecting projecting; … … 158 182 159 183 /** 184 * Gets the {@link MapViewPoint} for the given node. This is faster than {@link #getPointFor(LatLon)} because it uses the node east/north 185 * cache. 186 * @param node The node 187 * @return The position of that node. 188 * @since 10826 189 */ 190 public MapViewPoint getPointFor(Node node) { 191 return getPointFor(node.getEastNorth(getProjection())); 192 } 193 194 /** 160 195 * Gets a rectangle representing the whole view area. 161 196 * @return The rectangle. … … 169 204 * @param rectangle The rectangle to get. 170 205 * @return The view area. 171 * @since 10 458172 */ 173 public MapViewRectangle getViewArea(Rectangle rectangle) {206 * @since 10826 207 */ 208 public MapViewRectangle getViewArea(Rectangle2D rectangle) { 174 209 return getForView(rectangle.getMinX(), rectangle.getMinY()).rectTo(getForView(rectangle.getMaxX(), rectangle.getMaxY())); 175 210 } … … 331 366 } 332 367 333 protected abstract double getInViewX(); 334 335 protected abstract double getInViewY(); 368 /** 369 * Get the x coordinate in view space without creating an intermediate object. 370 * @return The x coordinate 371 * @since 10826 372 */ 373 public abstract double getInViewX(); 374 375 /** 376 * Get the y coordinate in view space without creating an intermediate object. 377 * @return The y coordinate 378 * @since 10826 379 */ 380 public abstract double getInViewY(); 336 381 337 382 /** … … 399 444 return new MapViewEastNorthPoint(getEastNorth().add(en)); 400 445 } 446 447 /** 448 * Check if this point is inside the view bounds. 449 * 450 * This is the case iff <code>getOutsideRectangleFlags(getViewArea())</code> returns no flags 451 * @return true if it is. 452 * @since 10826 453 */ 454 public boolean isInView() { 455 return inRange(getInViewX(), 0, getViewWidth()) && inRange(getInViewY(), 0, getViewHeight()); 456 } 457 458 private boolean inRange(double val, int min, double max) { 459 return val >= min && val < max; 460 } 461 462 /** 463 * Gets the direction in which this point is outside of the given view rectangle. 464 * @param rect The rectangle to check agains. 465 * @return The direction in which it is outside of the view, as OUTSIDE_... flags. 466 * @since 10826 467 */ 468 public int getOutsideRectangleFlags(MapViewRectangle rect) { 469 Rectangle2D bounds = rect.getInView(); 470 int flags = 0; 471 if (getInViewX() < bounds.getMinX()) { 472 flags |= OUTSIDE_LEFT; 473 } else if (getInViewX() > bounds.getMaxX()) { 474 flags |= OUTSIDE_RIGHT; 475 } 476 if (getInViewY() < bounds.getMinY()) { 477 flags |= OUTSIDE_TOP; 478 } else if (getInViewY() > bounds.getMaxY()) { 479 flags |= OUTSIDE_BOTTOM; 480 } 481 482 return flags; 483 } 484 485 /** 486 * Gets the sum of the x/y view distances between the points. |x1 - x2| + |y1 - y2| 487 * @param p2 The other point 488 * @return The norm 489 * @since 10826 490 */ 491 public double oneNormInView(MapViewPoint p2) { 492 return Math.abs(getInViewX() - p2.getInViewX()) + Math.abs(getInViewY()) - p2.getInViewY(); 493 } 494 495 /** 496 * Gets the squared distance between this point and an other point. 497 * @param p2 The other point 498 * @return The squared distance. 499 * @since 10826 500 */ 501 public double distanceToInViewSq(MapViewPoint p2) { 502 double dx = getInViewX() - p2.getInViewX(); 503 double dy = getInViewY() - p2.getInViewY(); 504 return dx * dx + dy * dy; 505 } 506 507 /** 508 * Gets the distance between this point and an other point. 509 * @param p2 The other point 510 * @return The distance. 511 * @since 10826 512 */ 513 public double distanceToInView(MapViewPoint p2) { 514 return Math.sqrt(distanceToInViewSq(p2)); 515 } 401 516 } 402 517 … … 411 526 412 527 @Override 413 p rotecteddouble getInViewX() {528 public double getInViewX() { 414 529 return x; 415 530 } 416 531 417 532 @Override 418 p rotecteddouble getInViewY() {533 public double getInViewY() { 419 534 return y; 420 535 } … … 435 550 436 551 @Override 437 p rotecteddouble getInViewX() {552 public double getInViewX() { 438 553 return (eastNorth.east() - topLeft.east()) / scale; 439 554 } 440 555 441 556 @Override 442 p rotecteddouble getInViewY() {557 public double getInViewY() { 443 558 return (topLeft.north() - eastNorth.north()) / scale; 444 559 } … … 517 632 return new Rectangle2D.Double(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2)); 518 633 } 634 635 /** 636 * Check if the rectangle intersects the map view area. 637 * @return <code>true</code> if it intersects. 638 * @since 10826 639 */ 640 public boolean isInView() { 641 return getInView().intersects(getViewArea().getInView()); 642 } 519 643 } 520 644
Note:
See TracChangeset
for help on using the changeset viewer.