comparison backend/src/main/java/org/dive4elements/river/importer/XY.java @ 7730:e1b831fe435a slt-simplify-cross-sections

Merged default into slt-simplify-cross-sections branch and updated package and class names.
author Tom Gottfried <tom@intevation.de>
date Mon, 20 Jan 2014 14:04:20 +0100
parents flys-backend/src/main/java/de/intevation/flys/importer/XY.java@7bbee0cfc171 flys-backend/src/main/java/de/intevation/flys/importer/XY.java@4c3ccf2b0304
children
comparison
equal deleted inserted replaced
5084:ca45dd039b54 7730:e1b831fe435a
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
2 * Software engineering by Intevation GmbH
3 *
4 * This file is Free Software under the GNU AGPL (>=v3)
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
6 * documentation coming with Dive4Elements River for details.
7 */
8
9 package org.dive4elements.river.importer;
10
11
12 /** Two doubles and an int index. */
13 public class XY
14 implements Comparable<XY>
15 {
16 public static final double X_EPSILON = 1e-4;
17
18 protected double x;
19 protected double y;
20 protected int index;
21
22 public XY() {
23 }
24
25 public XY(XY other) {
26 this(other.x, other.y, other.index);
27 }
28
29 public XY(double x, double y, int index) {
30 this.x = x;
31 this.y = y;
32 this.index = index;
33 }
34
35 @Override
36 public int compareTo(XY other) {
37 if (x + X_EPSILON < other.x) return -1;
38 if (x > other.x + X_EPSILON) return +1;
39 if (index < other.index) return -1;
40 if (index > other.index) return +1;
41 return 0;
42 }
43
44 public double getX() {
45 return x;
46 }
47
48 public void setX(double x) {
49 this.x = x;
50 }
51
52 public double getY() {
53 return y;
54 }
55
56 public void setY(double y) {
57 this.y = y;
58 }
59
60 public int getIndex() {
61 return index;
62 }
63
64 public void setIndex(int index) {
65 this.index = index;
66 }
67
68 public double dot(double ox, double oy) {
69 return x*ox + y*oy;
70 }
71
72 public double dot(XY other) {
73 return dot(other.x, other.y);
74 }
75
76 public XY sub(XY other) {
77 x -= other.x;
78 y -= other.y;
79 return this;
80 }
81
82 public XY ortho() {
83 double z = x;
84 x = y;
85 y = -z;
86 return this;
87 }
88
89 public XY normalize() {
90 double len = dot(this);
91
92 if (len > 1e-6) {
93 len = 1d/Math.sqrt(len);
94 x *= len;
95 y *= len;
96 }
97
98 return this;
99 }
100
101 // x*nx + y*ny + d = 0 <=> d = -x*nx -y*ny
102 public double lineOffset(XY p) {
103 return -x*p.x -y*p.y;
104 }
105 }
106 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org