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