Skip to content

Commit

Permalink
FIXED HALF EDGE
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 5, 2015
1 parent 130e197 commit 49c7380
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 32 deletions.
35 changes: 18 additions & 17 deletions main/DrawHalfEdge.pde
Original file line number Diff line number Diff line change
@@ -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<Vertex> vlist) {
for(Vertex vertex: vlist) {
drawConnectedGraph(vertex);
public void drawGraph(ArrayList<Point> vlist) {
for(Point p: vlist) {
drawConnectedGraph(p);
}
zoom(vlist);
}

public void drawConnectedGraph(Vertex vertex) {
ArrayList<HalfEdge> edges = vertex.getAllLeavingEdges();
drawpoint(vertex);
System.out.println(vertex);
public void drawConnectedGraph(Point p) {
ArrayList<HalfEdge> 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<Vertex> vlist) {
public void zoom(ArrayList<Point> vlist) {
float[] bounds = getbounds(vlist);
float[] range = getRange(bounds); //{maxx,minx,maxy,miny};
float scalefactor = scalingfactor(range);
Expand All @@ -52,12 +53,12 @@ public class DrawHalfEdge {
float[] range = {rangex, rangey};
return range;
}
public float[] getbounds(ArrayList<Vertex> vlist) {
public float[] getbounds(ArrayList<Point> 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) {
Expand Down
25 changes: 23 additions & 2 deletions main/HalfEdge.pde
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,30 @@ public class HalfEdge {




}
public void makeVertexReference() {
origin.setRef(this);
}


public int connect() {
ArrayList<HalfEdge> 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;
}
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions main/Point.pde
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ public class Point {
return ref.getEntering();
}

public String toString() {
return "(x,y) = " + x + "," + y;
}

}
6 changes: 6 additions & 0 deletions main/PointList.pde
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ public class PointList {
points = new ArrayList<Point>();
}

public ArrayList<Point> getPoints() {
return points;
}

public boolean contains(Point p) {
return points.contains(p);
}



public void addPoint(Point p) {
points.add(p);
}
Expand Down
34 changes: 21 additions & 13 deletions main/main.pde
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 49c7380

Please sign in to comment.