From f1d4a52f4cc01843f5d7c40499fcfe44cc82712f Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 21 Aug 2012 01:33:13 +0200 Subject: dont crash if there's infinity or NaN in transformation matrix diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index ee04e05..c84d21f 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -241,6 +241,15 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) // First union all children N = applyToChildren(node, CGE_UNION); + if ( matrix_contains_infinity( node.matrix ) ) { + PRINT("Warning: Transformation matrix contains Infinity - removing object."); + N.reset(); + } + if ( matrix_contains_nan( node.matrix ) ) { + PRINT("Warning: Transformation matrix contains Not-a-Number - 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 @@ -248,7 +257,7 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) // Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2 // objects. So we convert in to our internal 2d data format, transform it, // tesselate it and create a new CGAL_Nef_polyhedron2 from it.. What a hack! - + Eigen::Matrix2f testmat; testmat << node.matrix(0,0), node.matrix(0,1), node.matrix(1,0), node.matrix(1,1); if (testmat.determinant() == 0) { 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 // 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 Date: Tue, 21 Aug 2012 01:40:06 +0200 Subject: improve test scad diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index c84d21f..75b9097 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -257,7 +257,7 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) // Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2 // objects. So we convert in to our internal 2d data format, transform it, // tesselate it and create a new CGAL_Nef_polyhedron2 from it.. What a hack! - + Eigen::Matrix2f testmat; testmat << node.matrix(0,0), node.matrix(0,1), node.matrix(1,0), node.matrix(1,1); if (testmat.determinant() == 0) { diff --git a/testdata/scad/bugs/transform-nan-inf-tests.scad b/testdata/scad/bugs/transform-nan-inf-tests.scad index eff62fc..eb3cb0c 100644 --- a/testdata/scad/bugs/transform-nan-inf-tests.scad +++ b/testdata/scad/bugs/transform-nan-inf-tests.scad @@ -1,10 +1,10 @@ // Test translation by NaN and Infinity -// NaN test - cube(2) should not be rendered -cube(1); +// NaN test - cube() should not be rendered +sphere(); angle = asin(1.1); render() rotate([0, 0, angle]) -cube(2); +cube(); // FIXME: how do you test infinity? diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ce7698e..66cd36e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -670,6 +670,7 @@ list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include- 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) +list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad) list(APPEND THROWNTOGETHERTEST_FILES ${OPENCSGTEST_FILES}) list(APPEND CGALSTLSANITYTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/normal-nan.scad) -- cgit v0.10.1 From 358129cad65758b2e732558fa3bbae2fffaecf83 Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 21 Aug 2012 02:39:18 +0200 Subject: improve test scad. don't use dumptest(), 'nan' is a bit of a problem diff --git a/testdata/scad/bugs/transform-nan-inf-tests.scad b/testdata/scad/bugs/transform-nan-inf-tests.scad index eb3cb0c..b647d08 100644 --- a/testdata/scad/bugs/transform-nan-inf-tests.scad +++ b/testdata/scad/bugs/transform-nan-inf-tests.scad @@ -1,10 +1,12 @@ // Test translation by NaN and Infinity +// cube()s should not be rendered -// NaN test - cube() should not be rendered +// NaN sphere(); -angle = asin(1.1); -render() -rotate([0, 0, angle]) -cube(); +rotate([0, 0, asin(1.1) ]) cube(); -// FIXME: how do you test infinity? +// Infinity +translate([4,0,0]) { + sphere(); + rotate([0, 0, 1/0]) cube(); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 66cd36e..bb7738a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -666,11 +666,11 @@ 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) -list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad) list(APPEND THROWNTOGETHERTEST_FILES ${OPENCSGTEST_FILES}) list(APPEND CGALSTLSANITYTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/normal-nan.scad) -- cgit v0.10.1 From 6a8254f8492f4b07ecbfd58f9f6313791b1f035a Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 21 Aug 2012 02:47:45 +0200 Subject: add images for tests 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 Binary files /dev/null and b/tests/regression/cgalpngtest/transform-nan-inf-tests-expected.png 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 Binary files /dev/null and b/tests/regression/opencsgtest/transform-nan-inf-tests-expected.png 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 Binary files /dev/null and b/tests/regression/throwntogethertest/transform-nan-inf-tests-expected.png differ -- cgit v0.10.1 From 69f90c13bb7826fc2da6f1f5c35ab3ac550fc6da Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 21 Aug 2012 02:54:53 +0200 Subject: clarify that 'infinity' is not 'really' tested currently. diff --git a/testdata/scad/bugs/transform-nan-inf-tests.scad b/testdata/scad/bugs/transform-nan-inf-tests.scad index b647d08..cb8a667 100644 --- a/testdata/scad/bugs/transform-nan-inf-tests.scad +++ b/testdata/scad/bugs/transform-nan-inf-tests.scad @@ -5,7 +5,7 @@ sphere(); rotate([0, 0, asin(1.1) ]) cube(); -// Infinity +// Infinity (as of 2012-08 this is detected as NaN) translate([4,0,0]) { sphere(); rotate([0, 0, 1/0]) cube(); -- cgit v0.10.1 From d831b44474b4b3220d884306fd29aaf0cb5810fe Mon Sep 17 00:00:00 2001 From: don bright Date: Tue, 21 Aug 2012 03:10:06 +0200 Subject: clarify warning message diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 75b9097..ac6190f 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -241,12 +241,9 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) // First union all children N = applyToChildren(node, CGE_UNION); - if ( matrix_contains_infinity( node.matrix ) ) { - PRINT("Warning: Transformation matrix contains Infinity - removing object."); - N.reset(); - } - if ( matrix_contains_nan( node.matrix ) ) { - PRINT("Warning: Transformation matrix contains Not-a-Number - removing object"); + 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(); } -- cgit v0.10.1