Created
June 13, 2013 11:31
-
-
Save PatrickLerner/5773023 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void deletePoint(Point p) { | |
HashSet<Triangle> innerTriangles = new HashSet<Triangle>(); | |
HashSet<Edge> outerEdges = new HashSet<Edge>(); | |
// root is any outer point. From this point on we will later build the | |
// new triangles | |
Point root = null; | |
// build the sets noted above | |
try { | |
for (Edge e : this.getAllEdges()) { | |
if (!e.containsPoint(p)) // if e is not an inner edge | |
continue; // skip it | |
// get the triangles of e, both are innerTriangles | |
for (Triangle t : this.getTrianglesOfEdge(e)) { | |
innerTriangles.add(t); // add them | |
for (Edge ie : t.getEdges()) { | |
if (ie.containsPoint(p)) // if the triangle's edge contains | |
// p, it's not an outer edge | |
continue; // skip it | |
outerEdges.add(ie); | |
// set the root (might be overwritten) | |
if (!ie.getP2().equals(p)) | |
root = ie.getP2(); | |
if (!ie.getP1().equals(p)) | |
root = ie.getP1(); | |
} | |
} | |
} | |
} catch (IllegalAccessException e1) { | |
e1.printStackTrace(); | |
} | |
System.out.println(root.toString()); | |
Triangle t = null; | |
for (Edge e : outerEdges) { | |
if (!e.containsPoint(root)) { | |
// construct triangle with edge and point root | |
LinkedList<Edge> edges = this.buildEdgeList( | |
this.getOrCreateEdge(e.getP1(), root), | |
this.getOrCreateEdge(e.getP2(), root), | |
e); | |
t = new Triangle(edges); | |
// set triangle in edges | |
for (Edge ne : edges) { | |
if (ne.getT1() == null || innerTriangles.contains(ne.getT1())) | |
ne.setT1(t); | |
else if (ne.getT2() == null || innerTriangles.contains(ne.getT2())) | |
ne.setT2(t); | |
} | |
} | |
} | |
// since our start triangle might be invalid, lets replace it | |
// with a triangle | |
// that is definitely not invalid (the one we just created) just | |
// in case | |
this.root = t; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment