source: josm/trunk/src/org/openstreetmap/josm/data/coor/ILatLon.java@ 12659

Last change on this file since 12659 was 12171, checked in by michael2402, 7 years ago

Fixed checkstyle warnings.

File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.coor;
3
4import org.openstreetmap.josm.Main;
5import 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 */
18public 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 */
47 default EastNorth getEastNorth() {
48 return getEastNorth(Main.getProjection());
49 }
50
51 /**
52 * Replies the projected east/north coordinates.
53 * <p>
54 * The result of the last conversion may be cached. Null is returned in case this object is invalid.
55 * @param projecting The projection to use.
56 * @return The projected east/north coordinates
57 * @since 10827
58 */
59 default EastNorth getEastNorth(Projecting projecting) {
60 if (!isLatLonKnown()) {
61 return null;
62 } else {
63 return projecting.latlon2eastNorth(this);
64 }
65 }
66}
Note: See TracBrowser for help on using the repository browser.