Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (77 sloc) 2.15 KB
public class DrawHalfEdge {
public void drawline(Point v1, Point v2) {
//////System.out.println(v1 + " " + v2);
line(v1.getX(), v1.getY(), v2.getX(), v2.getY());
}
public void drawpoint(Point v) {
ellipse(v.getX(), v.getY(),10,10);
}
public void drawGraph(ArrayList<Point> vlist) {
for(Point p: vlist) {
drawConnectedGraph(p);
}
//zoom(vlist);
}
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);
}
}
}
public void drawConnection(HalfEdge edge) {
//////System.out.println("drawing connection");
Point v2 = edge.getOrigin();
Point v1 = edge.gettwin().getOrigin();
drawline(v1, v2);
}
public void zoom(ArrayList<Point> 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<Point> vlist) {
float maxx = Float.NEGATIVE_INFINITY;
float maxy = Float.NEGATIVE_INFINITY;
float minx = Float.POSITIVE_INFINITY;
float miny = Float.POSITIVE_INFINITY;
for(Point 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;
}
}
//find lowest and highest x and y, divide by difference.
You can’t perform that action at this time.