1 | package org.openstreetmap.josm.data;
|
---|
2 |
|
---|
3 |
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * An point holding latitude/longitude and their corresponding north/east values,
|
---|
7 | * which may not be initialized.
|
---|
8 | *
|
---|
9 | * if x or y is "NaN", these are not initialized yet.
|
---|
10 | *
|
---|
11 | * @author imi
|
---|
12 | */
|
---|
13 | public class GeoPoint implements Cloneable {
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Latitude/Longitude coordinates.
|
---|
17 | */
|
---|
18 | public double lat = Double.NaN, lon = Double.NaN;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * East/North coordinates;
|
---|
22 | */
|
---|
23 | public double x = Double.NaN, y = Double.NaN;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Construct the point with latitude / longitude values.
|
---|
27 | * The x/y values are left uninitialized.
|
---|
28 | *
|
---|
29 | * @param lat Latitude of the point.
|
---|
30 | * @param lon Longitude of the point.
|
---|
31 | */
|
---|
32 | public GeoPoint(double lat, double lon) {
|
---|
33 | this.lat = lat;
|
---|
34 | this.lon = lon;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Construct the point with all values unset (set to NaN)
|
---|
39 | */
|
---|
40 | public GeoPoint() {
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | public GeoPoint clone() {
|
---|
45 | try {return (GeoPoint)super.clone();} catch (CloneNotSupportedException e) {}
|
---|
46 | return null;
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * Return the squared distance of the northing/easting values between
|
---|
51 | * this and the argument.
|
---|
52 | *
|
---|
53 | * @param other The other point to calculate the distance to.
|
---|
54 | * @return The square of the distance between this and the other point,
|
---|
55 | * regarding to the x/y values.
|
---|
56 | */
|
---|
57 | public double distanceXY(GeoPoint other) {
|
---|
58 | return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
|
---|
59 | }
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * @return <code>true</code>, if the other GeoPoint has the same lat/lon values.
|
---|
63 | */
|
---|
64 | public boolean equalsLatLon(GeoPoint other) {
|
---|
65 | return lat == other.lat && lon == other.lon;
|
---|
66 | }
|
---|
67 | }
|
---|