source: josm/trunk/src/org/openstreetmap/josm/gui/MapViewState.java@ 12707

Last change on this file since 12707 was 12505, checked in by michael2402, 7 years ago

Add a method that allows traversing an offset version of a MapViewPath

  • Property svn:eol-style set to native
File size: 25.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui;
3
4import java.awt.Container;
5import java.awt.Point;
6import java.awt.geom.AffineTransform;
7import java.awt.geom.Area;
8import java.awt.geom.Path2D;
9import java.awt.geom.Point2D;
10import java.awt.geom.Point2D.Double;
11import java.awt.geom.Rectangle2D;
12import java.io.Serializable;
13import java.util.Objects;
14import java.util.Optional;
15
16import javax.swing.JComponent;
17
18import org.openstreetmap.josm.Main;
19import org.openstreetmap.josm.data.Bounds;
20import org.openstreetmap.josm.data.ProjectionBounds;
21import org.openstreetmap.josm.data.coor.EastNorth;
22import org.openstreetmap.josm.data.coor.ILatLon;
23import org.openstreetmap.josm.data.coor.LatLon;
24import org.openstreetmap.josm.data.osm.Node;
25import org.openstreetmap.josm.data.projection.Projecting;
26import org.openstreetmap.josm.data.projection.Projection;
27import org.openstreetmap.josm.gui.download.DownloadDialog;
28import org.openstreetmap.josm.tools.CheckParameterUtil;
29import org.openstreetmap.josm.tools.Geometry;
30import org.openstreetmap.josm.tools.JosmRuntimeException;
31import org.openstreetmap.josm.tools.bugreport.BugReport;
32
33/**
34 * This class represents a state of the {@link MapView}.
35 * @author Michael Zangl
36 * @since 10343
37 */
38public final class MapViewState implements Serializable {
39
40 private static final long serialVersionUID = 1L;
41
42 /**
43 * A flag indicating that the point is outside to the top of the map view.
44 * @since 10827
45 */
46 public static final int OUTSIDE_TOP = 1;
47
48 /**
49 * A flag indicating that the point is outside to the bottom of the map view.
50 * @since 10827
51 */
52 public static final int OUTSIDE_BOTTOM = 2;
53
54 /**
55 * A flag indicating that the point is outside to the left of the map view.
56 * @since 10827
57 */
58 public static final int OUTSIDE_LEFT = 4;
59
60 /**
61 * A flag indicating that the point is outside to the right of the map view.
62 * @since 10827
63 */
64 public static final int OUTSIDE_RIGHT = 8;
65
66 /**
67 * Additional pixels outside the view for where to start clipping.
68 */
69 private static final int CLIP_BOUNDS = 50;
70
71 private final transient Projecting projecting;
72
73 private final int viewWidth;
74 private final int viewHeight;
75
76 private final double scale;
77
78 /**
79 * Top left {@link EastNorth} coordinate of the view.
80 */
81 private final EastNorth topLeft;
82
83 private final Point topLeftOnScreen;
84 private final Point topLeftInWindow;
85
86 /**
87 * Create a new {@link MapViewState}
88 * @param projection The projection to use.
89 * @param viewWidth The view width
90 * @param viewHeight The view height
91 * @param scale The scale to use
92 * @param topLeft The top left corner in east/north space.
93 * @param topLeftInWindow The top left point in window
94 * @param topLeftOnScreen The top left point on screen
95 */
96 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft,
97 Point topLeftInWindow, Point topLeftOnScreen) {
98 CheckParameterUtil.ensureParameterNotNull(projection, "projection");
99 CheckParameterUtil.ensureParameterNotNull(topLeft, "topLeft");
100 CheckParameterUtil.ensureParameterNotNull(topLeftInWindow, "topLeftInWindow");
101 CheckParameterUtil.ensureParameterNotNull(topLeftOnScreen, "topLeftOnScreen");
102
103 this.projecting = projection;
104 this.scale = scale;
105 this.topLeft = topLeft;
106
107 this.viewWidth = viewWidth;
108 this.viewHeight = viewHeight;
109 this.topLeftInWindow = topLeftInWindow;
110 this.topLeftOnScreen = topLeftOnScreen;
111 }
112
113 private MapViewState(Projecting projection, int viewWidth, int viewHeight, double scale, EastNorth topLeft) {
114 this(projection, viewWidth, viewHeight, scale, topLeft, new Point(0, 0), new Point(0, 0));
115 }
116
117 private MapViewState(EastNorth topLeft, MapViewState mvs) {
118 this(mvs.projecting, mvs.viewWidth, mvs.viewHeight, mvs.scale, topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen);
119 }
120
121 private MapViewState(double scale, MapViewState mvs) {
122 this(mvs.projecting, mvs.viewWidth, mvs.viewHeight, scale, mvs.topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen);
123 }
124
125 private MapViewState(JComponent position, MapViewState mvs) {
126 this(mvs.projecting, position.getWidth(), position.getHeight(), mvs.scale, mvs.topLeft,
127 findTopLeftInWindow(position), findTopLeftOnScreen(position));
128 }
129
130 private MapViewState(Projecting projecting, MapViewState mvs) {
131 this(projecting, mvs.viewWidth, mvs.viewHeight, mvs.scale, mvs.topLeft, mvs.topLeftInWindow, mvs.topLeftOnScreen);
132 }
133
134 private static Point findTopLeftInWindow(JComponent position) {
135 Point result = new Point();
136 // better than using swing utils, since this allows us to use the method if no screen is present.
137 Container component = position;
138 while (component != null) {
139 result.x += component.getX();
140 result.y += component.getY();
141 component = component.getParent();
142 }
143 return result;
144 }
145
146 private static Point findTopLeftOnScreen(JComponent position) {
147 try {
148 return position.getLocationOnScreen();
149 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
150 throw BugReport.intercept(e).put("position", position).put("parent", position::getParent);
151 }
152 }
153
154 /**
155 * The scale in east/north units per pixel.
156 * @return The scale.
157 */
158 public double getScale() {
159 return scale;
160 }
161
162 /**
163 * Gets the MapViewPoint representation for a position in view coordinates.
164 * @param x The x coordinate inside the view.
165 * @param y The y coordinate inside the view.
166 * @return The MapViewPoint.
167 */
168 public MapViewPoint getForView(double x, double y) {
169 return new MapViewViewPoint(x, y);
170 }
171
172 /**
173 * Gets the {@link MapViewPoint} for the given {@link EastNorth} coordinate.
174 * @param eastNorth the position.
175 * @return The point for that position.
176 */
177 public MapViewPoint getPointFor(EastNorth eastNorth) {
178 return new MapViewEastNorthPoint(eastNorth);
179 }
180
181 /**
182 * Gets the {@link MapViewPoint} for the given {@link LatLon} coordinate.
183 * <p>
184 * This method exists to not break binary compatibility with old plugins
185 * @param latlon the position
186 * @return The point for that position.
187 * @since 10651
188 */
189 public MapViewPoint getPointFor(LatLon latlon) {
190 return getPointFor((ILatLon) latlon);
191 }
192
193 /**
194 * Gets the {@link MapViewPoint} for the given {@link LatLon} coordinate.
195 * @param latlon the position
196 * @return The point for that position.
197 * @since 12161
198 */
199 public MapViewPoint getPointFor(ILatLon latlon) {
200 try {
201 return getPointFor(Optional.ofNullable(latlon.getEastNorth(getProjection()))
202 .orElseThrow(IllegalArgumentException::new));
203 } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) {
204 throw BugReport.intercept(e).put("latlon", latlon);
205 }
206 }
207
208 /**
209 * Gets the {@link MapViewPoint} for the given node.
210 * This is faster than {@link #getPointFor(LatLon)} because it uses the node east/north cache.
211 * @param node The node
212 * @return The position of that node.
213 * @since 10827
214 */
215 public MapViewPoint getPointFor(Node node) {
216 return getPointFor((ILatLon) node);
217 }
218
219 /**
220 * Gets a rectangle representing the whole view area.
221 * @return The rectangle.
222 */
223 public MapViewRectangle getViewArea() {
224 return getForView(0, 0).rectTo(getForView(viewWidth, viewHeight));
225 }
226
227 /**
228 * Gets a rectangle of the view as map view area.
229 * @param rectangle The rectangle to get.
230 * @return The view area.
231 * @since 10827
232 */
233 public MapViewRectangle getViewArea(Rectangle2D rectangle) {
234 return getForView(rectangle.getMinX(), rectangle.getMinY()).rectTo(getForView(rectangle.getMaxX(), rectangle.getMaxY()));
235 }
236
237 /**
238 * Gets the center of the view.
239 * @return The center position.
240 */
241 public MapViewPoint getCenter() {
242 return getForView(viewWidth / 2.0, viewHeight / 2.0);
243 }
244
245 /**
246 * Gets the width of the view on the Screen;
247 * @return The width of the view component in screen pixel.
248 */
249 public double getViewWidth() {
250 return viewWidth;
251 }
252
253 /**
254 * Gets the height of the view on the Screen;
255 * @return The height of the view component in screen pixel.
256 */
257 public double getViewHeight() {
258 return viewHeight;
259 }
260
261 /**
262 * Gets the current projection used for the MapView.
263 * @return The projection.
264 * @see #getProjecting()
265 */
266 public Projection getProjection() {
267 return projecting.getBaseProjection();
268 }
269
270 /**
271 * Gets the current projecting instance that is used to convert between east/north and lat/lon space.
272 * @return The projection.
273 * @since 12161
274 */
275 public Projecting getProjecting() {
276 return projecting;
277 }
278
279 /**
280 * Creates an affine transform that is used to convert the east/north coordinates to view coordinates.
281 * @return The affine transform. It should not be changed.
282 * @since 10375
283 */
284 public AffineTransform getAffineTransform() {
285 return new AffineTransform(1.0 / scale, 0.0, 0.0, -1.0 / scale, -topLeft.east() / scale,
286 topLeft.north() / scale);
287 }
288
289 /**
290 * Gets a rectangle that is several pixel bigger than the view. It is used to define the view clipping.
291 * @return The rectangle.
292 */
293 public MapViewRectangle getViewClipRectangle() {
294 return getForView(-CLIP_BOUNDS, -CLIP_BOUNDS).rectTo(getForView(getViewWidth() + CLIP_BOUNDS, getViewHeight() + CLIP_BOUNDS));
295 }
296
297 /**
298 * Returns the area for the given bounds.
299 * @param bounds bounds
300 * @return the area for the given bounds
301 */
302 public Area getArea(Bounds bounds) {
303 Path2D area = new Path2D.Double();
304 bounds.visitEdge(getProjection(), latlon -> {
305 MapViewPoint point = getPointFor(latlon);
306 if (area.getCurrentPoint() == null) {
307 area.moveTo(point.getInViewX(), point.getInViewY());
308 } else {
309 area.lineTo(point.getInViewX(), point.getInViewY());
310 }
311 });
312 area.closePath();
313 return new Area(area);
314 }
315
316 /**
317 * Creates a new state that is the same as the current state except for that it is using a new center.
318 * @param newCenter The new center coordinate.
319 * @return The new state.
320 * @since 10375
321 */
322 public MapViewState usingCenter(EastNorth newCenter) {
323 return movedTo(getCenter(), newCenter);
324 }
325
326 /**
327 * @param mapViewPoint The reference point.
328 * @param newEastNorthThere The east/north coordinate that should be there.
329 * @return The new state.
330 * @since 10375
331 */
332 public MapViewState movedTo(MapViewPoint mapViewPoint, EastNorth newEastNorthThere) {
333 EastNorth delta = newEastNorthThere.subtract(mapViewPoint.getEastNorth());
334 if (delta.distanceSq(0, 0) < .1e-20) {
335 return this;
336 } else {
337 return new MapViewState(topLeft.add(delta), this);
338 }
339 }
340
341 /**
342 * Creates a new state that is the same as the current state except for that it is using a new scale.
343 * @param newScale The new scale to use.
344 * @return The new state.
345 * @since 10375
346 */
347 public MapViewState usingScale(double newScale) {
348 return new MapViewState(newScale, this);
349 }
350
351 /**
352 * Creates a new state that is the same as the current state except for that it is using the location of the given component.
353 * <p>
354 * The view is moved so that the center is the same as the old center.
355 * @param positon The new location to use.
356 * @return The new state.
357 * @since 10375
358 */
359 public MapViewState usingLocation(JComponent positon) {
360 EastNorth center = this.getCenter().getEastNorth();
361 return new MapViewState(positon, this).usingCenter(center);
362 }
363
364 /**
365 * Creates a state that uses the projection.
366 * @param projection The projection to use.
367 * @return The new state.
368 * @since 10486
369 */
370 public MapViewState usingProjection(Projection projection) {
371 if (projection.equals(this.projecting)) {
372 return this;
373 } else {
374 return new MapViewState(projection, this);
375 }
376 }
377
378 /**
379 * Create the default {@link MapViewState} object for the given map view. The screen position won't be set so that this method can be used
380 * before the view was added to the hirarchy.
381 * @param width The view width
382 * @param height The view height
383 * @return The state
384 * @since 10375
385 */
386 public static MapViewState createDefaultState(int width, int height) {
387 Projection projection = Main.getProjection();
388 double scale = projection.getDefaultZoomInPPD();
389 MapViewState state = new MapViewState(projection, width, height, scale, new EastNorth(0, 0));
390 EastNorth center = calculateDefaultCenter();
391 return state.movedTo(state.getCenter(), center);
392 }
393
394 private static EastNorth calculateDefaultCenter() {
395 Bounds b = Optional.ofNullable(DownloadDialog.getSavedDownloadBounds()).orElseGet(
396 () -> Main.getProjection().getWorldBoundsLatLon());
397 return b.getCenter().getEastNorth();
398 }
399
400 /**
401 * Check if this MapViewState equals another one, disregarding the position
402 * of the JOSM window on screen.
403 * @param other the other MapViewState
404 * @return true if the other MapViewState has the same size, scale, position and projection,
405 * false otherwise
406 */
407 public boolean equalsInWindow(MapViewState other) {
408 return other != null &&
409 this.viewWidth == other.viewWidth &&
410 this.viewHeight == other.viewHeight &&
411 this.scale == other.scale &&
412 Objects.equals(this.topLeft, other.topLeft) &&
413 Objects.equals(this.projecting, other.projecting);
414 }
415
416 /**
417 * A class representing a point in the map view. It allows to convert between the different coordinate systems.
418 * @author Michael Zangl
419 */
420 public abstract class MapViewPoint {
421 /**
422 * Gets the map view state this path is used for.
423 * @return The state.
424 * @since 12505
425 */
426 public MapViewState getMapViewState() {
427 return MapViewState.this;
428 }
429
430 /**
431 * Get this point in view coordinates.
432 * @return The point in view coordinates.
433 */
434 public Point2D getInView() {
435 return new Point2D.Double(getInViewX(), getInViewY());
436 }
437
438 /**
439 * Get the x coordinate in view space without creating an intermediate object.
440 * @return The x coordinate
441 * @since 10827
442 */
443 public abstract double getInViewX();
444
445 /**
446 * Get the y coordinate in view space without creating an intermediate object.
447 * @return The y coordinate
448 * @since 10827
449 */
450 public abstract double getInViewY();
451
452 /**
453 * Convert this point to window coordinates.
454 * @return The point in window coordinates.
455 */
456 public Point2D getInWindow() {
457 return getUsingCorner(topLeftInWindow);
458 }
459
460 /**
461 * Convert this point to screen coordinates.
462 * @return The point in screen coordinates.
463 */
464 public Point2D getOnScreen() {
465 return getUsingCorner(topLeftOnScreen);
466 }
467
468 private Double getUsingCorner(Point corner) {
469 return new Point2D.Double(corner.getX() + getInViewX(), corner.getY() + getInViewY());
470 }
471
472 /**
473 * Gets the {@link EastNorth} coordinate of this point.
474 * @return The east/north coordinate.
475 */
476 public EastNorth getEastNorth() {
477 return new EastNorth(topLeft.east() + getInViewX() * scale, topLeft.north() - getInViewY() * scale);
478 }
479
480 /**
481 * Create a rectangle from this to the other point.
482 * @param other The other point. Needs to be of the same {@link MapViewState}
483 * @return A rectangle.
484 */
485 public MapViewRectangle rectTo(MapViewPoint other) {
486 return new MapViewRectangle(this, other);
487 }
488
489 /**
490 * Gets the current position in LatLon coordinates according to the current projection.
491 * @return The positon as LatLon.
492 * @see #getLatLonClamped()
493 */
494 public LatLon getLatLon() {
495 return projecting.getBaseProjection().eastNorth2latlon(getEastNorth());
496 }
497
498 /**
499 * Gets the latlon coordinate clamped to the current world area.
500 * @return The lat/lon coordinate
501 * @since 10805
502 */
503 public LatLon getLatLonClamped() {
504 return projecting.eastNorth2latlonClamped(getEastNorth());
505 }
506
507 /**
508 * Add the given offset to this point
509 * @param en The offset in east/north space.
510 * @return The new point
511 * @since 10651
512 */
513 public MapViewPoint add(EastNorth en) {
514 return new MapViewEastNorthPoint(getEastNorth().add(en));
515 }
516
517 /**
518 * Check if this point is inside the view bounds.
519 *
520 * This is the case iff <code>getOutsideRectangleFlags(getViewArea())</code> returns no flags
521 * @return true if it is.
522 * @since 10827
523 */
524 public boolean isInView() {
525 return inRange(getInViewX(), 0, getViewWidth()) && inRange(getInViewY(), 0, getViewHeight());
526 }
527
528 private boolean inRange(double val, int min, double max) {
529 return val >= min && val < max;
530 }
531
532 /**
533 * Gets the direction in which this point is outside of the given view rectangle.
534 * @param rect The rectangle to check agains.
535 * @return The direction in which it is outside of the view, as OUTSIDE_... flags.
536 * @since 10827
537 */
538 public int getOutsideRectangleFlags(MapViewRectangle rect) {
539 Rectangle2D bounds = rect.getInView();
540 int flags = 0;
541 if (getInViewX() < bounds.getMinX()) {
542 flags |= OUTSIDE_LEFT;
543 } else if (getInViewX() > bounds.getMaxX()) {
544 flags |= OUTSIDE_RIGHT;
545 }
546 if (getInViewY() < bounds.getMinY()) {
547 flags |= OUTSIDE_TOP;
548 } else if (getInViewY() > bounds.getMaxY()) {
549 flags |= OUTSIDE_BOTTOM;
550 }
551
552 return flags;
553 }
554
555 /**
556 * Gets the sum of the x/y view distances between the points. |x1 - x2| + |y1 - y2|
557 * @param p2 The other point
558 * @return The norm
559 * @since 10827
560 */
561 public double oneNormInView(MapViewPoint p2) {
562 return Math.abs(getInViewX() - p2.getInViewX()) + Math.abs(getInViewY() - p2.getInViewY());
563 }
564
565 /**
566 * Gets the squared distance between this point and an other point.
567 * @param p2 The other point
568 * @return The squared distance.
569 * @since 10827
570 */
571 public double distanceToInViewSq(MapViewPoint p2) {
572 double dx = getInViewX() - p2.getInViewX();
573 double dy = getInViewY() - p2.getInViewY();
574 return dx * dx + dy * dy;
575 }
576
577 /**
578 * Gets the distance between this point and an other point.
579 * @param p2 The other point
580 * @return The distance.
581 * @since 10827
582 */
583 public double distanceToInView(MapViewPoint p2) {
584 return Math.sqrt(distanceToInViewSq(p2));
585 }
586
587 /**
588 * Do a linear interpolation to the other point
589 * @param p1 The other point
590 * @param i The interpolation factor. 0 is at the current point, 1 at the other point.
591 * @return The new point
592 * @since 10874
593 */
594 public MapViewPoint interpolate(MapViewPoint p1, double i) {
595 return new MapViewViewPoint((1 - i) * getInViewX() + i * p1.getInViewX(), (1 - i) * getInViewY() + i * p1.getInViewY());
596 }
597 }
598
599 private class MapViewViewPoint extends MapViewPoint {
600 private final double x;
601 private final double y;
602
603 MapViewViewPoint(double x, double y) {
604 this.x = x;
605 this.y = y;
606 }
607
608 @Override
609 public double getInViewX() {
610 return x;
611 }
612
613 @Override
614 public double getInViewY() {
615 return y;
616 }
617
618 @Override
619 public String toString() {
620 return "MapViewViewPoint [x=" + x + ", y=" + y + ']';
621 }
622 }
623
624 private class MapViewEastNorthPoint extends MapViewPoint {
625
626 private final EastNorth eastNorth;
627
628 MapViewEastNorthPoint(EastNorth eastNorth) {
629 this.eastNorth = Objects.requireNonNull(eastNorth, "eastNorth");
630 }
631
632 @Override
633 public double getInViewX() {
634 return (eastNorth.east() - topLeft.east()) / scale;
635 }
636
637 @Override
638 public double getInViewY() {
639 return (topLeft.north() - eastNorth.north()) / scale;
640 }
641
642 @Override
643 public EastNorth getEastNorth() {
644 return eastNorth;
645 }
646
647 @Override
648 public String toString() {
649 return "MapViewEastNorthPoint [eastNorth=" + eastNorth + ']';
650 }
651 }
652
653 /**
654 * A rectangle on the MapView. It is rectangular in screen / EastNorth space.
655 * @author Michael Zangl
656 */
657 public class MapViewRectangle {
658 private final MapViewPoint p1;
659 private final MapViewPoint p2;
660
661 /**
662 * Create a new MapViewRectangle
663 * @param p1 The first point to use
664 * @param p2 The second point to use.
665 */
666 MapViewRectangle(MapViewPoint p1, MapViewPoint p2) {
667 this.p1 = p1;
668 this.p2 = p2;
669 }
670
671 /**
672 * Gets the projection bounds for this rectangle.
673 * @return The projection bounds.
674 */
675 public ProjectionBounds getProjectionBounds() {
676 ProjectionBounds b = new ProjectionBounds(p1.getEastNorth());
677 b.extend(p2.getEastNorth());
678 return b;
679 }
680
681 /**
682 * Gets a rough estimate of the bounds by assuming lat/lon are parallel to x/y.
683 * @return The bounds computed by converting the corners of this rectangle.
684 * @see #getLatLonBoundsBox()
685 */
686 public Bounds getCornerBounds() {
687 Bounds b = new Bounds(p1.getLatLon());
688 b.extend(p2.getLatLon());
689 return b;
690 }
691
692 /**
693 * Gets the real bounds that enclose this rectangle.
694 * This is computed respecting that the borders of this rectangle may not be a straignt line in latlon coordinates.
695 * @return The bounds.
696 * @since 10458
697 */
698 public Bounds getLatLonBoundsBox() {
699 // TODO @michael2402: Use hillclimb.
700 return projecting.getBaseProjection().getLatLonBoundsBox(getProjectionBounds());
701 }
702
703 /**
704 * Gets this rectangle on the screen.
705 * @return The rectangle.
706 * @since 10651
707 */
708 public Rectangle2D getInView() {
709 double x1 = p1.getInViewX();
710 double y1 = p1.getInViewY();
711 double x2 = p2.getInViewX();
712 double y2 = p2.getInViewY();
713 return new Rectangle2D.Double(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x1 - x2), Math.abs(y1 - y2));
714 }
715
716 /**
717 * Check if the rectangle intersects the map view area.
718 * @return <code>true</code> if it intersects.
719 * @since 10827
720 */
721 public boolean isInView() {
722 return getInView().intersects(getViewArea().getInView());
723 }
724
725 /**
726 * Gets the entry point at which a line between start and end enters the current view.
727 * @param start The start
728 * @param end The end
729 * @return The entry point or <code>null</code> if the line does not intersect this view.
730 */
731 public MapViewPoint getLineEntry(MapViewPoint start, MapViewPoint end) {
732 ProjectionBounds bounds = getProjectionBounds();
733 if (bounds.contains(start.getEastNorth())) {
734 return start;
735 }
736
737 double dx = end.getEastNorth().east() - start.getEastNorth().east();
738 double boundX = dx > 0 ? bounds.minEast : bounds.maxEast;
739 EastNorth borderIntersection = Geometry.getSegmentSegmentIntersection(start.getEastNorth(), end.getEastNorth(),
740 new EastNorth(boundX, bounds.minNorth),
741 new EastNorth(boundX, bounds.maxNorth));
742 if (borderIntersection != null) {
743 return getPointFor(borderIntersection);
744 }
745
746 double dy = end.getEastNorth().north() - start.getEastNorth().north();
747 double boundY = dy > 0 ? bounds.minNorth : bounds.maxNorth;
748 borderIntersection = Geometry.getSegmentSegmentIntersection(start.getEastNorth(), end.getEastNorth(),
749 new EastNorth(bounds.minEast, boundY),
750 new EastNorth(bounds.maxEast, boundY));
751 if (borderIntersection != null) {
752 return getPointFor(borderIntersection);
753 }
754
755 return null;
756 }
757 }
758
759}
Note: See TracBrowser for help on using the repository browser.