diff options
author | Marius Kintel <marius@kintel.net> | 2012-08-22 00:31:28 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2012-08-22 00:31:28 (GMT) |
commit | a629560cee963087f6e43019d37933ce60776e49 (patch) | |
tree | ad8c0b150ce405b49eb575593ac778415047ce58 /src | |
parent | 1e56bf65b940f4d71104a358d3fea1e06f0ee461 (diff) | |
parent | d831b44474b4b3220d884306fd29aaf0cb5810fe (diff) |
Merge pull request #186 from openscad/issue185
Issue185
Diffstat (limited to 'src')
-rw-r--r-- | src/CGALEvaluator.cc | 6 | ||||
-rw-r--r-- | src/linalg.cc | 21 | ||||
-rw-r--r-- | src/linalg.h | 3 |
3 files changed, 30 insertions, 0 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 |