diff --git a/main/CompGeo.pde b/main/CompGeo.pde index 0c3dd2f..308da4b 100644 --- a/main/CompGeo.pde +++ b/main/CompGeo.pde @@ -1,6 +1,6 @@ public static class CompGeo { - public int CCW(Vertex a, Vertex b, Vertex c) { + public 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(Vertex parent, Vertex child, Vertex v1, Vertex v2) { + public 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,4 @@ public static class CompGeo { return CCW(parent, v1, v2); } -} +} \ No newline at end of file diff --git a/main/Point.pde b/main/Point.pde index d24a22a..6c7668e 100644 --- a/main/Point.pde +++ b/main/Point.pde @@ -16,7 +16,18 @@ public class Point { return y; } + public HalfEdge getRef() { + return ref; + } + + public void setRef(HalfEdge h) { + ref = h; + } + public boolean equals(float a, float b) { return ((a == x) && (b == y)); } + + + // NEED METHOD GETTING ALL EDGES LEAVING POINT } \ No newline at end of file diff --git a/main/PointList.pde b/main/PointList.pde new file mode 100644 index 0000000..b9518c4 --- /dev/null +++ b/main/PointList.pde @@ -0,0 +1,20 @@ +public class PointList { + + private ArrayList points; + + public PointList() { + points = new ArrayList(); + } + + public boolean contains(Point p) { + return points.contains(p); + } + + public void addPoint(Point p) { + points.add(p); + } + + public boolean removePoint(Point p) { + return points.remove(p); + } +} \ No newline at end of file diff --git a/main/Vertex.pde b/main/Vertex.pde deleted file mode 100644 index 4be053c..0000000 --- a/main/Vertex.pde +++ /dev/null @@ -1,155 +0,0 @@ -public class Vertex { - private float x,y; - private HalfEdge halfedge; - - public Vertex(float a, float b) { - x = a; - y = b; - halfedge = null; - } - public boolean equals(Vertex v) { - return (v.x == x && v.y == y); - } - - public void setX(float i) { - x = i; - } - public void setY(float i) { - y = i; - } - public float getX() { - return x; - } - public float getY(){ - return y; - } - - public HalfEdge getIncidentEdge() { - return halfedge; - } - public ArrayList getAllLeavingEdges() { - if(halfedge == null) { - return null; - } - return halfedge.getHalfEdgesAlsoLeaving(); - } - public void setIncidentEdge(HalfEdge e) { - halfedge = e; - } - - public HalfEdge[] getEdgesToUpdate(Vertex v) { - if (halfedge == null) { return null; } - ArrayList leaving = getAllLeavingEdges(); - HalfEdge[] prevNext = new HalfEdge[2]; - System.out.println("TEST\n"); - if (leaving.size() == 1) { - prevNext[1] = leaving.get(0); - prevNext[0] = prevNext[1].gettwin(); - return prevNext; - } - System.out.println("TEST2\n"); - Vertex v1 = this; - Vertex v4 = v; - Vertex v2; - Vertex v3; - int[] temp = new int[leaving.size()]; - for (int i = 0; i < leaving.size(); i++) { - temp[i] = 0; - } - System.out.println("TEST3\n"); - for (int i = 0; i < leaving.size(); i++) { - v2 = leaving.get(i).gettwin().getOrigin(); - v3 = leaving.get((i+1)%leaving.size()).gettwin().getOrigin(); - if (is2closerCCWof4(v1, v2, v3, v4)) { - System.out.println(i); - temp[i]++; - } else { - System.out.println((i+1)%leaving.size()); - temp[(i+1)%leaving.size()]++; - } - } - System.out.println("TEST4\n"); - for (int i = 0; i < leaving.size(); i++) { - System.out.println("Temp[" + i + "] = " + temp[i]); - if (temp[i] == 2) { - System.out.println(leaving.get(i).gettwin()); - System.out.println(leaving.get(i).gettwin().getnext()); - //prevNext[1] = leaving.get(i); - //prevNext[0] = prevNext[1].getprevious(); - } - } - System.out.println("Test5\n"); - - System.out.println(prevNext[0]); - System.out.println(prevNext[1]); - - return prevNext; - } - - private float[] safeSlope(float dy, float dx) { - float[] ret = new float[2]; - if (dx == 0) { - ret[0] = Float.POSITIVE_INFINITY; - if (dy > 0) { - ret[1] = 1; - } else { - ret[1] = -1; - } - } else { - ret[0] = dy/dx; - } - if (dx < 0) { - ret[1] = 1; - } else { - ret[1] = -1; - } - return ret; - } - - public boolean is2closerCCWof4(Vertex v1, Vertex v2, Vertex v3, Vertex v4) { - float tolerance = 0; - float[] ss12 = safeSlope(v2.getY()-v1.getY(), v2.getX()-v1.getX()); - float[] ss13 = safeSlope(v3.getY()-v1.getY(), v3.getX()-v1.getX()); - float[] ss14 = safeSlope(v4.getY()-v1.getY(), v4.getX()-v1.getX()); - System.out.println(v1); - System.out.println(v2); - System.out.println(v3); - System.out.println(v4); - System.out.println(ss12[0] + " " + ss12[1] + " " + ss13[0] + " " + ss13[1] + " " + ss14[0] + " " + ss14[1]); - if (ss14[0] == Float.POSITIVE_INFINITY) { - if (ss14[1] == 1) { - if (ss12[1] > ss13[1]) { return true; } - if (ss13[1] > ss12[1]) { return false; } - if (ss12[0] - tolerance < ss13[0]) { return true; } - else { return false; } - } else { - if (ss12[1] < ss13[1]) { return true; } - if (ss13[1] < ss12[1]) { return false; } - if (ss12[0] - tolerance < ss13[0]) { return true; } - else { return false; } - } - } - if (ss12[1] == ss13[1]) { - if (ss12[0] + tolerance > ss14[0]) { - if ((ss13[0] > ss12[0]) || (ss13[0] - tolerance < ss14[0])) { return true; } - else { return false; } - } else { - if ((ss13[0] > ss12[0]) && (ss13[0] - tolerance < ss14[0])) { return true; } - else { return false; } - } - } - if (ss12[1] == ss14[1]) { - if (ss12[0] + tolerance > ss14[0]) { return true; } - else { return false; } - } else { - if (ss13[0] - tolerance < ss14[0]) { return true; } - else { return false; } - } - - } - - public String toString() { - return "x: " + x + "\n" + "y: " + y; - } - -} \ No newline at end of file diff --git a/main/VertexList.pde b/main/VertexList.pde deleted file mode 100644 index 2786cc1..0000000 --- a/main/VertexList.pde +++ /dev/null @@ -1,45 +0,0 @@ -public class VertexList { - // stores a list of all the connected graphs currently in memory - private ArrayList vertices; - - public VertexList() { - vertices = new ArrayList(); - } - - public ArrayList getVertexList() { - return vertices; - } - - public boolean contains(Vertex v) { - return vertices.contains(v); - } - - public void addVertex(Vertex v) { - if (alreadyContains(v)) { return; } - vertices.add(v); - } - - public boolean alreadyContains(Vertex v) { - for(Vertex w: vertices) { - if (w.equals(v)) { - return true; - } - } - return false; - } - - public boolean removeVertex(Vertex v) { - return vertices.remove(v); - } - - // given a vertex, find the half edge datastructure that contains that vertex - /*public Vertex findHalfEdge(Vertex v) { - for(Vertex v: graphs) { - HalfEdge result = h.findHalfEdge(v); - if(result != null) { - return result; - } - } - return null; - }*/ -} \ No newline at end of file diff --git a/main/main.pde b/main/main.pde index 8f275fa..e6b2dc5 100644 --- a/main/main.pde +++ b/main/main.pde @@ -6,17 +6,17 @@ public void setup() { fill(0,0); translate(width/2, height/2); VertexList list = new VertexList(); - Vertex v = new Vertex(0,0); - Vertex v1 = new Vertex(0,200); - Vertex v2 = new Vertex(80,100); - Vertex v3 = new Vertex(200,0); - Vertex v4 = new Vertex(-100,-100); - list.addVertex(v); - list.addVertex(v1); - list.addVertex(v2); - list.addVertex(v3); - list.addVertex(v4); - DrawHalfEdge draw = new DrawHalfEdge(); + //Vertex v = new Vertex(0,0); + //Vertex v1 = new Vertex(0,200); + //Vertex v2 = new Vertex(80,100); + //Vertex v3 = new Vertex(200,0); + //Vertex v4 = new Vertex(-100,-100); + //list.addVertex(v); + //list.addVertex(v1); + //list.addVertex(v2); + //list.addVertex(v3); + //list.addVertex(v4); + //DrawHalfEdge draw = new DrawHalfEdge(); //HalfEdge h1 = new HalfEdge(v, v1); //h1.facePrint(); //HalfEdge h2 = new HalfEdge(v, v3); @@ -27,7 +27,7 @@ public void setup() { //h1.facePrint(); //HalfEdge h5 = new HalfEdge(v1,v2); //h1.facePrint(); - draw.drawGraph(list.getVertexList()); + //draw.drawGraph(list.getVertexList()); } /*public void draw() { fill(0,0,255,40);