1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
2 | package org.openstreetmap.josm.data.coor;
|
---|
3 |
|
---|
4 | import java.io.Serializable;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * Base class of points of both coordinate systems.
|
---|
8 | *
|
---|
9 | * The variables are default package protected to allow routines in the
|
---|
10 | * data package to access them directly.
|
---|
11 | *
|
---|
12 | * As the class itself is package protected too, it is not visible
|
---|
13 | * outside of the data package. Routines there should only use LatLon or
|
---|
14 | * EastNorth.
|
---|
15 | *
|
---|
16 | * @since 6162
|
---|
17 | */
|
---|
18 | abstract class Coordinate implements Serializable {
|
---|
19 |
|
---|
20 | protected final double x;
|
---|
21 | protected final double y;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Construct the point with latitude / longitude values.
|
---|
25 | *
|
---|
26 | * @param x X coordinate of the point.
|
---|
27 | * @param y Y coordinate of the point.
|
---|
28 | */
|
---|
29 | Coordinate(double x, double y) {
|
---|
30 | this.x = x; this.y = y;
|
---|
31 | }
|
---|
32 |
|
---|
33 | public double getX() {
|
---|
34 | return x;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public double getY() {
|
---|
38 | return y;
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Returns the square of the euclidean distance from this {@code Coordinate} to a specified {@code Coordinate}.
|
---|
43 | *
|
---|
44 | * @param coor the specified coordinate to be measured against this {@code Coordinate}
|
---|
45 | * @return the square of the euclidean distance from this {@code Coordinate} to a specified {@code Coordinate}
|
---|
46 | */
|
---|
47 | public double distanceSq(final Coordinate coor) {
|
---|
48 | final double dx = this.x-coor.x;
|
---|
49 | final double dy = this.y-coor.y;
|
---|
50 | return dx*dx + dy*dy;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public int hashCode() {
|
---|
55 | final int prime = 31;
|
---|
56 | int result = super.hashCode();
|
---|
57 | long temp;
|
---|
58 | temp = java.lang.Double.doubleToLongBits(x);
|
---|
59 | result = prime * result + (int) (temp ^ (temp >>> 32));
|
---|
60 | temp = java.lang.Double.doubleToLongBits(y);
|
---|
61 | result = prime * result + (int) (temp ^ (temp >>> 32));
|
---|
62 | return result;
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public boolean equals(Object obj) {
|
---|
67 | if (this == obj)
|
---|
68 | return true;
|
---|
69 | if (getClass() != obj.getClass())
|
---|
70 | return false;
|
---|
71 | Coordinate other = (Coordinate) obj;
|
---|
72 | if (java.lang.Double.doubleToLongBits(x) != java.lang.Double.doubleToLongBits(other.x))
|
---|
73 | return false;
|
---|
74 | if (java.lang.Double.doubleToLongBits(y) != java.lang.Double.doubleToLongBits(other.y))
|
---|
75 | return false;
|
---|
76 | return true;
|
---|
77 | }
|
---|
78 | }
|
---|