mirror of https://github.com/vitalif/openscad
#1225 Fix nan or inf normal vector output
parent
56f3552404
commit
b13075d2a5
|
@ -150,9 +150,16 @@ void export_stl(const PolySet &ps, std::ostream &output)
|
|||
// so the default value of "1 0 0" can be used. If the vertices are not
|
||||
// collinear then the unit normal must be calculated from the
|
||||
// components.
|
||||
output << " facet normal ";
|
||||
|
||||
Vector3d normal = (p[1] - p[0]).cross(p[2] - p[0]);
|
||||
normal.normalize();
|
||||
output << " facet normal " << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
|
||||
if (is_finite(normal) && !is_nan(normal)) {
|
||||
output << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
|
||||
}
|
||||
else {
|
||||
output << "0 0 0\n";
|
||||
}
|
||||
output << " outer loop\n";
|
||||
|
||||
BOOST_FOREACH(const Vector3d &v, p) {
|
||||
|
|
|
@ -24,6 +24,14 @@ using Eigen::Matrix4d;
|
|||
bool matrix_contains_infinity( const Transform3d &m );
|
||||
bool matrix_contains_nan( const Transform3d &m );
|
||||
|
||||
template<typename Derived> bool is_finite(const Eigen::MatrixBase<Derived>& x) {
|
||||
return ( (x - x).array() == (x - x).array()).all();
|
||||
}
|
||||
|
||||
template<typename Derived> bool is_nan(const Eigen::MatrixBase<Derived>& x) {
|
||||
return ((x.array() == x.array())).all();
|
||||
}
|
||||
|
||||
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
|
||||
|
||||
class Color4f : public Eigen::Vector4f
|
||||
|
|
Loading…
Reference in New Issue