diff --git a/main/DrawHalfEdge.pde b/main/DrawHalfEdge.pde index aafe6d9..7bc0a88 100644 --- a/main/DrawHalfEdge.pde +++ b/main/DrawHalfEdge.pde @@ -1,38 +1,39 @@ public class DrawHalfEdge { - public void drawline(Vertex v1, Vertex v2) { + public void drawline(Point v1, Point v2) { + System.out.println(v1 + " " + v2); line(v1.getX(), v1.getY(), v2.getX(), v2.getY()); } - public void drawpoint(Vertex v) { - ellipse(v.getX(), v.getY(),25,25); + public void drawpoint(Point v) { + ellipse(v.getX(), v.getY(),10,10); } - public void drawGraph(ArrayList vlist) { - for(Vertex vertex: vlist) { - drawConnectedGraph(vertex); + public void drawGraph(ArrayList vlist) { + for(Point p: vlist) { + drawConnectedGraph(p); } zoom(vlist); } - public void drawConnectedGraph(Vertex vertex) { - ArrayList edges = vertex.getAllLeavingEdges(); - drawpoint(vertex); - System.out.println(vertex); + public void drawConnectedGraph(Point p) { + ArrayList edges = p.getLeaving(); + drawpoint(p); + System.out.println(p); if(edges != null) { for(HalfEdge edge: edges) { //System.out.println(edge); - drawConnection(edge.gettwin(), vertex); + drawConnection(edge); } } } - public void drawConnection(HalfEdge edge, Vertex v1) { + public void drawConnection(HalfEdge edge) { //System.out.println("drawing connection"); - Vertex v2 = edge.getOrigin(); - drawpoint(v2); + Point v2 = edge.getOrigin(); + Point v1 = edge.gettwin().getOrigin(); drawline(v1, v2); } - public void zoom(ArrayList vlist) { + public void zoom(ArrayList vlist) { float[] bounds = getbounds(vlist); float[] range = getRange(bounds); //{maxx,minx,maxy,miny}; float scalefactor = scalingfactor(range); @@ -52,12 +53,12 @@ public class DrawHalfEdge { float[] range = {rangex, rangey}; return range; } - public float[] getbounds(ArrayList vlist) { + public float[] getbounds(ArrayList vlist) { float maxx = Float.NEGATIVE_INFINITY; float maxy = Float.NEGATIVE_INFINITY; float minx = Float.POSITIVE_INFINITY; float miny = Float.POSITIVE_INFINITY; - for(Vertex v: vlist) { + for(Point v: vlist) { float x = v.getX(); float y = v.getY(); if(x < minx) { diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index d8a2062..821c4b4 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -28,20 +28,30 @@ public class HalfEdge { + + } + public void makeVertexReference() { + origin.setRef(this); } + public int connect() { ArrayList others = origin.getEntering(); if (others == null) { this.setprevious(gettwin()); gettwin().setnext(this); // update vertex + makeVertexReference(); return 0; } if (others.size() == 1) { HalfEdge other = others.get(0); - this.setprevious(other.gettwin()); - gettwin().setnext(other); + this.setprevious(other); + other.setnext(this); + gettwin().setnext(other.gettwin()); + other.gettwin().setprevious(gettwin()); + + // no update vertex return 1; } @@ -135,6 +145,17 @@ public class HalfEdge { others.add(this); return others; } + public void printFace() { + HalfEdge temp = next; + System.out.println("PrintFaceBegin"); + System.out.println(origin + " " + twin.getOrigin()); + while (temp != this) { + System.out.println(temp.getOrigin() + " " + temp.gettwin().getOrigin()); + temp = temp.getnext(); + } + System.out.println(); + } + // 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 aa3974e..4f564a2 100644 --- a/main/Point.pde +++ b/main/Point.pde @@ -43,4 +43,8 @@ public class Point { return ref.getEntering(); } + public String toString() { + return "(x,y) = " + x + "," + y; + } + } \ No newline at end of file diff --git a/main/PointList.pde b/main/PointList.pde index b9518c4..588acc4 100644 --- a/main/PointList.pde +++ b/main/PointList.pde @@ -6,10 +6,16 @@ public class PointList { points = new ArrayList(); } + public ArrayList getPoints() { + return points; + } + public boolean contains(Point p) { return points.contains(p); } + + public void addPoint(Point p) { points.add(p); } diff --git a/main/main.pde b/main/main.pde index 0d3c7ce..5c0627e 100644 --- a/main/main.pde +++ b/main/main.pde @@ -5,18 +5,26 @@ public void setup() { background(255); 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(); + PointList list = new PointList(); + Point p1 = new Point(0, 0); + list.addPoint(p1); + Point p2 = new Point(100, 200); + list.addPoint(p2); + Point p3 = new Point(-100, -100); + list.addPoint(p3); + Point p4 = new Point(0, 150); + list.addPoint(p4); + Point p5 = new Point(200, 0); + list.addPoint(p5); + DrawHalfEdge draw = new DrawHalfEdge(); + HalfEdge h1 = new HalfEdge(p1, p2); + HalfEdge h2 = new HalfEdge(p1, p4); + HalfEdge h3 = new HalfEdge(p3, p1); + HalfEdge h4 = new HalfEdge(p1, p5); + h1.printFace(); + //HalfEdge h5 = new HalfEdge(p5, p2); + //h5.gettwin().printFace(); + //h5.printFace(); //HalfEdge h1 = new HalfEdge(v, v1); //h1.facePrint(); //HalfEdge h2 = new HalfEdge(v, v3); @@ -27,7 +35,7 @@ public void setup() { //h1.facePrint(); //HalfEdge h5 = new HalfEdge(v1,v2); //h1.facePrint(); - //draw.drawGraph(list.getVertexList()); + draw.drawGraph(list.getPoints()); } /*public void draw() { fill(0,0,255,40);