diff --git a/main/HalfEdge.pde b/main/HalfEdge.pde index 6278e9b..d2be093 100644 --- a/main/HalfEdge.pde +++ b/main/HalfEdge.pde @@ -245,6 +245,48 @@ public class HalfEdge { } } + public HalfEdge findStart(float x, float y, float distance, Point farAway) { + HalfEdge temp = findHalfEdgeSelected(x,y,distance, farAway); + reset(); + return temp; + } + + public HalfEdge findHalfEdgeSelected(float x, float y, float distance, Point farAway) { + if (this.isSelected(x,y,distance, farAway)) { return this; } + if (counted != false) { + counted = true; + HalfEdge temp = twin.findHalfEdgeSelected(x,y,distance,farAway); + if (temp != null) { return temp; } + temp = next.findHalfEdgeSelected(x,y,distance,farAway); + if (temp != null) { return temp; } + temp = previous.findHalfEdgeSelected(x,y,distance,farAway); + if (temp != null) { return temp; } + } + return null; + } + + public boolean isSelected(float x, float y, float distance, Point farAway) { + Point p1 = new Point(origin.getX(), origin.getY()); + Point p3 = new Point(twin.getOrigin().getX(), twin.getOrigin().getY()); + float midx = (p1.getX() + p3.getX())/2; + float midy = (p1.getY() + p3.getY())/2; + float dx = p1.getX() - p3.getX(); + float dy = p1.getY() - p3.getY(); + float ndx = -dy; + float ndy = dx; + float notScaled = sqrt(ndx*ndx + ndy*ndy); + float scale = notScaled/distance; + ndx = ndx/scale; + ndy = ndy/scale; + Point p2 = new Point(midx + ndx, midy + ndy); + Point p4 = new Point(midx - ndx, midy - ndy); + HalfEdge h1 = new HalfEdge(p1, p2); + HalfEdge h2 = new HalfEdge(p2, p3); + HalfEdge h3 = new HalfEdge(p3, p4); + HalfEdge h4 = new HalfEdge(p4, p1); + return CompGeo.inside(h, new Point(x, y), farAway); + } + public ArrayList getAllLeaving() { ArrayList others = getOtherLeaving(); others.add(this); @@ -370,6 +412,8 @@ public class HalfEdge { incidentFace = f; } + + public void printRNext() { //System.out.println(" " + origin); HalfEdge temp = next; diff --git a/main/PointList.pde b/main/PointList.pde index 1f19a6c..615b367 100644 --- a/main/PointList.pde +++ b/main/PointList.pde @@ -51,6 +51,17 @@ public class PointList { return struct; } + public HalfEdge getHalfEdgeBySinglePoint(float x, float y, float distance) { + ArrayList pieces = getAllStructures(); + int num = pieces.size(); + HalfEdge temp = null; + for (int i = 0; i < num; i++) { + temp = pieces.get(i).findStart(x,y,distance, far); + if (temp != null) { return temp; } + } + return null; + } + public HalfEdge getHalfEdge(Point p, Point q) { //System.out.println(p); //System.out.println(q);