Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
magic maybe?
  • Loading branch information
JimmyBoivie authored and JimmyBoivie committed Dec 6, 2015
1 parent 98ddaee commit 53f2abb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 37 deletions.
71 changes: 71 additions & 0 deletions main/CompGeo.pde
Expand Up @@ -68,6 +68,77 @@ public static class CompGeo {
return sum;
}

public static boolean isContained(HalfEdge inner, HalfEdge outer, Point far) {
Point inHandle = inner.getOrigin();
return inside(outer, inHandle, far);
}




public static ArrayList findFriends(HalfEdge inner, 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; }
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 ((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; }
}
}
}
return friends;
}


public static HalfEdge findTightOuterBoundary(HalfEdge inner, PointList points) {
Point far = points.getFar();
ArrayList<HalfEdge> handles = points.getAllStructures();
int num = handles.size();
HalfEdge temp;
HalfEdge tightest = null;
for (int i = 0; i < num; i++) {
temp = handles.get(i);
if (inner.canReach(temp)) { continue; } // MAKE SURE DONT CHECK AGAINST ITSELF
if (isContained(inner, temp, far)) {
if (tightest == null) {
tightest = temp;
} else {
if (isContained(temp, tightest, far)) {
tightest = temp;
}
}
}
}
tightest = findSuperTightBoundary(inner, tightest, far);
tightest.reset();
return tightest;
}

public static HalfEdge findSuperTightBoundary(HalfEdge inner, HalfEdge outer, Point far) {
if (outer == null) { return null; }
if ((isContained(inner, outer, far)) && (signedArea(outer) < 0)) { return outer; }
if (outer.getCounted() == false) {
outer.setCounted(true);
HalfEdge temp = findSuperTightBoundary(inner, outer.getnext(), far);
if (temp != null) { return temp; }
temp = findSuperTightBoundary(inner, outer.getprevious(), far);
if (temp != null) { return temp; }
temp = findSuperTightBoundary(inner, outer.gettwin(), far);
if (temp != null) { return temp; }
}
return null;
}




}
29 changes: 0 additions & 29 deletions main/FaceList.pde

This file was deleted.

1 change: 1 addition & 0 deletions main/HalfEdge.pde
Expand Up @@ -293,6 +293,7 @@ public class HalfEdge {
return "Origin: " + origin.toString() + "\nDestination: " + twin.getOrigin().toString();
}


public ArrayList<Point> getPointsNext() {
ArrayList<Point> points = new ArrayList<Point>();
points.add(this.getOrigin());
Expand Down
6 changes: 6 additions & 0 deletions main/Point.pde
Expand Up @@ -11,10 +11,16 @@ public class Point {
public float getX() {
return x;
}
public void setX(float f) {
x = f;
}

public float getY() {
return y;
}
public void setY(float f) {
y = f;
}

public HalfEdge getRef() {
return ref;
Expand Down
13 changes: 11 additions & 2 deletions main/PointList.pde
@@ -1,9 +1,15 @@
public class PointList {

private ArrayList<Point> points;
private Point far;

public PointList() {
points = new ArrayList<Point>();
points = new ArrayList<Point>();
far = new Point(0, 10000);
}

public Point getFar() {
return far;
}

public ArrayList<Point> getPoints() {
Expand All @@ -17,7 +23,10 @@ public class PointList {


public void addPoint(Point p) {
points.add(p);
points.add(p);
if (p.getY() > far.getY()) {
far.setY(p.getY() + 1);
}
}

public boolean removePoint(Point p) {
Expand Down
13 changes: 7 additions & 6 deletions main/main.pde
Expand Up @@ -8,9 +8,9 @@ public void setup() {
PointList list = new PointList();
Point p1 = new Point(0, 0);
list.addPoint(p1);
Point p2 = new Point(100, 200);
Point p2 = new Point(100, 50);
list.addPoint(p2);
Point p3 = new Point(-100, -100);
Point p3 = new Point(-200, -50);
list.addPoint(p3);
Point p4 = new Point(0, 150);
list.addPoint(p4);
Expand All @@ -24,13 +24,14 @@ public void setup() {
HalfEdge h2 = new HalfEdge(p1, p4);
HalfEdge h3 = new HalfEdge(p3, p1);
HalfEdge h4 = new HalfEdge(p1, p5);
//HalfEdge h5 = new HalfEdge(p3, p4);
float f = CompGeo.signedArea(h2.gettwin());
float f2 = CompGeo.signedArea(h2);
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();
h2.printFace();
h1.printFace();
if (CompGeo.inside(h1.gettwin(), p6, p7)) {
System.out.println("INSIDE");
} else { System.out.println("OUTSIDE"); }
Expand Down

0 comments on commit 53f2abb

Please sign in to comment.