annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/Utils.java @ 4323:33d6d4025d0f

FixWQCurveGenerator: Handle extreme_wq_curve facets (stub).
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 30 Oct 2012 12:06:29 +0100
parents 5cc9453456a7
children b195fede1c3b
rev   line source
4259
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.math;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
2
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
3
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
4 public final class Utils {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
5
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
6 public static final double EPSILON = 1e-3;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
7
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
8 private Utils() {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
9 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
10
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
11 public static final boolean epsilonEquals(double a, double b) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
12 return epsilonEquals(a, b, EPSILON);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
13 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
14
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
15 public static final boolean epsilonEquals(double a, double b, double eps) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
16 return Math.abs(a - b) < eps;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
17 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
18
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
19 public static int relativeCCW(
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
20 double x1, double y1,
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
21 double x2, double y2,
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
22 double px, double py
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
23 ) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
24 if ((epsilonEquals(x1, x2) && epsilonEquals(y1, y2))
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
25 || ((epsilonEquals(x1, px) && epsilonEquals(y1, py)))) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
26 return 0; // Coincident points.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
27 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
28 // Translate to the origin.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
29 x2 -= x1;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
30 y2 -= y1;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
31 px -= x1;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
32 py -= y1;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
33 double slope2 = y2 / x2;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
34 double slopep = py / px;
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
35 if (epsilonEquals(slope2, slopep)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
36 || (epsilonEquals(x2, 0.0) && epsilonEquals(px, 0.0))) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
37 return y2 > EPSILON // Colinear.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
38 ? (py < -EPSILON ? -1 : py > y2 ? 1 : 0)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
39 : (py > -EPSILON ? -1 : py < y2 ? 1 : 0);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
40 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
41 if (x2 >= EPSILON && slope2 >= EPSILON) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
42 return px >= EPSILON // Quadrant 1.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
43 ? (slope2 > slopep ? 1 : -1)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
44 : (slope2 < slopep ? 1 : -1);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
45 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
46
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
47 if (y2 > EPSILON) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
48 return px < -EPSILON // Quadrant 2.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
49 ? (slope2 > slopep ? 1 : -1)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
50 : (slope2 < slopep ? 1 : -1);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
51 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
52 if (slope2 >= EPSILON) {
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
53 return px >= EPSILON // Quadrant 3.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
54 ? (slope2 < slopep ? 1 : -1)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
55 : (slope2 > slopep ? 1 : -1);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
56 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
57 return px < -EPSILON // Quadrant 4.
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
58 ? (slope2 < slopep ? 1 : -1)
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
59 : (slope2 > slopep ? 1 : -1);
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
60 }
5cc9453456a7 First complete but untested version of the 'Auslagerung extremer Wasserspiegellagen' calculation.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
diff changeset
61 }

http://dive4elements.wald.intevation.org