Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java @ 3743:51f76225823b
Extreme waterlevels: calculate the segments for Q km ranges.
flys-artifacts/trunk@5426 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 10 Sep 2012 15:59:34 +0000 |
parents | 3c006a53e551 |
children |
rev | line source |
---|---|
3227
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
1 package de.intevation.flys.artifacts.geom; |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.awt.Shape; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.awt.geom.Path2D; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.awt.geom.Point2D; |
3227
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
6 import java.io.Serializable; |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.ArrayList; |
3227
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
8 import java.util.Arrays; |
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
9 import java.util.Collections; |
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
10 import java.util.Comparator; |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 import java.util.List; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
13 import de.intevation.flys.artifacts.math.Linear; |
3227
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
14 import static de.intevation.flys.artifacts.geom.VectorUtils.EPSILON; |
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
15 import static de.intevation.flys.artifacts.geom.VectorUtils.X; |
ed07dd55f487
Fixed various bugs (package declarations, moved classes to correct places).
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
3076
diff
changeset
|
16 import static de.intevation.flys.artifacts.geom.VectorUtils.Y; |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
17 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 public class Polygon2D |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 implements Serializable |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public static final Comparator<Point2D> POINT_X_CMP = |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 new Comparator<Point2D>() { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public int compare(Point2D a, Point2D b) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
24 double d = X(a) - X(b); |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 if (d < 0d) return -1; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 return d > 0d ? + 1 : 0; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 }; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 public static final Comparator<Point2D []> FIRST_POINT_X = |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 new Comparator<Point2D []>() { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public int compare(Point2D [] a, Point2D [] b) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 if (a.length == 0) return -1; // should not happen. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 if (b.length == 0) return +1; // should not happen. |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
35 double d = X(a[0]) - Y(b[0]); |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 if (d < 0d) return -1; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 return d > 0d ? + 1 : 0; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 }; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
41 protected List<Point2D> points; |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 public Polygon2D() { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
44 points = new ArrayList<Point2D>(); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
45 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
46 |
1800
1402991208d5
Polygon2D: made it compilable again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1799
diff
changeset
|
47 public Polygon2D(List<Point2D> points) { |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
48 this.points = points; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
49 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
50 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 public void add(double x, double y) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
52 points.add(new Point2D.Double(x, y)); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
53 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
54 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
55 protected static boolean addCheck(Point2D p, List<Point2D> points) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
56 switch (points.size()) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
57 case 0: |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
58 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
59 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
60 case 1: |
1797
5eec623db50a
Polygon2D: moved 2D vector operation to separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1795
diff
changeset
|
61 if (VectorUtils.epsilonEquals(points.get(0), p)) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
62 return false; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
63 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
64 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
65 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
66 default: |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
67 int L = points.size()-1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
68 Point2D last = points.get(L); |
1797
5eec623db50a
Polygon2D: moved 2D vector operation to separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1795
diff
changeset
|
69 if (VectorUtils.epsilonEquals(last, p)) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
70 return false; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
71 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
72 Point2D before = points.get(L-1); |
1797
5eec623db50a
Polygon2D: moved 2D vector operation to separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1795
diff
changeset
|
73 if (VectorUtils.collinear(before, last, p)) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
74 points.set(L, p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
75 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
76 else { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
77 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
78 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
79 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
80 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
81 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
82 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
83 public boolean addCheck(Point2D p) { |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
84 return addCheck(p, points); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
85 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
86 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
87 public void addReversed(List<Point2D> other) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
88 for (int i = other.size()-1; i >= 0; --i) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
89 addCheck(other.get(i)); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
90 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
91 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
92 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 public double area() { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 double area = 0d; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 |
3258
3c006a53e551
Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3227
diff
changeset
|
96 for (int i = 0, N = points.size(); i < N; ++i) { |
3c006a53e551
Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3227
diff
changeset
|
97 int j = (i + 1) % N; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
98 Point2D pi = points.get(i); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
99 Point2D pj = points.get(j); |
3258
3c006a53e551
Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3227
diff
changeset
|
100 area += X(pi)*Y(pj); |
3c006a53e551
Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3227
diff
changeset
|
101 area -= X(pj)*Y(pi); |
3c006a53e551
Replaced tabs with four spaces each.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3227
diff
changeset
|
102 } |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 return 0.5d*area; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 public Shape toShape() { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 Path2D.Double path = new Path2D.Double(); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
110 int N = points.size(); |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 if (N > 0) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
113 Point2D p = points.get(0); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
114 path.moveTo(X(p), Y(p)); |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 for (int i = 1; i < N; ++i) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
116 p = points.get(i); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
117 path.lineTo(X(p), Y(p)); |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 path.closePath(); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 return path; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 protected static List<Point2D []> splitByNaNs( |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 double [] xs, |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 double [] ys |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 ) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 List<Point2D []> parts = new ArrayList<Point2D []>(); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 List<Point2D> tmp = new ArrayList<Point2D>(xs.length); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 for (int i = 0; i < xs.length; ++i) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 double x = xs[i]; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 double y = ys[i]; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 if (Double.isNaN(x) || Double.isNaN(y)) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 if (!tmp.isEmpty()) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 Point2D [] part = new Point2D[tmp.size()]; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 parts.add(tmp.toArray(part)); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 tmp.clear(); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 else { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 tmp.add(new Point2D.Double(x, y)); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 if (!tmp.isEmpty()) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 Point2D [] part = new Point2D[tmp.size()]; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 parts.add(tmp.toArray(part)); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 return parts; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
157 protected static boolean removeNoneIntersecting( |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
158 List<Point2D []> As, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
159 List<Point2D []> Bs |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
160 ) { |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
161 int B = Bs.size()-1; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
162 OUTER: for (int i = 0; i < As.size();) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
163 Point2D [] a = As.get(i); |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
164 int lo = 0, hi = B; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
165 while (lo <= hi) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
166 int mid = (lo + hi) >> 1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
167 Point2D [] b = Bs.get(mid); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
168 if (X(a[0]) > X(b[b.length-1])) lo = mid+1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
169 else if (X(a[a.length-1]) < X(b[0])) hi = mid-1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
170 else { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
171 // found: keep |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
172 ++i; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
173 continue OUTER; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
174 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
175 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
176 // not found: remove |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
177 As.remove(i); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
178 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
179 |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
180 return As.isEmpty(); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
181 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
182 |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
183 protected static void buildPolygons( |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
184 Point2D [] as, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
185 Point2D [] bs, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
186 Point2D [][] rest, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
187 List<Polygon2D> positives, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
188 List<Polygon2D> negatives |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
189 ) { |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
190 List<Point2D> apoints = new ArrayList<Point2D>(); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
191 List<Point2D> bpoints = new ArrayList<Point2D>(); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
192 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
193 double ax = X(as[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
194 double bx = X(bs[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
195 |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
196 int ai = 1; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
197 int bi = 1; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
198 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
199 boolean intersect = false; |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
200 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
201 if (ax == bx) { |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
202 apoints.add(as[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
203 bpoints.add(bs[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
204 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
205 else if (ax > bx) { |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
206 apoints.add(as[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
207 double bx1; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
208 while ((bx1 = X(bs[bi])) < ax) ++bi; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
209 if (bx1 == ax) { |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
210 bpoints.add(bs[bi]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
211 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
212 else { // need to calculate start b point. |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
213 intersect = true; |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
214 double by1 = Linear.linear( |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
215 ax, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
216 X(bs[bi-1]), bx1, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
217 Y(bs[bi-1]), Y(bs[bi])); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
218 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
219 bpoints.add(new Point2D.Double(ax, by1)); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
220 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
221 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
222 else { // bx > ax: Symmetric case |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
223 bpoints.add(bs[0]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
224 double ax1; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
225 while ((ax1 = X(as[ai])) < bx) ++ai; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
226 if (ax1 == bx) { |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
227 apoints.add(as[ai]); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
228 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
229 else { // need to calculate start b point. |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
230 intersect = true; |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
231 double ay1 = Linear.linear( |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
232 bx, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
233 X(as[ai-1]), ax1, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
234 Y(as[ai-1]), Y(as[ai])); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
235 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
236 apoints.add(new Point2D.Double(bx, ay1)); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
237 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
238 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
239 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
240 // now we have a point in each list, decide if neg/pos. |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
241 boolean neg = Y(bpoints.get(0)) > Y(apoints.get(0)); |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
242 |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
243 // Continue with inner points |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
244 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
245 Line line = new Line(); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
246 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
247 while (ai < as.length && bi < bs.length) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
248 double xan = X(as[ai]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
249 double xbn = X(bs[bi]); |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1801
diff
changeset
|
250 if (xan == xbn) { |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
251 double yan = Y(as[ai]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
252 double ybn = Y(bs[ai]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
253 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
254 if (neg) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
255 if (yan > ybn) { // intersection |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
256 Point2D ip = VectorUtils.intersection( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
257 apoints.get(apoints.size()-1), as[ai], |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
258 bpoints.get(bpoints.size()-1), bs[bi]); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
259 addCheck(ip, apoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
260 addCheck(ip, bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
261 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
262 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
263 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
264 negatives.add(p); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
265 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
266 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
267 apoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
268 bpoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
269 neg = !neg; |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
270 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
271 else { // no intersection |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
272 addCheck(as[ai], apoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
273 addCheck(bs[bi], bpoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
274 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
275 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
276 else { // not neg |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
277 if (ybn > yan) { // intersection |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
278 Point2D ip = VectorUtils.intersection( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
279 apoints.get(apoints.size()-1), as[ai], |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
280 bpoints.get(bpoints.size()-1), bs[bi]); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
281 addCheck(ip, apoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
282 addCheck(ip, bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
283 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
284 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
285 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
286 positives.add(p); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
287 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
288 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
289 apoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
290 bpoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
291 neg = !neg; |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
292 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
293 else { // no intersection |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
294 addCheck(as[ai], apoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
295 addCheck(bs[bi], bpoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
296 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
297 } |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
298 ++ai; |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
299 ++bi; |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
300 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
301 else if (xan > xbn) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
302 line.set(apoints.get(apoints.size()-1), as[ai]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
303 double dir = neg ? -1d: 1d; // XXX: correct sign? |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1801
diff
changeset
|
304 while (bi < bs.length |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
305 && X(bs[bi]) < xan |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1801
diff
changeset
|
306 && line.eval(bs[bi])*dir > EPSILON) |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
307 ++bi; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
308 if (bi == bs.length) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
309 // b run out of points |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
310 // calculate Y(last_a, as[ai]) for X(bs[bi-1]) |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
311 double ay1 = Linear.linear( |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
312 X(bs[bi-1]), |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
313 X(apoints.get(apoints.size()-1)), X(as[ai]), |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
314 Y(apoints.get(apoints.size()-1)), Y(as[ai])); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
315 addCheck(new Point2D.Double(X(bs[bi-1]), ay1), apoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
316 addCheck(bs[bi-1], bpoints); |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
317 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
318 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
319 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
320 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
321 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
322 (neg ? negatives : positives).add(p); |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
323 break; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
324 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
325 else { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
326 // TODO: intersect line and/or X(bs[bi]) >= xan? |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
327 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
328 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
329 else { // xbn > xan |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
330 line.set(bpoints.get(bpoints.size()-1), bs[bi]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
331 // TODO: continue symmetric |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
332 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
333 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
334 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
335 // TODO: Continue with closing segment |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
336 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
337 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
338 public static final class Line { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
339 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
340 private double a; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
341 private double b; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
342 private double c; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
343 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
344 public Line() { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
345 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
346 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
347 public Line(Point2D p1, Point2D p2) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
348 set(p1, p2); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
349 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
350 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
351 public void set(Point2D p1, Point2D p2) { |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1801
diff
changeset
|
352 Point2D p3 = |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
353 VectorUtils.normalize( |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
354 VectorUtils.sub(p1, p2)); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
355 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
356 Point2D n = VectorUtils.ortho(p3); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
357 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
358 a = X(n); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
359 b = Y(n); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
360 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
361 // a*x + b*y + c = 0 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
362 // c = -a*x -b*y |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
363 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
364 c = -a*X(p1) - b*Y(p1); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
365 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
366 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
367 public double eval(Point2D p) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
368 return a*X(p) + b*Y(p) + c; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
369 } |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
370 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
371 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 public static void createPolygons( |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
373 double [] xAs, double [] yAs, |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
374 double [] xBs, double [] yBs, |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
375 List<Polygon2D> positives, |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
376 List<Polygon2D> negatives |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
377 ) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
378 if (xAs.length == 0 || xBs.length == 0) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 return; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
380 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 List<Point2D []> splAs = splitByNaNs(xAs, yAs); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 List<Point2D []> splBs = splitByNaNs(xBs, yBs); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
384 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 // They feeded us with NaNs only. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 if (splAs.isEmpty() || splBs.isEmpty()) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
387 return; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
388 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
389 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
390 // Sort each part by x to ensure that the first |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
391 // is the smallest. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
392 for (Point2D [] splA: splAs) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
393 Arrays.sort(splA, POINT_X_CMP); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
395 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
396 for (Point2D [] splB: splBs) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 Arrays.sort(splB, POINT_X_CMP); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
400 // Now sort all parts by there first elements. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
401 // Should be good enough to find overlapping regions. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 Collections.sort(splAs, FIRST_POINT_X); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 Collections.sort(splBs, FIRST_POINT_X); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
405 // Check if the two series intersect at all. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 // If no then there will be no area between them. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
408 Point2D [] p1 = splAs.get(0); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 Point2D [] p2 = splBs.get(splBs.size()-1); |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
410 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
411 // Sort out the ranges that are not intersecting |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
412 // the ranges in the other series. |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
413 // We are going to merge them anyway |
3076
5642a83420f2
FLYS artifacts: Removed trailing whitespace.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1801
diff
changeset
|
414 // so this is not strictly required. |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
415 // Keep it to recude cases. |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
416 if (removeNoneIntersecting(splAs, splBs) |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
417 || removeNoneIntersecting(splBs, splAs) |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
418 ) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
419 // They do not intersect at all. |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
420 return; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
422 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 // TODO: Intersect/split the two series parts. |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
424 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
425 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |