Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 3, 2015
2 parents 3b71cdb + 670ac6f commit 2503a49
Showing 1 changed file with 57 additions and 22 deletions.
79 changes: 57 additions & 22 deletions main/DrawHalfEdge.pde
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,69 @@ public class DrawHalfEdge {
point(v.getX(), v.getY());
}

public void drawGraph(ArrayList<HalfEdge> hlist) {
for(HalfEdge halfedge: hlist) {
drawConnectedGraph(halfedge);
halfedge.reset();
public void drawGraph(ArrayList<Vertex> vlist) {
for(Vertex vertex: vlist) {
drawConnectedGraph(vertex);
}
zoom(vlist);
}

public void drawConnectedGraph(HalfEdge halfedge) {
if(halfedge.getdrawn() != true) {
drawHalfEdge(halfedge);
halfedge.setdrawn();
drawConnectedGraph(halfedge.getnext());
drawConnectedGraph(halfedge.gettwin());
drawConnectedGraph(halfedge.getprevious());
}
public void drawConnectedGraph(Vertex vertex) {
ArrayList<HalfEdge> edges = vertex.getAllLeavingEdges();
drawpoint(vertex);
for(HalfEdge edge: edges) {
drawConnection(edge, vertex);
}
}

public void drawHalfEdge(HalfEdge halfedge) {
if(halfedge != null) {
Vertex v1 = halfedge.getVertex();
drawpoint(v1);
if(halfedge.gettwin() != null && halfedge.gettwin().getdrawn() != true) {
HalfEdge twin = halfedge.gettwin();
Vertex v2 = twin.getVertex();
drawpoint(v2);
drawline(v1,v2);

public void drawConnection(HalfEdge edge, Vertex v1) {
Vertex v2 = edge.getOrigin();
drawpoint(v2);
drawline(v1, v2);
}
public void zoom(ArrayList<Vertex> vlist) {
float[] bounds = getbounds(vlist);
float[] range = getRange(bounds); //{maxx,minx,maxy,miny};
float scalefactor = scalingfactor(range);
translate(range[0]/2, range[1]/2); // center the figure
scale(scalefactor);
}
public float scalingfactor(float[] range) {
float rangex = range[0];
float rangey = range[1];
float diffx = width/rangex;
float diffy = height/rangey;
return Math.min(diffx,diffy);
}
public float[] getRange(float[] bounds) {
float rangex = bounds[0] - bounds[1];
float rangey = bounds[2] - bounds[3];
float[] range = {rangex, rangey};
return range;
}
public float[] getbounds(ArrayList<Vertex> 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) {
float x = v.getX();
float y = v.getY();
if(x < minx) {
minx = x;
}
if(x > maxx) {
maxx= x;
}
if(y < miny) {
miny = y;
}
if(y > maxy) {
maxy = y;
}
}
float[] result = {maxx,minx,maxy,miny};
return result;
}
}

Expand Down

0 comments on commit 2503a49

Please sign in to comment.