1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.coor;
|
---|
3 |
|
---|
4 | import org.openstreetmap.josm.data.Bounds;
|
---|
5 | import org.openstreetmap.josm.data.projection.Projection;
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * LatLon are unprojected latitude / longitude coordinates.
|
---|
9 | *
|
---|
10 | * This class is immutable.
|
---|
11 | *
|
---|
12 | * @author Imi
|
---|
13 | */
|
---|
14 | public class LatLon extends Coordinate {
|
---|
15 |
|
---|
16 | public LatLon(double lat, double lon) {
|
---|
17 | super(lon, lat);
|
---|
18 | }
|
---|
19 |
|
---|
20 | public double lat() {
|
---|
21 | return y;
|
---|
22 | }
|
---|
23 |
|
---|
24 | public double lon() {
|
---|
25 | return x;
|
---|
26 | }
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * @return <code>true</code>, if the other point has almost the same lat/lon
|
---|
30 | * values, only differ by no more than 1/Projection.MAX_SERVER_PRECISION.
|
---|
31 | */
|
---|
32 | public boolean equalsEpsilon(LatLon other) {
|
---|
33 | final double p = 1/Projection.MAX_SERVER_PRECISION;
|
---|
34 | return Math.abs(lat()-other.lat()) <= p && Math.abs(lon()-other.lon()) <= p;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * @return <code>true</code>, if the coordinate is outside the world, compared
|
---|
39 | * by using lat/lon.
|
---|
40 | */
|
---|
41 | public boolean isOutSideWorld() {
|
---|
42 | return lat() < -Projection.MAX_LAT || lat() > Projection.MAX_LAT ||
|
---|
43 | lon() < -Projection.MAX_LON || lon() > Projection.MAX_LON;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @return <code>true</code> if this is within the given bounding box.
|
---|
48 | */
|
---|
49 | public boolean isWithin(Bounds b) {
|
---|
50 | return lat() >= b.min.lat() && lat() <= b.max.lat() && lon() > b.min.lon() && lon() < b.max.lon();
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override public String toString() {
|
---|
54 | return "LatLon[lat="+lat()+",lon="+lon()+"]";
|
---|
55 | }
|
---|
56 | }
|
---|