Mercurial > dive4elements > river
changeset 1798:552888e9c64a
Polygon2D: Handle start points when building polygons. Work in progress.
flys-artifacts/trunk@3121 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 31 Oct 2011 11:32:11 +0000 (2011-10-31) |
parents | 5eec623db50a |
children | 281b9430c720 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java |
diffstat | 2 files changed, 66 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Mon Oct 31 10:03:32 2011 +0000 +++ b/flys-artifacts/ChangeLog Mon Oct 31 11:32:11 2011 +0000 @@ -1,3 +1,8 @@ +2011-10-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java: + Handle start points when building polygons. Work in progress. + 2011-10-31 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/java/de/intevation/flys/artifacts/geom/VectorUtils.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java Mon Oct 31 10:03:32 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Polygon2D.java Mon Oct 31 11:32:11 2011 +0000 @@ -13,6 +13,8 @@ import java.util.Comparator; import java.util.Collections; +import de.intevation.flys.artifacts.math.Linear; + public class Polygon2D implements Serializable { @@ -54,7 +56,7 @@ points.add(new Point2D.Double(x, y)); } - public boolean addCheck(Point2D p) { + protected static boolean addCheck(Point2D p, List<Point2D> points) { switch (points.size()) { case 0: points.add(p); @@ -82,6 +84,10 @@ } } + public boolean addCheck(Point2D p) { + return addCheck(p, points); + } + public void addReversed(List<Point2D> other) { for (int i = other.size()-1; i >= 0; --i) { addCheck(other.get(i)); @@ -156,9 +162,10 @@ List<Point2D []> As, List<Point2D []> Bs ) { + int B = Bs.size()-1; OUTER: for (int i = 0; i < As.size();) { Point2D [] a = As.get(i); - int lo = 0, hi = Bs.size()-1; + int lo = 0, hi = B; while (lo <= hi) { int mid = (lo + hi) >> 1; Point2D [] b = Bs.get(mid); @@ -184,6 +191,58 @@ List<Polygon2D> positives, List<Polygon2D> negatives ) { + List<Point2D> apoints = new ArrayList<Point2D>(); + List<Point2D> bpoints = new ArrayList<Point2D>(); + + double ax = X(as[0]); + double bx = X(bs[0]); + + int ai = 0; + int bi = 0; + + if (ax == bx) { + apoints.add(as[0]); + bpoints.add(bs[0]); + } + else if (ax > bx) { + apoints.add(as[0]); + bi = 1; // exists because of overlap + double bx1; + while ((bx1 = X(bs[bi])) < ax) ++bi; + if (bx1 == ax) { + bpoints.add(bs[bi]); + } + else { // need to calculate start b point. + double by1 = Linear.linear( + ax, + X(bs[bi-1]), bx1, + Y(bs[bi-1]), Y(bs[bi])); + + bpoints.add(new Point2D.Double(ax, by1)); + } + } + else { // bx > ax: Symmetric case + bpoints.add(bs[0]); + ai = 1; // exists because of overlap + double ax1; + while ((ax1 = X(as[ai])) < bx) ++ai; + if (ax1 == bx) { + apoints.add(as[ai]); + } + else { // need to calculate start b point. + double ay1 = Linear.linear( + bx, + X(as[ai-1]), ax1, + Y(as[ai-1]), Y(as[ai])); + + apoints.add(new Point2D.Double(bx, ay1)); + } + } + + // now we have a point in each list, decide if neg/pos. + boolean neg = Y(bpoints.get(0)) > Y(apoints.get(0)); + + // TODO: Continue with inner points } public static void createPolygons(