[298] | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others
|
---|
[71] | 2 | package org.openstreetmap.josm.data.coor;
|
---|
| 3 |
|
---|
[1004] | 4 | import java.awt.geom.Point2D;
|
---|
[1094] | 5 | import java.io.Serializable;
|
---|
[71] | 6 |
|
---|
| 7 | /**
|
---|
[655] | 8 | * Base class of points of both coordinate systems.
|
---|
[1169] | 9 | *
|
---|
| 10 | * The variables are default package protected to allow routines in the
|
---|
[1094] | 11 | * data package to access them directly.
|
---|
[1169] | 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
|
---|
[1094] | 15 | * EastNorth.
|
---|
[71] | 16 | *
|
---|
| 17 | * @author imi
|
---|
[1169] | 18 | */
|
---|
[1094] | 19 | abstract class Coordinate extends Point2D implements Serializable {
|
---|
[71] | 20 |
|
---|
[1004] | 21 | protected double x;
|
---|
| 22 | protected double y;
|
---|
[1169] | 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) {
|
---|
[1004] | 31 | this.x = x; this.y = y;
|
---|
[1169] | 32 | }
|
---|
| 33 |
|
---|
[1004] | 34 | public double getX() {
|
---|
| 35 | return x;
|
---|
| 36 | }
|
---|
[1169] | 37 |
|
---|
[1004] | 38 | public double getY() {
|
---|
[1169] | 39 | return y;
|
---|
[1004] | 40 | }
|
---|
[1169] | 41 |
|
---|
[1004] | 42 | public void setLocation (double x, double y) {
|
---|
[1169] | 43 | this.x = x;
|
---|
[1004] | 44 | this.y = y;
|
---|
| 45 | }
|
---|
[71] | 46 |
|
---|
[2327] | 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 | }
|
---|
[71] | 74 | }
|
---|