Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the stackOverflow issue in #54 #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/main/java/eu/mihosoft/jcsg/Plane.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,40 @@ public void splitPolygon(
final int BACK = 2;
final int SPANNING = 3; // == some in the FRONT + some in the BACK

// Classify each point as well as the entire polygon into one of the
// above four classes.
// search for the epsilon values of the incoming plane
double negEpsilon = -Plane.EPSILON;
double posEpsilon = Plane.EPSILON;
for (int i = 0; i < polygon.vertices.size(); i++) {
double t = polygon.plane.normal.dot(polygon.vertices.get(i).pos) - polygon.plane.dist;
if(t>posEpsilon) {
//System.err.println("Non flat polygon, increasing positive epsilon "+t);
posEpsilon=t+Plane.EPSILON;
}
if(t<negEpsilon) {
//System.err.println("Non flat polygon, decreasing negative epsilon "+t);
negEpsilon=t-Plane.EPSILON;
}
}
int polygonType = 0;
List<Integer> types = new ArrayList<>(polygon.vertices.size());
List<Integer> types = new ArrayList<>();
boolean somePointsInfront = false;
boolean somePointsInBack = false;
for (int i = 0; i < polygon.vertices.size(); i++) {
double t = this.normal.dot(polygon.vertices.get(i).pos) - this.dist;
int type = (t < -Plane.EPSILON) ? BACK : (t > Plane.EPSILON) ? FRONT : COPLANAR;
polygonType |= type;
int type = (t < negEpsilon) ? BACK : (t > posEpsilon) ? FRONT : COPLANAR;
//polygonType |= type;
if(type==BACK)
somePointsInBack=true;
if(type==FRONT)
somePointsInfront = true;
types.add(type);
}

if(somePointsInBack && somePointsInfront)
polygonType=SPANNING;
else if(somePointsInBack) {
polygonType=BACK;
}else if(somePointsInfront)
polygonType=FRONT;
//System.out.println("> switching");
// Put the polygon in the correct list, splitting it when necessary.
switch (polygonType) {
Expand Down