diff --git a/main/CompGeo.pde b/main/CompGeo.pde index 308da4b..4e52df8 100644 --- a/main/CompGeo.pde +++ b/main/CompGeo.pde @@ -1,6 +1,6 @@ public static class CompGeo { - public int CCW(Point a, Point b, Point c) { + public static int CCW(Point a, Point b, Point c) { // Return 1 if turn abc is ccw -1 if turn abc is cw 0 if no turn float f = (b.getX() - a.getX())*(c.getY() - a.getY()) - (c.getX() - a.getX())*(b.getY()-a.getY()); if (f < 0) { return -1; } @@ -8,7 +8,7 @@ public static class CompGeo { return 0; } - public int immediateCCW(Point parent, Point child, Point v1, Point v2) { + public static int immediateCCW(Point parent, Point child, Point v1, Point v2) { // returns 1 if v1 is more immediate CCW of parent, child than v2 // returns -1 if v2 is more immediate CCW of parent, child than v1 if (CCW(parent, child, v1) > CCW(parent, child, v2)) { return 1; } @@ -16,4 +16,6 @@ public static class CompGeo { return CCW(parent, v1, v2); } + + } \ No newline at end of file diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index c383e26..d8a2062 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -10,6 +10,76 @@ public class HalfEdge { public HalfEdge(){} + public HalfEdge(Point p, Point q) { + // SETS THE TWIN + settwin(new HalfEdge()); + twin.settwin(this); + // SETS THE ORIGIN + setOrigin(p); + twin.setOrigin(q); + // SETS THE COUNTED + setCounted(false); + twin.setCounted(false); + + // MAGIC METHOD + connect(); + twin.connect(); + + + + + } + + public int connect() { + ArrayList others = origin.getEntering(); + if (others == null) { + this.setprevious(gettwin()); + gettwin().setnext(this); + // update vertex + return 0; + } + if (others.size() == 1) { + HalfEdge other = others.get(0); + this.setprevious(other.gettwin()); + gettwin().setnext(other); + // no update vertex + return 1; + } + return complex(this, others); + } + + + public int complex (HalfEdge self, ArrayList entering) { + Point parent = self.getOrigin(); + Point child = self.gettwin().getOrigin(); + Point p1; + Point p2; + int num = entering.size(); + int[] chart = new int[num]; + for (int i = 0; i < num; i++) { + p1 = entering.get(i).getOrigin(); + p2 = entering.get((i+1)%num).getOrigin(); + if (CompGeo.immediateCCW(parent, child, p1, p2) == 1) { chart[i]++; } + else { chart[(i+1)%num]++; } + } + int Loser = 0; + int Winner = 0; + for (int i = 0; i < num; i++) { + if (chart[i] == 0) { Loser = i; } + if (chart[i] == 2) { Winner = i; } + } + self.setprevious(entering.get(Winner)); + entering.get(Winner).setnext(self); + self.gettwin().setnext(entering.get(Loser).gettwin()); + entering.get(Loser).gettwin().setprevious(self.gettwin()); + return 2; + } + + + + + + public int count() { if (counted == false) { counted = true; @@ -29,29 +99,42 @@ public class HalfEdge { } } - public ArrayList getHalfEdgesAlsoLeaving() { - ArrayList result = new ArrayList(); - result.add(this); + public ArrayList getAdjacentPoints() { + ArrayList points = new ArrayList(); HalfEdge temp = previous.gettwin(); while (temp != this) { - result.add(temp); - temp = (temp.getprevious()).gettwin(); + points.add(temp.gettwin().getOrigin()); + temp = temp.getprevious().gettwin(); } - return result; + points.add(this.getOrigin()); + return points; } - public ArrayList getFace() { + public ArrayList getEntering() { ArrayList result = new ArrayList(); - result.add(this); - HalfEdge temp = next; - while (temp != this) { + HalfEdge temp = twin.getnext().gettwin(); + while (temp != twin) { result.add(temp); - temp = temp.getnext(); + temp = temp.getnext().gettwin(); } - return result; + result.add(twin); + return result; } - + public ArrayList getOtherLeaving() { + ArrayList result = new ArrayList(); + HalfEdge temp = previous.gettwin(); + while (temp != this) { + result.add(temp); + temp = (temp.getprevious()).gettwin(); + } + return result; + } + public ArrayList getAllLeaving() { + ArrayList others = getOtherLeaving(); + others.add(this); + return others; + } // may not want getters, but for now they are here. public void setprevious(HalfEdge p) { diff --git a/main/Point.pde b/main/Point.pde index 6c7668e..aa3974e 100644 --- a/main/Point.pde +++ b/main/Point.pde @@ -28,6 +28,19 @@ public class Point { return ((a == x) && (b == y)); } + public ArrayList getLeaving() { + if (ref == null) { return null; } + return ref.getAllLeaving(); + } + + public ArrayList getAdjacentPoints() { + if (ref == null) { return null; } + return ref.getAdjacentPoints(); + } + + public ArrayList getEntering() { + if (ref == null) { return null; } + return ref.getEntering(); + } - // NEED METHOD GETTING ALL EDGES LEAVING POINT } \ No newline at end of file