Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java @ 2253:707b47d8c554
Dont sort the data series in reference curve.
flys-artifacts/trunk@3903 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Fri, 03 Feb 2012 14:53:11 +0000 |
parents | 6f83d9d434f2 |
children | 5642a83420f2 |
rev | line source |
---|---|
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.geom; |
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.io.Serializable; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 |
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.Shape; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
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.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
|
8 import java.awt.geom.Point2D; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 import java.util.ArrayList; |
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 import java.util.Arrays; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 import java.util.Comparator; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 import java.util.Collections; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
16 import de.intevation.flys.artifacts.math.Linear; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
17 |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
18 import static de.intevation.flys.geom.VectorUtils.X; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
19 import static de.intevation.flys.geom.VectorUtils.Y; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
20 import static de.intevation.flys.geom.VectorUtils.EPSILON; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
21 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 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
|
23 implements Serializable |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 }; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 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
|
35 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
|
36 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
|
37 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
|
38 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
|
39 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
|
40 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
|
41 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
|
42 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 }; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
45 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
|
46 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 public Polygon2D() { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
48 points = new ArrayList<Point2D>(); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
49 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
50 |
1800
1402991208d5
Polygon2D: made it compilable again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1799
diff
changeset
|
51 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
|
52 this.points = points; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
53 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
54 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 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
|
56 points.add(new Point2D.Double(x, y)); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
57 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
58 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
59 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
|
60 switch (points.size()) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
61 case 0: |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
62 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
63 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
64 case 1: |
1797
5eec623db50a
Polygon2D: moved 2D vector operation to separate class.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1795
diff
changeset
|
65 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
|
66 return false; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
67 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
68 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
69 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
70 default: |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
71 int L = points.size()-1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
72 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
|
73 if (VectorUtils.epsilonEquals(last, p)) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
74 return false; |
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 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
|
77 if (VectorUtils.collinear(before, last, p)) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
78 points.set(L, p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
79 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
80 else { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
81 points.add(p); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
82 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
83 return true; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
84 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
85 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
86 |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
87 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
|
88 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
|
89 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
90 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
91 public void addReversed(List<Point2D> other) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
92 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
|
93 addCheck(other.get(i)); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
94 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
95 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
96 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 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
|
98 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
|
99 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
100 for (int i = 0, N = points.size(); i < N; ++i) { |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 int j = (i + 1) % N; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
102 Point2D pi = points.get(i); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
103 Point2D pj = points.get(j); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
104 area += X(pi)*Y(pj); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
105 area -= X(pj)*Y(pi); |
1794
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 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 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
|
109 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 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
|
112 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
|
113 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
114 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
|
115 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 if (N > 0) { |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
117 Point2D p = points.get(0); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
118 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
|
119 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
|
120 p = points.get(i); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
121 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
|
122 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 path.closePath(); |
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 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 return path; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
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 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
|
130 double [] xs, |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 double [] ys |
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 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
|
134 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 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
|
136 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 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
|
138 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
|
139 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
|
140 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 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
|
142 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
|
143 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
|
144 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
|
145 tmp.clear(); |
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 else { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 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
|
150 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 } |
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 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
|
154 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
|
155 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
|
156 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 return parts; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
161 protected static boolean removeNoneIntersecting( |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
162 List<Point2D []> As, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
163 List<Point2D []> Bs |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
164 ) { |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
165 int B = Bs.size()-1; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
166 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
|
167 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
|
168 int lo = 0, hi = B; |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
169 while (lo <= hi) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
170 int mid = (lo + hi) >> 1; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
171 Point2D [] b = Bs.get(mid); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
172 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
|
173 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
|
174 else { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
175 // found: keep |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
176 ++i; |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
177 continue OUTER; |
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 // not found: remove |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
181 As.remove(i); |
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 |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
184 return As.isEmpty(); |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
185 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
186 |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
187 protected static void buildPolygons( |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
188 Point2D [] as, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
189 Point2D [] bs, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
190 Point2D [][] rest, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
191 List<Polygon2D> positives, |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
192 List<Polygon2D> negatives |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
193 ) { |
1798
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
194 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
|
195 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
|
196 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
197 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
|
198 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
|
199 |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
200 int ai = 1; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
201 int bi = 1; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
202 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
203 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
|
204 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
205 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 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
|
208 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
209 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
|
210 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
|
211 double bx1; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
216 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
|
217 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
|
218 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
|
219 ax, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
220 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
|
221 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
|
222 |
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(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
|
224 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
225 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
226 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
|
227 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
|
228 double ax1; |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 bx, |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
237 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
|
238 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
|
239 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
240 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
|
241 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
242 } |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
243 |
552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1797
diff
changeset
|
244 // 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
|
245 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
|
246 |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
247 // Continue with inner points |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
248 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
249 Line line = new Line(); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
250 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
251 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
|
252 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
|
253 double xbn = X(bs[bi]); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
254 if (xan == xbn) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
255 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
|
256 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
|
257 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
258 if (neg) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
259 if (yan > ybn) { // intersection |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
260 Point2D ip = VectorUtils.intersection( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
261 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
|
262 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
|
263 addCheck(ip, apoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
264 addCheck(ip, bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
265 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
266 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
267 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
268 negatives.add(p); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
269 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
270 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
271 apoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
272 bpoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
273 neg = !neg; |
1799
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 else { // no intersection |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
276 addCheck(as[ai], apoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
277 addCheck(bs[bi], bpoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
278 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
279 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
280 else { // not neg |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
281 if (ybn > yan) { // intersection |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
282 Point2D ip = VectorUtils.intersection( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
283 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
|
284 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
|
285 addCheck(ip, apoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
286 addCheck(ip, bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
287 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
288 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
289 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
290 positives.add(p); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
291 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
292 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
293 apoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
294 bpoints.add(ip); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
295 neg = !neg; |
1799
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 else { // no intersection |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
298 addCheck(as[ai], apoints); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
299 addCheck(bs[bi], bpoints); |
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 } |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
302 ++ai; |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
303 ++bi; |
1799
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
304 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
305 else if (xan > xbn) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
306 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
|
307 double dir = neg ? -1d: 1d; // XXX: correct sign? |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
308 while (bi < bs.length |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
309 && X(bs[bi]) < xan |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
310 && line.eval(bs[bi])*dir > EPSILON) |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
311 ++bi; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
312 if (bi == bs.length) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
313 // 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
|
314 // 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
|
315 double ay1 = Linear.linear( |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
316 X(bs[bi-1]), |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 addCheck(bs[bi-1], bpoints); |
1801
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
321 Polygon2D p = new Polygon2D( |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
322 new ArrayList<Point2D>(apoints)); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
323 p.addReversed(bpoints); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
324 apoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
325 bpoints.clear(); |
6f83d9d434f2
Polygon2D: Generate polygons for trivial cases.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1800
diff
changeset
|
326 (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
|
327 break; |
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 { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
330 // 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
|
331 } |
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 else { // xbn > xan |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
334 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
|
335 // TODO: continue symmetric |
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 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
339 // 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
|
340 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
341 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
342 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
|
343 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
344 private double a; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
345 private double b; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
346 private double c; |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
347 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
348 public Line() { |
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 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
|
352 set(p1, p2); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
353 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
354 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
355 public void set(Point2D p1, Point2D p2) { |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
356 Point2D p3 = |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
357 VectorUtils.normalize( |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
358 VectorUtils.sub(p1, p2)); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
359 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
360 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
|
361 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
362 a = X(n); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
363 b = Y(n); |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
364 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
365 // 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
|
366 // 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
|
367 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
368 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
|
369 } |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
370 |
281b9430c720
Polygon2D: More code to build polygons from curve.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1798
diff
changeset
|
371 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
|
372 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
|
373 } |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
374 } |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
375 |
1794
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
376 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
|
377 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
|
378 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
|
379 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
|
380 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
|
381 ) { |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 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
|
383 return; |
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 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
386 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
|
387 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
|
388 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
389 // 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
|
390 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
|
391 return; |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
392 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
393 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 // 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
|
395 // 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
|
396 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
|
397 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
|
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 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
|
401 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
|
402 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
403 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 // 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
|
405 // 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
|
406 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
|
407 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
|
408 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 // 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
|
410 // 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
|
411 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
412 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
|
413 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
|
414 |
1795
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
415 // 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
|
416 // the ranges in the other series. |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
417 // We are going to merge them anyway |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
418 // so this is not strictly required. |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
419 // Keep it to recude cases. |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
420 if (removeNoneIntersecting(splAs, splBs) |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
421 || removeNoneIntersecting(splBs, splAs) |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
422 ) { |
fe7f9264a2ed
Interim checkin for polygon calculation.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1794
diff
changeset
|
423 // 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
|
424 return; |
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 |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
427 // 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
|
428 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
429 } |
2ad7ba85a2b3
Work in progress: Added polygon to help creating 'Raum/Flaeche' renderers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |