Skip to content

Commit a40dec3

Browse files
committed
Making the polygon loading more robust by detectiing invalid normals and
rejecting those points
1 parent a10a30b commit a40dec3

File tree

11 files changed

+603
-253
lines changed

11 files changed

+603
-253
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ html
2626
/handmade.step
2727
/test-export-2.step
2828
/test-export.step
29+
/Part-Num-0.svg.png

src/main/java/eu/mihosoft/vrl/v3d/Edge.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static Polygon toPolygon(List<Vector3d> points, Plane plane) {
125125
Polygon p = Polygon.fromPoints(points);
126126

127127
p.vertices.stream().forEachOrdered((vertex) -> {
128-
vertex.normal = plane.normal.clone();
128+
vertex.normal = plane.getNormal().clone();
129129
});
130130

131131
// // we try to detect wrong orientation by comparing normals
@@ -897,8 +897,8 @@ private static List<List<Polygon>> searchPlaneGroups(List<Polygon> polygons) {
897897
continue;
898898
}
899899

900-
Vector3d nOuter = pOuter.plane.normal;
901-
Vector3d nInner = pInner.plane.normal;
900+
Vector3d nOuter = pOuter.plane.getNormal();
901+
Vector3d nInner = pInner.plane.getNormal();
902902

903903
double angle = nOuter.angle(nInner);
904904

src/main/java/eu/mihosoft/vrl/v3d/Extrude.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,18 @@ private CSG monotoneExtrude(Vector3d dir, Polygon polygon1) {
9898
Vector3d topV1 = polygon2.vertices.get(i).pos;
9999
Vector3d bottomV2 = polygon1.vertices.get(nexti).pos;
100100
Vector3d topV2 = polygon2.vertices.get(nexti).pos;
101-
101+
double distance = bottomV1.minus(bottomV2).magnitude();
102+
if(Math.abs(distance)<Plane.EPSILON*10) {
103+
//System.out.println("Skipping invalid polygon");
104+
continue;
105+
}
102106
List<Vector3d> pPoints = Arrays.asList(bottomV2, topV2, topV1, bottomV1);
103-
104-
newPolygons.add(Polygon.fromPoints(pPoints, polygon1.getStorage()));
105-
107+
try {
108+
newPolygons.add(Polygon.fromPoints(pPoints, polygon1.getStorage()));
109+
}catch(Exception ex) {
110+
System.out.println("Polygon has problems: ");
111+
ex.printStackTrace();
112+
}
106113
}
107114

108115
polygon2 = polygon2.flipped();

0 commit comments

Comments
 (0)