summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CGALEvaluator.cc6
-rw-r--r--src/linalg.cc21
-rw-r--r--src/linalg.h3
-rw-r--r--testdata/scad/bugs/transform-nan-inf-tests.scad12
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/regression/cgalpngtest/transform-nan-inf-tests-expected.pngbin0 -> 4333 bytes
-rw-r--r--tests/regression/opencsgtest/transform-nan-inf-tests-expected.pngbin0 -> 4718 bytes
-rw-r--r--tests/regression/throwntogethertest/transform-nan-inf-tests-expected.pngbin0 -> 4715 bytes
8 files changed, 44 insertions, 1 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index ee04e05..ac6190f 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -241,6 +241,12 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
// First union all children
N = applyToChildren(node, CGE_UNION);
+ if ( matrix_contains_infinity( node.matrix ) || matrix_contains_nan( node.matrix ) ) {
+ // due to the way parse/eval works we can't currently distinguish between NaN and Inf
+ PRINT("Warning: Transformation matrix contains Not-a-Number and/or Infinity - removing object.");
+ N.reset();
+ }
+
// Then apply transform
// If there is no geometry under the transform, N will be empty and of dim 0,
// just just silently ignore such nodes
diff --git a/src/linalg.cc b/src/linalg.cc
index 30f23af..b0ea2b4 100644
--- a/src/linalg.cc
+++ b/src/linalg.cc
@@ -1,4 +1,5 @@
#include "linalg.h"
+#include <boost/math/special_functions/fpclassify.hpp>
// FIXME: We can achieve better pruning by either:
// o Recalculate the box based on the transformed object
@@ -25,3 +26,23 @@ BoundingBox operator*(const Transform3d &m, const BoundingBox &box)
return newbox;
}
+bool matrix_contains_infinity( const Eigen::Transform3d &m )
+{
+ for (int i=0;i<m.matrix().rows();i++) {
+ for (int j=0;j<m.matrix().cols();j++) {
+ if ((boost::math::isinf)(m(i,j))) return true;
+ }
+ }
+ return false;
+}
+
+bool matrix_contains_nan( const Eigen::Transform3d &m )
+{
+ for (int i=0;i<m.matrix().rows();i++) {
+ for (int j=0;j<m.matrix().cols();j++) {
+ if ((boost::math::isnan)(m(i,j))) return true;
+ }
+ }
+ return false;
+}
+
diff --git a/src/linalg.h b/src/linalg.h
index 7f12a2e..450e593 100644
--- a/src/linalg.h
+++ b/src/linalg.h
@@ -18,6 +18,9 @@ using Eigen::Matrix4d;
using Eigen::Transform3d;
#endif
+bool matrix_contains_infinity( const Eigen::Transform3d &m );
+bool matrix_contains_nan( const Eigen::Transform3d &m );
+
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
class Color4f : public Eigen::Vector4f
diff --git a/testdata/scad/bugs/transform-nan-inf-tests.scad b/testdata/scad/bugs/transform-nan-inf-tests.scad
new file mode 100644
index 0000000..cb8a667
--- /dev/null
+++ b/testdata/scad/bugs/transform-nan-inf-tests.scad
@@ -0,0 +1,12 @@
+// Test translation by NaN and Infinity
+// cube()s should not be rendered
+
+// NaN
+sphere();
+rotate([0, 0, asin(1.1) ]) cube();
+
+// Infinity (as of 2012-08 this is detected as NaN)
+translate([4,0,0]) {
+ sphere();
+ rotate([0, 0, 1/0]) cube();
+}
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 12fca3c..33f3547 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -713,7 +713,8 @@ list(APPEND DUMPTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/escape-test
list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILES})
list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad
- ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad)
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad
+ ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad)
list(APPEND OPENCSGTEST_FILES ${CGALPNGTEST_FILES})
list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/bbox-transform-bug.scad)
list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/intersection-prune-test.scad)
diff --git a/tests/regression/cgalpngtest/transform-nan-inf-tests-expected.png b/tests/regression/cgalpngtest/transform-nan-inf-tests-expected.png
new file mode 100644
index 0000000..2d9c3ba
--- /dev/null
+++ b/tests/regression/cgalpngtest/transform-nan-inf-tests-expected.png
Binary files differ
diff --git a/tests/regression/opencsgtest/transform-nan-inf-tests-expected.png b/tests/regression/opencsgtest/transform-nan-inf-tests-expected.png
new file mode 100644
index 0000000..c756800
--- /dev/null
+++ b/tests/regression/opencsgtest/transform-nan-inf-tests-expected.png
Binary files differ
diff --git a/tests/regression/throwntogethertest/transform-nan-inf-tests-expected.png b/tests/regression/throwntogethertest/transform-nan-inf-tests-expected.png
new file mode 100644
index 0000000..b706711
--- /dev/null
+++ b/tests/regression/throwntogethertest/transform-nan-inf-tests-expected.png
Binary files differ
contact: Jan Huwald // Impressum