1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.coor;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.Main;
|
---|
5 | import org.openstreetmap.josm.data.projection.Projecting;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * This interface represents a coordinate in LatLon space.
|
---|
9 | * <p>
|
---|
10 | * It provides methods to get the coordinates. The coordinates may be unknown.
|
---|
11 | * In this case, both {@link #lat()} and {@link #lon()} need to return a NaN value and {@link #isLatLonKnown()} needs to return false.
|
---|
12 | * <p>
|
---|
13 | * Whether the coordinates are immutable or not is implementation specific.
|
---|
14 | *
|
---|
15 | * @author Michael Zangl
|
---|
16 | * @since 12161
|
---|
17 | */
|
---|
18 | public interface ILatLon {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Returns the longitude, i.e., the east-west position in degrees.
|
---|
22 | * @return the longitude or NaN if {@link #isLatLonKnown()} returns false
|
---|
23 | */
|
---|
24 | double lon();
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Returns the latitude, i.e., the north-south position in degrees.
|
---|
28 | * @return the latitude or NaN if {@link #isLatLonKnown()} returns false
|
---|
29 | */
|
---|
30 | double lat();
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Determines if this object has valid coordinates.
|
---|
34 | * @return {@code true} if this object has valid coordinates
|
---|
35 | */
|
---|
36 | default boolean isLatLonKnown() {
|
---|
37 | return !Double.isNaN(lat()) && !Double.isNaN(lon());
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * <p>Replies the projected east/north coordinates.</p>
|
---|
42 | *
|
---|
43 | * <p>Uses the {@link Main#getProjection() global projection} to project the lan/lon-coordinates.</p>
|
---|
44 | *
|
---|
45 | * @return the east north coordinates or {@code null} if #is
|
---|
46 | * @deprecated use {@link #getEastNorth(org.openstreetmap.josm.data.projection.Projecting)}
|
---|
47 | */
|
---|
48 | @Deprecated
|
---|
49 | default EastNorth getEastNorth() {
|
---|
50 | return getEastNorth(Main.getProjection());
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Replies the projected east/north coordinates.
|
---|
55 | * <p>
|
---|
56 | * The result of the last conversion may be cached. Null is returned in case this object is invalid.
|
---|
57 | * @param projecting The projection to use.
|
---|
58 | * @return The projected east/north coordinates
|
---|
59 | * @since 10827
|
---|
60 | */
|
---|
61 | default EastNorth getEastNorth(Projecting projecting) {
|
---|
62 | if (!isLatLonKnown()) {
|
---|
63 | return null;
|
---|
64 | } else {
|
---|
65 | return projecting.latlon2eastNorth(this);
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|