001// License: GPL. For details, see LICENSE file. 002package org.openstreetmap.josm.data.coor; 003 004import org.openstreetmap.josm.data.projection.Projecting; 005 006/** 007 * This interface represents a coordinate in LatLon space. 008 * <p> 009 * It provides methods to get the coordinates. The coordinates may be unknown. 010 * In this case, both {@link #lat()} and {@link #lon()} need to return a NaN value and {@link #isLatLonKnown()} needs to return false. 011 * <p> 012 * Whether the coordinates are immutable or not is implementation specific. 013 * 014 * @author Michael Zangl 015 * @since 12161 016 */ 017public interface ILatLon { 018 019 /** 020 * Returns the longitude, i.e., the east-west position in degrees. 021 * @return the longitude or NaN if {@link #isLatLonKnown()} returns false 022 */ 023 double lon(); 024 025 /** 026 * Returns the latitude, i.e., the north-south position in degrees. 027 * @return the latitude or NaN if {@link #isLatLonKnown()} returns false 028 */ 029 double lat(); 030 031 /** 032 * Determines if this object has valid coordinates. 033 * @return {@code true} if this object has valid coordinates 034 */ 035 default boolean isLatLonKnown() { 036 return !Double.isNaN(lat()) && !Double.isNaN(lon()); 037 } 038 039 /** 040 * Replies the projected east/north coordinates. 041 * <p> 042 * The result of the last conversion may be cached. Null is returned in case this object is invalid. 043 * @param projecting The projection to use. 044 * @return The projected east/north coordinates 045 * @since 10827 046 */ 047 default EastNorth getEastNorth(Projecting projecting) { 048 if (!isLatLonKnown()) { 049 return null; 050 } else { 051 return projecting.latlon2eastNorth(this); 052 } 053 } 054}