source: josm/trunk/src/org/openstreetmap/josm/data/coor/Coordinate.java@ 627

Last change on this file since 627 was 627, checked in by framm, 16 years ago
  • Property svn:eol-style set to native
File size: 2.0 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.coor;
3
4import java.io.Serializable;
5
6/**
7 * Base class of points of both coordinate system.
8 *
9 * The variables are default package protected to allow routines in the data package
10 * to access them directly.
11 *
12 * As the class itself is package protected too, it is not visible outside of the data
13 * package. Routines there should only use LatLon or EastNorth
14 *
15 * @author imi
16 */
17abstract class Coordinate implements Serializable {
18
19 /**
20 * Either easting or latitude
21 */
22 final double x;
23 /**
24 * Either northing or longitude
25 */
26 final double y;
27
28 /**
29 * Construct the point with latitude / longitude values.
30 * The x/y values are left uninitialized.
31 *
32 * @param lat Latitude of the point.
33 * @param lon Longitude of the point.
34 */
35 Coordinate(double x, double y) {
36 this.x = x;
37 this.y = y;
38 }
39
40 /**
41 * Return the squared distance of the northing/easting values between
42 * this and the argument.
43 *
44 * This method does NOT compute a great circle distance between two
45 * locations!
46 *
47 * @param other The other point to calculate the distance to.
48 * @return The square of the distance between this and the other point,
49 * regarding to the x/y values.
50 */
51 public double distanceSq(Coordinate other) {
52 return (x-other.x)*(x-other.x)+(y-other.y)*(y-other.y);
53 }
54
55 /**
56 * Return the distance of the northing/easting values between this and
57 * the argument.
58 *
59 * This method does NOT compute a great circle distance between two
60 * locations!
61 *
62 * @param other The other point to calculate the distance to.
63 * @return The square of the distance between this and the other point,
64 * regarding to the x/y values.
65 */
66 public double distance(Coordinate other) {
67 return Math.sqrt(distanceSq(other));
68 }
69
70 @Override public boolean equals(Object obj) {
71 return obj instanceof Coordinate ? x == ((Coordinate)obj).x && ((Coordinate)obj).y == y : false;
72 }
73
74 @Override public int hashCode() {
75 return (int)(x*65536+y*4096);
76 }
77}
Note: See TracBrowser for help on using the repository browser.