Part: bugfix #17468 recursively unpack compounds for boolean fuse (#17469)

* fix #17468  recursively unpack compounds for boolean fuse

* fix and into &&, add ctest case for multifuse with compounds and recursive compounds

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unneeded duplicated code - allow Part::Common to be created with a single object (compound or shape) - will result in Unity and possibly a warning message

* prevent endless loop in case of endless recursive compounds as suggested in chat

* Update src/Mod/Part/App/FeaturePartFuse.cpp

Co-authored-by: Benjamin Nauck <benjamin@nauck.se>

* implemented suggestion by wwmayer

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Benjamin Nauck <benjamin@nauck.se>
This commit is contained in:
Eric Price
2024-11-11 17:51:56 +01:00
committed by GitHub
parent 3d5e4f7cd8
commit 03cb520215
3 changed files with 71 additions and 20 deletions

View File

@@ -4,6 +4,7 @@
#include "Mod/Part/App/FeaturePartFuse.h"
#include <src/App/InitApplication.h>
#include "Mod/Part/App/FeatureCompound.h"
#include "PartTestHelpers.h"
@@ -20,12 +21,14 @@ protected:
{
createTestDoc();
_fuse = dynamic_cast<Part::Fuse*>(_doc->addObject("Part::Fuse"));
_multiFuse = dynamic_cast<Part::MultiFuse*>(_doc->addObject("Part::MultiFuse"));
}
void TearDown() override
{}
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
Part::Fuse* _fuse = nullptr; // NOLINT Can't be private in a test framework
Part::MultiFuse* _multiFuse = nullptr; // NOLINT Can't be private in a test framework
};
TEST_F(FeaturePartFuseTest, testIntersecting)
@@ -51,6 +54,64 @@ TEST_F(FeaturePartFuseTest, testIntersecting)
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testCompound)
{
// Arrange
Part::Compound* _compound = nullptr;
_compound = dynamic_cast<Part::Compound*>(_doc->addObject("Part::Compound"));
_compound->Links.setValues({_boxes[0], _boxes[1]});
_multiFuse->Shapes.setValues({_compound});
// Act
_compound->execute();
_multiFuse->execute();
Part::TopoShape ts = _multiFuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 9.0);
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 3.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testRecursiveCompound)
{
// Arrange
Part::Compound* _compound[3] = {nullptr};
int t;
for (t = 0; t < 3; t++) {
_compound[t] = dynamic_cast<Part::Compound*>(_doc->addObject("Part::Compound"));
}
_compound[0]->Links.setValues({_boxes[0], _boxes[1]});
_compound[1]->Links.setValues({_compound[0]});
_compound[2]->Links.setValues({_compound[1]});
_multiFuse->Shapes.setValues({_compound[2]});
// Act
for (t = 0; t < 3; t++) {
_compound[t]->execute();
}
_multiFuse->execute();
Part::TopoShape ts = _multiFuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 9.0);
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 0.0);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 3.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testNonIntersecting)
{
// Arrange