diff --git a/testdata/scad/bugs/issue1225.scad b/testdata/scad/bugs/issue1225.scad new file mode 100644 index 00000000..4792cbc8 --- /dev/null +++ b/testdata/scad/bugs/issue1225.scad @@ -0,0 +1,5 @@ +cylinder(h = 19.05, r = 25.4); +translate([-20, -2.26, 19.05]) { + translate([0, 4.375, 0]) sphere(1); + translate([7.5, 1.875, 0]) sphere(1); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 93658a0f..2804c9c8 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1274,7 +1274,8 @@ list(APPEND BUGS_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue13.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue945d.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue945e.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue1223.scad - ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue1223b.scad) + ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue1223b.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/issue1225.scad) # We know that we cannot import weakly manifold files into CGAL, so to make tests easier # to manage, don't try. Once we improve import, we can reenable this diff --git a/tests/regression/cgalpngtest/issue1225-expected.png b/tests/regression/cgalpngtest/issue1225-expected.png new file mode 100644 index 00000000..e72475a7 Binary files /dev/null and b/tests/regression/cgalpngtest/issue1225-expected.png differ diff --git a/tests/regression/monotonepngtest/issue1225-expected.png b/tests/regression/monotonepngtest/issue1225-expected.png new file mode 100644 index 00000000..e72475a7 Binary files /dev/null and b/tests/regression/monotonepngtest/issue1225-expected.png differ diff --git a/tests/regression/opencsgtest/issue1225-expected.png b/tests/regression/opencsgtest/issue1225-expected.png new file mode 100644 index 00000000..997ced68 Binary files /dev/null and b/tests/regression/opencsgtest/issue1225-expected.png differ diff --git a/tests/validatestl.py b/tests/validatestl.py index f9960e24..043549fc 100755 --- a/tests/validatestl.py +++ b/tests/validatestl.py @@ -1,7 +1,10 @@ #!/usr/bin/env python # -# Simple tool to validate if an STL has non-manifold (dangling) edges. +# Simple tool to validate an STL. +# It checks for: +# o Any occurrence of "nan" or "inf" vertices or normals +# o Any non-manifold (dangling) edges. # # Usage: validatestl.py # @@ -17,14 +20,15 @@ import io import hashlib import os import subprocess +import math from collections import Counter def read_stl(filename): triangles = list() with open(filename, "r") as fd: triangle = { - "facet": [0, 0, 0], - "points": list() + 'normal': [0, 0, 0], + 'points': list() } for line in fd: line = line.strip() @@ -37,7 +41,7 @@ def read_stl(filename): elif line.startswith('facet'): parts = line.split(' ') for i in range(2, 5): - triangle['facet'][i-2] = float(parts[i]) + triangle['normal'][i-2] = float(parts[i]) continue elif line.startswith('vertex'): parts = line.split(' ') @@ -51,7 +55,7 @@ def read_stl(filename): elif line.startswith('endfacet'): triangles.append(triangle) triangle = { - "facet": [0, 0, 0], + "normal": [0, 0, 0], "points": list() } continue @@ -64,7 +68,9 @@ class Mesh(): def __init__(self, triangles): points = list() p_triangles = list() + p_normals = list() for triangle in triangles: + p_normals.append(triangle['normal']) p_triangle = list() for point in triangle['points']: if point not in points: @@ -75,10 +81,20 @@ class Mesh(): p_triangles.append(p_triangle) self.points = points self.triangles = p_triangles + self.normals = p_normals def validateSTL(filename): mesh = read_stl(filename); + + if len([n[i] for i in range(0,3) for n in mesh.points if math.isinf(n[i]) or math.isnan(n[i])]): + print "NaN of Inf vertices found" + return False + + if len([n[i] for i in range(0,3) for n in mesh.normals if math.isinf(n[i]) or math.isnan(n[i])]): + print "NaN of Inf normals found" + return False + edges = Counter((t[i], t[(i+1)%3]) for i in range(0,3) for t in mesh.triangles) reverse_edges = Counter((t[(i+1)%3], t[i]) for i in range(0,3) for t in mesh.triangles) edges.subtract(reverse_edges)