Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed bugs - I think it is good
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 6, 2015
1 parent 53f2abb commit 74cd347
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 62 deletions.
41 changes: 29 additions & 12 deletions main/CompGeo.pde
Expand Up @@ -75,23 +75,24 @@ public static class CompGeo {




public static ArrayList findFriends(HalfEdge inner, HalfEdge outer, PointList points) {
public static ArrayList<HalfEdge> findFriends(HalfEdge outer, PointList points) {
ArrayList<HalfEdge> handles = points.getAllStructures();
ArrayList<HalfEdge> friends = new ArrayList<HalfEdge>();
int num = handles.size();
HalfEdge out = null;
for (int i = 0; i < num; i++) {
if (inner.canReach(handles.get(i))) { continue; }
//if (inner.canReach(handles.get(i))) { friends.add(inner); continue; }
out = findTightOuterBoundary(handles.get(i), points);
if (out == outer) {
if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; }
else { friends.add(handles.get(i)); continue; }
//if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; }
//else { friends.add(handles.get(i)); continue; }
friends.add(findCWR(handles.get(i))); continue;
}
if ((out != null) && (outer != null)) {
if (out.canReach(outer)) {
if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; }
else { friends.add(handles.get(i)); continue; }
if (out.canReachNext(outer)) {
//if (signedArea(handles.get(i)) <= 0) { friends.add(handles.get(i).gettwin()); continue; }
//else { friends.add(handles.get(i)); continue; }
friends.add(findCWR(handles.get(i))); continue;
}
}
}
Expand All @@ -118,8 +119,8 @@ public static class CompGeo {
}
}
}
tightest = findSuperTightBoundary(inner, tightest, far);
tightest.reset();
tightest = findSuperTightBoundary(inner, tightest, far);
if (tightest != null) { tightest.reset(); }
return tightest;
}

Expand All @@ -138,7 +139,23 @@ public static class CompGeo {
return null;
}

public static HalfEdge findCWR(HalfEdge ref) {
HalfEdge out = findClockWiseRepresentation(ref);
ref.reset();
return out;
}



private static HalfEdge findClockWiseRepresentation(HalfEdge ref) {
if (signedArea(ref) >= 0) { return ref; }
if (ref.getCounted() == false) {
ref.setCounted(true);
HalfEdge temp = findClockWiseRepresentation(ref.getnext());
if (temp != null) { return temp; }
temp = findClockWiseRepresentation(ref.getprevious());
if (temp != null) { return temp; }
temp = findClockWiseRepresentation(ref.gettwin());
if (temp != null) { return temp; }
}
return null;
}
}
4 changes: 2 additions & 2 deletions main/DrawHalfEdge.pde
@@ -1,7 +1,7 @@
public class DrawHalfEdge {

public void drawline(Point v1, Point v2) {
System.out.println(v1 + " " + v2);
//System.out.println(v1 + " " + v2);
line(v1.getX(), v1.getY(), v2.getX(), v2.getY());
}
public void drawpoint(Point v) {
Expand All @@ -18,7 +18,7 @@ public class DrawHalfEdge {
public void drawConnectedGraph(Point p) {
ArrayList<HalfEdge> edges = p.getLeaving();
drawpoint(p);
System.out.println(p);
//System.out.println(p);
if(edges != null) {
for(HalfEdge edge: edges) {
//System.out.println(edge);
Expand Down
52 changes: 14 additions & 38 deletions main/Face.pde
Expand Up @@ -3,47 +3,23 @@ public class Face {
HalfEdge outerComponent;
ArrayList<HalfEdge> innerComponents;

public Face(HalfEdge outer) {
outerComponent = outer;
innerComponents = new ArrayList<HalfEdge>();
public Face(HalfEdge ref, PointList points) {
if (CompGeo.signedArea(ref) < 0) { outerComponent = ref; }
else { outerComponent = CompGeo.findTightOuterBoundary(ref, points); }
innerComponents = CompGeo.findFriends(outerComponent, points);
}

public void setOuterComponent(HalfEdge he) {
outerComponent = he;
}

public HalfEdge getOuterComponent() {
return outerComponent;
}

public void addInnerComponent(HalfEdge he) {
innerComponents.add(he);
}

public void removeInnerComponent(HalfEdge he) {
innerComponents.remove(he);
}

public void updateReference(HalfEdge he) {
for (HalfEdge h: innerComponents) {
if (he.isEventuallyNext(h)) {
removeInnerComponent(h);
}
public void printFace() {
System.out.println("Outer Face:");
if (outerComponent != null) { outerComponent.printRNext(); }
System.out.println();
System.out.println("Inner Components:");
int num = innerComponents.size();
for (int i = 0; i < num; i++) {
System.out.println("COMPONENT[" + i + "]");
innerComponents.get(i).printRNext();
}
addInnerComponent(he);
}


public ArrayList<HalfEdge> getInnerComponents() {
return innerComponents;
System.out.println();
}

// NEED METHODS
// MERGE: MERGE TWO FACES
// BREAK: BREAKS FACE INTO TWO
// INSIDE: CHECK IF POINT IS INSIDE A FACE????


// MAYBE ASSUME OUTTER FACE IS IMPLICIT???

}
22 changes: 22 additions & 0 deletions main/HalfEdge.pde
Expand Up @@ -261,12 +261,25 @@ public class HalfEdge {
}
return false;
}
private boolean isReachableNext(HalfEdge h) {
if (this == h) { return true; }
if (counted == false) {
counted = true;
return next.isReachableNext(h);
}
return false;
}

public boolean canReach(HalfEdge h) {
boolean out = isReachable(h);
reset();
return out;
}
public boolean canReachNext(HalfEdge h) {
boolean out = isReachableNext(h);
reset();
return out;
}


// may not want getters, but for now they are here.
Expand Down Expand Up @@ -324,4 +337,13 @@ public class HalfEdge {
incidentFace = f;
}

public void printRNext() {
System.out.println(" " + origin);
HalfEdge temp = next;
while (temp != this) {
System.out.println(" " + temp.getOrigin());
temp = temp.getnext();
}
}

}
1 change: 1 addition & 0 deletions main/PointList.pde
Expand Up @@ -37,6 +37,7 @@ public class PointList {
int num = points.size();
ArrayList<HalfEdge> struct = new ArrayList<HalfEdge>();
for (int i = 0; i < num; i++) {
if (points.get(i).getRef() == null) { continue; }
if (points.get(i).getRef().getCounted() == false) {
points.get(i).getRef().count();
struct.add(points.get(i).getRef());
Expand Down
56 changes: 46 additions & 10 deletions main/main.pde
Expand Up @@ -18,23 +18,56 @@ public void setup() {
list.addPoint(p5);
Point p6 = new Point (-20, -40);
list.addPoint(p6);
Point p7 = new Point (10000,10000);
Point p7 = new Point(-50, 0);
list.addPoint(p7);
Point p8 = new Point(-100, 0);
list.addPoint(p8);
Point p9 = new Point(-100, 35);
list.addPoint(p9);
Point p10 = new Point(-50, 35);
list.addPoint(p10);
Point p11 = new Point(-80, 15);
list.addPoint(p11);
Point p12 = new Point(-60, 25);
list.addPoint(p12);
Point p13 = new Point (-25, 25);
list.addPoint(p13);
Point p14 = new Point (-25, 100);
list.addPoint(p14);
Point p15 = new Point(-150, -20);
list.addPoint(p15);
Point p16 = new Point (20, 50);
list.addPoint(p16);
Point p17 = new Point (20, 100);
list.addPoint(p17);
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);
HalfEdge h5 = new HalfEdge(p3, p4);
HalfEdge h6 = new HalfEdge(p2, p4);
float f = CompGeo.signedArea(h1.gettwin());
float f2 = CompGeo.signedArea(h1);
System.out.println("Signed Area: " + f);
System.out.println("Signed Area: " + f2);
h1.gettwin().printFace();
h1.printFace();
if (CompGeo.inside(h1.gettwin(), p6, p7)) {
System.out.println("INSIDE");
} else { System.out.println("OUTSIDE"); }
HalfEdge h7 = new HalfEdge(p7, p8);
HalfEdge h8 = new HalfEdge(p8, p9);
HalfEdge h9 = new HalfEdge(p9, p10);
HalfEdge h10 = new HalfEdge(p10, p7);
HalfEdge h11 = new HalfEdge(p11,p12);
HalfEdge h12 = new HalfEdge(p13,p14);
HalfEdge h13 = new HalfEdge(p7, p15);
HalfEdge h14 = new HalfEdge(p8, p15);
HalfEdge h15 = new HalfEdge(p9, p15);
HalfEdge h16 = new HalfEdge(p16, p17);

//h1.printFace();
//float f = CompGeo.signedArea(h1.gettwin());
//float f2 = CompGeo.signedArea(h1);
//System.out.println("Signed Area: " + f);
//System.out.println("Signed Area: " + f2);
//h1.gettwin().printFace();
//h1.printFace();
//if (CompGeo.inside(h1.gettwin(), p6, p7)) {
// System.out.println("INSIDE");
//} else { System.out.println("OUTSIDE"); }
//HalfEdge h5 = new HalfEdge(p5, p2);
//h5.gettwin().printFace();
//h5.printFace();
Expand All @@ -49,6 +82,9 @@ public void setup() {
//HalfEdge h5 = new HalfEdge(v1,v2);
//h1.facePrint();
draw.drawGraph(list.getPoints());
//(new Face(h4, list)).printFace();
(new Face(h12, list)).printFace();

}
/*public void draw() {
fill(0,0,255,40);
Expand Down

0 comments on commit 74cd347

Please sign in to comment.