Merge pull request #186 from openscad/issue185

Issue185
felipesanches-svg
Marius Kintel 2012-08-21 17:31:28 -07:00
commit a629560cee
8 changed files with 44 additions and 1 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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

View File

@ -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();
}

View File

@ -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)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB