From 3c27bb0de23b986070d041b72fc77430964204b9 Mon Sep 17 00:00:00 2001 From: Kevin Harrington Date: Thu, 25 Mar 2021 17:26:18 -0400 Subject: [PATCH] Update Plane.java --- src/main/java/eu/mihosoft/jcsg/Plane.java | 35 +++++++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/eu/mihosoft/jcsg/Plane.java b/src/main/java/eu/mihosoft/jcsg/Plane.java index 37f1407c..364e8a73 100644 --- a/src/main/java/eu/mihosoft/jcsg/Plane.java +++ b/src/main/java/eu/mihosoft/jcsg/Plane.java @@ -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 types = new ArrayList<>(polygon.vertices.size()); + List 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) {