diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h index 44813df5..3ba9ffad 100644 --- a/src/CGAL_Nef_polyhedron.h +++ b/src/CGAL_Nef_polyhedron.h @@ -28,7 +28,8 @@ public: CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron *copy() const; class PolySet *convertToPolyset() const; - void transform( const Transform3d &matrix ); + void transform( const CGAL_Nef_polyhedron3::Aff_transformation_3 &t ); + void transform( const Transform3d &t ); shared_ptr p3; }; diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index 5ca39e8e..b4fbb5f5 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -42,21 +42,38 @@ std::string CGAL_Nef_polyhedron::dump() const } -void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) +void CGAL_Nef_polyhedron::transform( const CGAL_Nef_polyhedron3::Aff_transformation_3 &t ) { if (!this->isEmpty()) { - if (matrix.matrix().determinant() == 0) { + if (CGAL::sign_of_determinant( + t.cartesian(0,0),t.cartesian(0,1),t.cartesian(0,2), + t.cartesian(1,0),t.cartesian(1,1),t.cartesian(1,2), + t.cartesian(2,0),t.cartesian(2,1),t.cartesian(2,2) + )==0) { PRINT("Warning: Scaling a 3D object with 0 - removing object"); this->reset(); } else { - CGAL_Aff_transformation t( - matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3), - matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3), - matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3), matrix(3,3)); this->p3->transform(t); } } } +void CGAL_Nef_polyhedron::transform( const Transform3d &t ) +{ + if (!this->isEmpty()) { + if (t.matrix().determinant()==0) { + PRINT("Warning: Scaling a 3D object with 0 - removing object"); + this->reset(); + } + else { + CGAL_Nef_polyhedron3::Aff_transformation_3 aff( + t(0,0),t(0,1),t(0,2),t(0,3), + t(1,0),t(1,1),t(1,2),t(1,3), + t(2,0),t(2,1),t(2,2),t(2,3),t(3,3) ); + this->p3->transform(aff); + } + } +} + #endif // ENABLE_CGAL diff --git a/src/GeometryEvaluator.cc b/src/GeometryEvaluator.cc index 6b5a8c89..93060128 100644 --- a/src/GeometryEvaluator.cc +++ b/src/GeometryEvaluator.cc @@ -203,13 +203,12 @@ void GeometryEvaluator::applyResize3D(CGAL_Nef_polyhedron &N, if (autosize[i] && newsize[i]==0) scale[i] = autoscale; } - Eigen::Matrix4d t; - t << CGAL::to_double(scale[0]), 0, 0, 0, - 0, CGAL::to_double(scale[1]), 0, 0, - 0, 0, CGAL::to_double(scale[2]), 0, - 0, 0, 0, 1; + CGAL_Nef_polyhedron3::Aff_transformation_3 aff( + scale[0], 0, 0, + 0, scale[1], 0, + 0, 0, scale[2], 1 ); - N.transform(Transform3d(t)); + N.transform( aff ); return; } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6461bd85..fb16072f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -842,6 +842,7 @@ list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILE 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/bugs/transform-nan-inf-tests.scad + ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-precision.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles_dir/localfiles-compatibility-test.scad ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/rotate-empty-bbox.scad