1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.coor;
|
---|
3 |
|
---|
4 |
|
---|
5 |
|
---|
6 |
|
---|
7 | /**
|
---|
8 | * Base class of points of both coordinate system.
|
---|
9 | *
|
---|
10 | * The variables are default package protected to allow routines in the data package
|
---|
11 | * to access them directly.
|
---|
12 | *
|
---|
13 | * As the class itself is package protected too, it is not visible outside of the data
|
---|
14 | * package. Routines there should only use LatLon or EastNorth
|
---|
15 | *
|
---|
16 | * @author imi
|
---|
17 | */
|
---|
18 | abstract class Coordinate {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Either easting or latitude
|
---|
22 | */
|
---|
23 | final double x;
|
---|
24 | /**
|
---|
25 | * Either northing or longitude
|
---|
26 | */
|
---|
27 | final double y;
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Construct the point with latitude / longitude values.
|
---|
31 | * The x/y values are left uninitialized.
|
---|
32 | *
|
---|
33 | * @param lat Latitude of the point.
|
---|
34 | * @param lon Longitude of the point.
|
---|
35 | */
|
---|
36 | Coordinate(double x, double y) {
|
---|
37 | this.x = x;
|
---|
38 | this.y = y;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Return the squared distance of the northing/easting values between
|
---|
43 | * this and the argument.
|
---|
44 | *
|
---|
45 | * @param other The other point to calculate the distance to.
|
---|
46 | * @return The square of the distance between this and the other point,
|
---|
47 | * regarding to the x/y values.
|
---|
48 | */
|
---|
49 | public double distance(Coordinate other) {
|
---|
50 | return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override public boolean equals(Object obj) {
|
---|
54 | return obj instanceof Coordinate ? x == ((Coordinate)obj).x && ((Coordinate)obj).y == y : false;
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override public int hashCode() {
|
---|
58 | return (int)(x*65536+y*4096);
|
---|
59 | }
|
---|
60 | }
|
---|