diff options
-rw-r--r-- | openscad.pro | 1 | ||||
-rw-r--r-- | src/csgterm.cc | 21 | ||||
-rw-r--r-- | src/linalg.h | 2 | ||||
-rw-r--r-- | testdata/scad/bugs/bbox-transform-bug.scad | 9 | ||||
-rw-r--r-- | tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | tests/regression/opencsgtest/bbox-transform-bug-expected.png | bin | 0 -> 5777 bytes | |||
-rw-r--r-- | tests/regression/opencsgtest/transform-tests-expected.png | bin | 17407 -> 15379 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/bbox-transform-bug-expected.png | bin | 0 -> 6285 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/intersection_for-tests-expected.png | bin | 5947 -> 8797 bytes | |||
-rw-r--r-- | tests/regression/throwntogethertest/transform-tests-expected.png | bin | 14734 -> 15379 bytes | |||
-rwxr-xr-x | tests/test_pretty_print.py | 2 |
11 files changed, 23 insertions, 16 deletions
diff --git a/openscad.pro b/openscad.pro index ac49807..50a419d 100644 --- a/openscad.pro +++ b/openscad.pro @@ -232,6 +232,7 @@ SOURCES += src/openscad.cc \ src/CSGTermEvaluator.cc \ src/Tree.cc \ src/mathc99.cc \ + src/linalg.cc \ src/PolySetCache.cc \ src/PolySetEvaluator.cc diff --git a/src/csgterm.cc b/src/csgterm.cc index 426adca..56fcbb5 100644 --- a/src/csgterm.cc +++ b/src/csgterm.cc @@ -115,25 +115,22 @@ CSGTerm::~CSGTerm() void CSGTerm::initBoundingBox() { if (this->type == TYPE_PRIMITIVE) { - BoundingBox polybox = this->polyset->getBoundingBox(); - this->bbox.extend(this->m * polybox.min()); - this->bbox.extend(this->m * polybox.max()); + this->bbox = this->m * this->polyset->getBoundingBox(); } else { const BoundingBox &leftbox = this->left->getBoundingBox(); const BoundingBox &rightbox = this->right->getBoundingBox(); switch (this->type) { case TYPE_UNION: - this->bbox.extend(this->m * leftbox.min().cwise().min(rightbox.min())); - this->bbox.extend(this->m * leftbox.max().cwise().max(rightbox.max())); + this->bbox = this->m * BoundingBox(leftbox.min().cwise().min(rightbox.min()), + leftbox.max().cwise().max(rightbox.max())); break; case TYPE_INTERSECTION: - this->bbox.extend(this->m * leftbox.min().cwise().max(rightbox.min())); - this->bbox.extend(this->m * leftbox.max().cwise().min(rightbox.max())); + this->bbox = this->m * BoundingBox(leftbox.min().cwise().max(rightbox.min()), + leftbox.max().cwise().min(rightbox.max())); break; case TYPE_DIFFERENCE: - this->bbox.extend(this->m * leftbox.min()); - this->bbox.extend(this->m * leftbox.max()); + this->bbox = this->m * leftbox; break; case TYPE_PRIMITIVE: break; @@ -330,11 +327,7 @@ BoundingBox CSGChain::getBoundingBox() const if (types[i] != CSGTerm::TYPE_DIFFERENCE) { BoundingBox psbox = polysets[i]->getBoundingBox(); if (!psbox.isNull()) { - Eigen::Transform3d t; - // Column-major vs. Row-major - t = matrices[i]; - bbox.extend(t * psbox.min()); - bbox.extend(t * psbox.max()); + bbox.extend(matrices[i] * psbox); } } } diff --git a/src/linalg.h b/src/linalg.h index a83949e..c1a14d1 100644 --- a/src/linalg.h +++ b/src/linalg.h @@ -13,4 +13,6 @@ using Eigen::Matrix3d; using Eigen::Matrix4d; using Eigen::Transform3d; +BoundingBox operator*(const Transform3d &m, const BoundingBox &box); + #endif diff --git a/testdata/scad/bugs/bbox-transform-bug.scad b/testdata/scad/bugs/bbox-transform-bug.scad new file mode 100644 index 0000000..ccd2eab --- /dev/null +++ b/testdata/scad/bugs/bbox-transform-bug.scad @@ -0,0 +1,9 @@ +// +// Bug description: The intersection results in an empty object. +// Cause: The rotated bounding box is wrongly calculated, yielding a +// box which don't overlap with the bounding box of the second object. +// +intersection() { + rotate(45) cube(10); + translate([3,2,0]) cube(10); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e98dd8e..a8ab9b9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -244,6 +244,7 @@ add_definitions(-DOPENSCAD_TESTING) set(CORE_SOURCES tests-common.cc ../src/mathc99.cc + ../src/linalg.cc ../src/handle_dep.cc ../src/value.cc ../src/expr.cc @@ -531,7 +532,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 OPENCSGTEST_FILES ${CGALPNGTEST_FILES}) -list(APPEND THROWNTOGETHERTEST_FILES ${CGALPNGTEST_FILES}) +list(APPEND OPENCSGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/bbox-transform-bug.scad) +list(APPEND THROWNTOGETHERTEST_FILES ${OPENCSGTEST_FILES}) # Disable tests which are known to cause floating point comparison issues # Once we're capable of comparing these across platforms, we can put these back in diff --git a/tests/regression/opencsgtest/bbox-transform-bug-expected.png b/tests/regression/opencsgtest/bbox-transform-bug-expected.png Binary files differnew file mode 100644 index 0000000..52e4f2a --- /dev/null +++ b/tests/regression/opencsgtest/bbox-transform-bug-expected.png diff --git a/tests/regression/opencsgtest/transform-tests-expected.png b/tests/regression/opencsgtest/transform-tests-expected.png Binary files differindex dc43942..52f4330 100644 --- a/tests/regression/opencsgtest/transform-tests-expected.png +++ b/tests/regression/opencsgtest/transform-tests-expected.png diff --git a/tests/regression/throwntogethertest/bbox-transform-bug-expected.png b/tests/regression/throwntogethertest/bbox-transform-bug-expected.png Binary files differnew file mode 100644 index 0000000..dd55c91 --- /dev/null +++ b/tests/regression/throwntogethertest/bbox-transform-bug-expected.png diff --git a/tests/regression/throwntogethertest/intersection_for-tests-expected.png b/tests/regression/throwntogethertest/intersection_for-tests-expected.png Binary files differindex c80a576..4721663 100644 --- a/tests/regression/throwntogethertest/intersection_for-tests-expected.png +++ b/tests/regression/throwntogethertest/intersection_for-tests-expected.png diff --git a/tests/regression/throwntogethertest/transform-tests-expected.png b/tests/regression/throwntogethertest/transform-tests-expected.png Binary files differindex a120581..52f4330 100644 --- a/tests/regression/throwntogethertest/transform-tests-expected.png +++ b/tests/regression/throwntogethertest/transform-tests-expected.png diff --git a/tests/test_pretty_print.py b/tests/test_pretty_print.py index 87ac3df..5e25052 100755 --- a/tests/test_pretty_print.py +++ b/tests/test_pretty_print.py @@ -158,7 +158,7 @@ def parsetest(teststring): hits = map( lambda pattern: ezsearch(pattern,teststring), patterns ) test = Test(hits[0],hits[1],hits[2]=='Passed',hits[3],hits[4],hits[5],hits[6],hits[7],teststring) if len(test.actualfile) > 0: test.actualfile_data = tryread(test.actualfile) - if len(test.actualfile) > 0: test.expectedfile_data = tryread(test.expectedfile) + if len(test.expectedfile) > 0: test.expectedfile_data = tryread(test.expectedfile) return test def parselog(data): |