Cleanups per pesc0 review notes; general code tightening

This commit is contained in:
bgbsww
2023-12-23 05:47:39 -05:00
parent 906826c1c8
commit f81ce9d2e1
5 changed files with 277 additions and 182 deletions

View File

@@ -18,7 +18,7 @@ protected:
void SetUp() override
{
createTestFile();
createTestDoc();
_common = static_cast<Part::Common*>(_doc->addObject("Part::Common"));
}
@@ -31,119 +31,119 @@ protected:
TEST_F(FeaturePartCommonTest, testIntersecting)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box2obj);
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[1]);
// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
// Base::BoundBox3d bb = ts.getBoundBox();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
// If we wanted to be excessive, we could check the bounds:
// EXPECT_EQ(bb.MinX, 0);
// EXPECT_EQ(bb.MinY, 1);
// EXPECT_EQ(bb.MinZ, 0);
// EXPECT_EQ(bb.MaxX, 1);
// EXPECT_EQ(bb.MaxY, 2);
// EXPECT_EQ(bb.MaxZ, 3);
double volume = PartTestHelpers::getVolume(ts.getShape());
EXPECT_DOUBLE_EQ(volume, 3.0);
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 1.0);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCommonTest, testNonIntersecting)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box3obj);
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[2]);
// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FALSE(bb.IsValid());
double volume = PartTestHelpers::getVolume(ts.getShape());
EXPECT_DOUBLE_EQ(volume, 0.0);
}
TEST_F(FeaturePartCommonTest, testTouching)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box4obj);
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[3]);
// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FALSE(bb.IsValid());
double volume = PartTestHelpers::getVolume(ts.getShape());
EXPECT_DOUBLE_EQ(volume, 0.0);
}
TEST_F(FeaturePartCommonTest, testAlmostTouching)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box5obj);
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[4]);
// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FALSE(bb.IsValid());
double volume = PartTestHelpers::getVolume(ts.getShape());
EXPECT_DOUBLE_EQ(volume, 0.0);
}
TEST_F(FeaturePartCommonTest, testBarelyIntersecting)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box6obj);
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[5]);
// Act
_common->execute();
Part::TopoShape ts = _common->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
double target = Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_EQ(bb.MinX, 0);
EXPECT_EQ(bb.MinY, 1.9999);
EXPECT_EQ(bb.MinZ, 0);
EXPECT_EQ(bb.MaxX, 1);
EXPECT_EQ(bb.MaxY, 2);
EXPECT_EQ(bb.MaxZ, 3);
double volume = PartTestHelpers::getVolume(ts.getShape());
double target = Base::Precision::Confusion() * 3 * 1000;
// FLOAT, not DOUBLE here, because ULP accuracy would be too precise.
EXPECT_FLOAT_EQ(volume, target); // 0.00029999999999996696);
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15
// See https://google.github.io/googletest/reference/assertions.html#floating-point
EXPECT_FLOAT_EQ(volume, target); // Should be approximately 0.00029999999999996696
// double check using bounds:
EXPECT_DOUBLE_EQ(bb.MinX, 0.0);
EXPECT_DOUBLE_EQ(bb.MinY, 1.9999);
EXPECT_DOUBLE_EQ(bb.MinZ, 0.0);
EXPECT_DOUBLE_EQ(bb.MaxX, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxY, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCommonTest, testMustExecute)
{
// Act
short mE = _common->mustExecute();
// Assert
EXPECT_FALSE(mE);
_common->Base.setValue(_box1obj);
// Assert
mE = _common->mustExecute();
EXPECT_FALSE(mE);
// Act
_common->Tool.setValue(_box2obj);
// Assert
mE = _common->mustExecute();
EXPECT_TRUE(mE);
// Assert initially we don't need to execute
EXPECT_FALSE(_common->mustExecute());
// Act to change one property
_common->Base.setValue(_boxes[0]);
// Assert we still can't execute
EXPECT_FALSE(_common->mustExecute());
// Act to complete the properties we need
_common->Tool.setValue(_boxes[1]);
// Assert that we now must execute
EXPECT_TRUE(_common->mustExecute());
// Act to execute
_doc->recompute();
mE = _common->mustExecute();
EXPECT_FALSE(mE);
// Assert we don't need to execute anymore
EXPECT_FALSE(_common->mustExecute());
}
TEST_F(FeaturePartCommonTest, testGetProviderName)
@@ -155,55 +155,38 @@ TEST_F(FeaturePartCommonTest, testGetProviderName)
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
}
namespace Part
{
void PrintTo(ShapeHistory sh, std::ostream* os)
{
const char* types[] =
{"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"};
*os << "History for " << types[sh.type] << " is ";
for (const auto& it : sh.shapeMap) {
int old_shape_index = it.first;
*os << " " << old_shape_index << ": ";
if (!it.second.empty()) {
for (auto it2 : it.second) {
*os << it2 << " ";
}
}
}
*os << std::endl;
}
} // namespace Part
TEST_F(FeaturePartCommonTest, testHistory)
{
// Arrange
_common->Base.setValue(_box1obj);
_common->Tool.setValue(_box2obj);
// Act and Assert
std::vector<Part::ShapeHistory> hist = _common->History.getValues();
EXPECT_EQ(hist.size(), 0);
// This creates the histories classically generated by FreeCAD for comparison
_common->Base.setValue(_boxes[0]);
_common->Tool.setValue(_boxes[1]);
// Manually create the histories classically generated by FreeCAD for comparison
using MapList = std::map<int, std::vector<int>>;
using List = std::vector<int>;
MapList compare1 =
{{0, List {0}}, {1, List {5}}, {2, List()}, {3, List {2}}, {4, List {3}}, {5, List {1}}};
{{0, List {0}}, {1, List {5}}, {2, List () }, {3, List {2}}, {4, List {3}}, {5, List {1}}};
MapList compare2 =
{{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List()}, {4, List {3}}, {5, List {1}}};
{{0, List {0}}, {1, List {5}}, {2, List {4}}, {3, List () }, {4, List {3}}, {5, List {1}}};
// Act and Assert no histories yet
std::vector<Part::ShapeHistory> hist = _common->History.getValues();
EXPECT_EQ(hist.size(), 0);
// Act to generate histories
_common->execute();
hist = _common->History.getValues();
EXPECT_EQ(hist.size(), 2);
// Assert
ASSERT_EQ(hist.size(), 2);
EXPECT_EQ(hist[0].shapeMap, compare1);
EXPECT_EQ(hist[1].shapeMap, compare2);
_common->Base.setValue(_box2obj);
_common->Tool.setValue(_box1obj);
// Act to reverse the histories
_common->Base.setValue(_boxes[1]);
_common->Tool.setValue(_boxes[0]);
_common->execute();
hist = _common->History.getValues();
// std::cout << testing::PrintToString(hist[0]) << testing::PrintToString(hist[1]);
EXPECT_EQ(hist.size(), 2);
EXPECT_EQ(hist[1].shapeMap, compare1);
// Assert
ASSERT_EQ(hist.size(), 2);
EXPECT_EQ(hist[0].shapeMap, compare2);
EXPECT_EQ(hist[1].shapeMap, compare1);
}

View File

@@ -15,106 +15,152 @@ protected:
tests::initApplication();
}
void SetUp() override
{
createTestFile();
createTestDoc();
_cut = static_cast<Part::Cut*>(_doc->addObject("Part::Cut"));
}
void TearDown() override
{}
Part::Cut* _cut;
};
TEST_F(FeaturePartCutTest, testIntersecting)
{
// Arrange
_cut->Base.setValue(_box1obj);
_cut->Tool.setValue(_box2obj);
_cut->Base.setValue(_boxes[0]);
_cut->Tool.setValue(_boxes[1]);
// Act
_cut->execute();
Part::TopoShape ts = _cut->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 3.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, 1.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCutTest, testNonIntersecting)
{
// Arrange
_cut->Base.setValue(_box1obj);
_cut->Tool.setValue(_box3obj);
_cut->Base.setValue(_boxes[0]);
_cut->Tool.setValue(_boxes[2]);
// Act
_cut->execute();
Part::TopoShape ts = _cut->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 6.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, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCutTest, testTouching)
{
// Arrange
_cut->Base.setValue(_box1obj);
_cut->Tool.setValue(_box4obj);
_cut->Base.setValue(_boxes[0]);
_cut->Tool.setValue(_boxes[3]);
// Act
_cut->execute();
Part::TopoShape ts = _cut->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 6.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, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCutTest, testAlmostTouching)
{
// Arrange
_cut->Base.setValue(_box1obj);
_cut->Tool.setValue(_box5obj);
_cut->Base.setValue(_boxes[0]);
_cut->Tool.setValue(_boxes[4]);
// Act
_cut->execute();
Part::TopoShape ts = _cut->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 6.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, 2.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCutTest, testBarelyIntersecting)
{
// Arrange
_cut->Base.setValue(_box1obj);
_cut->Tool.setValue(_box6obj);
_cut->Base.setValue(_boxes[0]);
_cut->Tool.setValue(_boxes[5]);
// Act
_cut->execute();
Part::TopoShape ts = _cut->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
double target = 6 - Base::Precision::Confusion() * 3 * 1000;
double target = 6 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15
// See https://google.github.io/googletest/reference/assertions.html#floating-point
EXPECT_FLOAT_EQ(volume, target);
// 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, 1.9999);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartCutTest, testMustExecute)
{
// Act
short mE = _cut->mustExecute();
// Assert
EXPECT_FALSE(mE);
_cut->Base.setValue(_box1obj);
// Assert
mE = _cut->mustExecute();
EXPECT_FALSE(mE);
// Act
_cut->Tool.setValue(_box2obj);
// Assert
mE = _cut->mustExecute();
EXPECT_TRUE(mE);
// Assert initially we don't need to execute
EXPECT_FALSE(_cut->mustExecute());
// Act to change one property
_cut->Base.setValue(_boxes[0]);
// Assert we still can't execute
EXPECT_FALSE(_cut->mustExecute());
// Act to complete the properties we need
_cut->Tool.setValue(_boxes[1]);
// Assert that we now must execute
EXPECT_TRUE(_cut->mustExecute());
// Act to execute
_doc->recompute();
mE = _cut->mustExecute();
EXPECT_FALSE(mE);
// Assert we don't need to execute anymore
EXPECT_FALSE(_cut->mustExecute());
}
TEST_F(FeaturePartCutTest, testGetProviderName)
@@ -125,3 +171,5 @@ TEST_F(FeaturePartCutTest, testGetProviderName)
// Assert
EXPECT_STREQ(name, "PartGui::ViewProviderBoolean");
}
// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here.

View File

@@ -16,10 +16,9 @@ protected:
tests::initApplication();
}
void SetUp() override
{
createTestFile();
createTestDoc();
_fuse = static_cast<Part::Fuse*>(_doc->addObject("Part::Fuse"));
}
@@ -32,87 +31,137 @@ protected:
TEST_F(FeaturePartFuseTest, testIntersecting)
{
// Arrange
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box2obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[1]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->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
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box3obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[2]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 12.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, 5.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testTouching)
{
// Arrange
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box4obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[3]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_DOUBLE_EQ(volume, 12.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, 4.0);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testAlmostTouching)
{
// Arrange
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box5obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[4]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
EXPECT_FLOAT_EQ(volume, 12.0);
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, 12.0); // Use FLOAT to limit precision to 1E07 rather than 1E15
// 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_FLOAT_EQ(bb.MaxY, 4.0); // Use FLOAT to limit precision to 1E07 rather than 1E15
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testBarelyIntersecting)
{
// Arrange
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box6obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[5]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
double volume = PartTestHelpers::getVolume(ts.getShape());
double target = 12 - Base::Precision::Confusion() * 3 * 1000;
double target = 12 - Base::Precision::Confusion() * 3 * 1000; // Reduce precision to 1e04 over 3 dimensions
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
// Using FLOAT, not DOUBLE here so test library comparison is of reasonable precision 1e07 rather than 1e15
// See https://google.github.io/googletest/reference/assertions.html#floating-point
EXPECT_FLOAT_EQ(volume, target);
// 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.9999);
EXPECT_DOUBLE_EQ(bb.MaxZ, 3.0);
}
TEST_F(FeaturePartFuseTest, testMustExecute)
{
// Act
short mE = _fuse->mustExecute();
// Assert
EXPECT_FALSE(mE);
_fuse->Base.setValue(_box1obj);
// Assert
mE = _fuse->mustExecute();
EXPECT_FALSE(mE);
// Act
_fuse->Tool.setValue(_box2obj);
// Assert
mE = _fuse->mustExecute();
EXPECT_TRUE(mE);
// Assert initially we don't need to execute
EXPECT_FALSE(_fuse->mustExecute());
// Act to change one property
_fuse->Base.setValue(_boxes[0]);
// Assert we still can't execute
EXPECT_FALSE(_fuse->mustExecute());
// Act to complete the properties we need
_fuse->Tool.setValue(_boxes[1]);
// Assert that we now must execute
EXPECT_TRUE(_fuse->mustExecute());
// Act to execute
_doc->recompute();
mE = _fuse->mustExecute();
EXPECT_FALSE(mE);
// Assert we don't need to execute anymore
EXPECT_FALSE(_fuse->mustExecute());
}
TEST_F(FeaturePartFuseTest, testGetProviderName)
@@ -127,19 +176,22 @@ TEST_F(FeaturePartFuseTest, testGetProviderName)
TEST_F(FeaturePartFuseTest, testRefine)
{
// Arrange
_fuse->Base.setValue(_box1obj);
_fuse->Tool.setValue(_box2obj);
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[1]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
// what's the wire or face count here?
std::vector<Part::TopoShape> subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE
std::vector<Part::TopoShape> subs = ts.getSubTopoShapes(TopAbs_FACE); // TopAbs_WIRE alternate approach
// Assert two boxes, plus redundant faces at the joint.
EXPECT_EQ(subs.size(), 14);
// Assert
// Act
_fuse->Refine.setValue(true);
_fuse->execute();
ts = _fuse->Shape.getValue();
subs = ts.getSubTopoShapes(TopAbs_FACE); // WIRE
subs = ts.getSubTopoShapes(TopAbs_FACE);
// Assert we now just have one big box
EXPECT_EQ(subs.size(), 6);
}
// See FeaturePartCommon.cpp for a history test. It would be exactly the same and redundant here.

View File

@@ -11,37 +11,50 @@ double getVolume(TopoDS_Shape shape)
return prop.Mass();
}
void PartTestHelperClass::createTestFile()
void PartTestHelperClass::createTestDoc()
{
_docName = App::GetApplication().getUniqueDocumentName("test");
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
_box1obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
_box2obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
_box3obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
_box4obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
_box5obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
_box6obj = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
for (auto _box : {_box1obj, _box2obj, _box3obj, _box4obj, _box5obj, _box6obj}) {
_box->Length.setValue(1);
_box->Width.setValue(2);
_box->Height.setValue(3);
}
_box1obj->Placement.setValue(
Base::Placement(Base::Vector3d(), Base::Rotation(), Base::Vector3d()));
_box2obj->Placement.setValue(
Base::Placement(Base::Vector3d(0, 1, 0), Base::Rotation(), Base::Vector3d()));
_box3obj->Placement.setValue(
Base::Placement(Base::Vector3d(0, 3, 0), Base::Rotation(), Base::Vector3d()));
_box4obj->Placement.setValue(
Base::Placement(Base::Vector3d(0, 2, 0), Base::Rotation(), Base::Vector3d()));
_box5obj->Placement.setValue(
Base::Placement(Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0),
Base::Rotation(),
Base::Vector3d()));
_box6obj->Placement.setValue(
Base::Placement(Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0),
Base::Rotation(),
Base::Vector3d()));
_docName = App::GetApplication().getUniqueDocumentName("test");
_doc = App::GetApplication().newDocument(_docName.c_str(), "testUser");
std::array<Base::Vector3d, 6> box_origins = {
Base::Vector3d(), // First box at 0,0,0
Base::Vector3d(0, 1, 0), // Overlap with first box
Base::Vector3d(0, 3, 0), // Don't Overlap with first box
Base::Vector3d(0, 2, 0), // Touch the first box
Base::Vector3d(0, 2 + Base::Precision::Confusion(), 0), // Just Outside of touching
// For just inside of touching, go enough that precision rounding doesn't make us overlap.
Base::Vector3d(0, 2 - Base::Precision::Confusion() * 1000, 0)
};
// for (auto& [box, origin] : zip(_boxes, box_origins) ) {
// for ( int i : range(0,_boxes.size())) {
for ( unsigned i=0; i < _boxes.size(); i++ ) {
auto box = _boxes[i] = static_cast<Part::Box*>(_doc->addObject("Part::Box"));
box->Length.setValue(1);
box->Width.setValue(2);
box->Height.setValue(3);
box->Placement.setValue(Base::Placement(box_origins[i], Base::Rotation(), Base::Vector3d() ) );
}
}
} // namespace PartTestHelpers
}
// https://google.github.io/googletest/advanced.html#teaching-googletest-how-to-print-your-values
namespace Part
{
void PrintTo(ShapeHistory sh, std::ostream* os)
{
const char* types[] =
{"Compound", "CompSolid", "Solid", "Shell", "Face", "Wire", "Edge", "Vertex", "Shape"};
*os << "History for " << types[sh.type] << " is ";
for (const auto& it : sh.shapeMap) {
int old_shape_index = it.first;
*os << " " << old_shape_index << ": ";
if (!it.second.empty()) {
for (auto it2 : it.second) {
*os << it2 << " ";
}
}
}
*os << std::endl;
}
} // namespace Part

View File

@@ -16,9 +16,8 @@ class PartTestHelperClass
public:
App::Document* _doc;
std::string _docName;
Part::Box *_box1obj, *_box2obj, *_box3obj, *_box4obj, *_box5obj, *_box6obj;
void createTestFile();
std::array<Part::Box *, 6> _boxes;
void createTestDoc();
};
} // namespace PartTestHelpers