source: josm/trunk/src/org/openstreetmap/josm/data/coor/EastNorth.java@ 1076

Last change on this file since 1076 was 1076, checked in by framm, 16 years ago
  • replaced he align-in-rectangle function with a more general method that will make all angles in the selected shape orthogonal. if, in addition to one or more ways, exactly two nodes are also selected, then these two nodes determine the orientation of each resulting segment, otherwise a best match is chosen. Patch by Harald Kucharek.
  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1// License: GPL. Copyright 2007 by Immanuel Scholz and others
2package org.openstreetmap.josm.data.coor;
3
4/**
5 * Northing, Easting of the projected coordinates.
6 *
7 * This class is immutable.
8 *
9 * @author Imi
10 */
11public class EastNorth extends Coordinate {
12
13 public EastNorth(double east, double north) {
14 super(east,north);
15 }
16
17 public double east() {
18 return x;
19 }
20
21 public double north() {
22 return y;
23 }
24
25 public EastNorth add(double dx, double dy) {
26 return new EastNorth(x+dx, y+dy);
27 }
28
29 public EastNorth interpolate(EastNorth en2, double proportion) {
30 return new EastNorth(this.x + proportion * (en2.x - this.x),
31 this.y + proportion * (en2.y - this.y));
32 }
33
34 /**
35 * Returns the heading, in radians, that you have to use to get from
36 * this EastNorth to another. Heading is mapped into [0, 2pi)
37 *
38 * @param other the "destination" position
39 * @return heading
40 */
41 public double heading(EastNorth other) {
42 double hd = Math.atan2(other.east() - east(), other.north() - north());
43 if(hd < 0) hd = 2 * Math.PI + hd;
44 return hd;
45 }
46
47 public EastNorth sub(EastNorth en) {
48 return new EastNorth(en.east() - east(), en.north() - north());
49 }
50
51 /**
52 * Returns an EastNorth representing the this EastNorth rotatedaround
53 * a given EastNorth by a given angle
54 * @param pivot the center of the rotation
55 * @param angle the angle of the rotation
56 * @return EastNorth rotated object
57 */
58 public EastNorth rotate(EastNorth pivot, double angle) {
59 double cosPhi = Math.cos(angle);
60 double sinPhi = Math.sin(angle);
61 double x = east() - pivot.east();
62 double y = north() - pivot.north();
63 double nx = cosPhi * x + sinPhi * y + pivot.east();
64 double ny = -sinPhi * x + cosPhi * y + pivot.north();
65 return new EastNorth(nx, ny);
66 }
67
68 @Override public String toString() {
69 return "EastNorth[e="+x+", n="+y+"]";
70 }
71
72 /**
73 * Compares two EastNorth values
74 *
75 * @return true if "x" and "y" values are within 1E-6 of each other
76 */
77 public boolean equalsEpsilon(EastNorth other, double e) {
78 return (Math.abs(x - other.x) < e && Math.abs(y - other.y) < e);
79 }
80}
Note: See TracBrowser for help on using the repository browser.