Add Test for MakeElementRefine

This commit is contained in:
bgbsww
2024-02-03 12:23:03 -05:00
parent 31b7c3d145
commit 46230c9a93
8 changed files with 201 additions and 56 deletions

View File

@@ -15,6 +15,7 @@ target_sources(
${CMAKE_CURRENT_SOURCE_DIR}/TopoShape.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeCache.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeExpansion.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMakeElementRefine.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMakeShapeWithElementMap.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMapper.cpp
${CMAKE_CURRENT_SOURCE_DIR}/TopoShapeMakeShape.cpp

View File

@@ -642,7 +642,6 @@ TEST_F(TopoShapeExpansionTest, makeElementShellIntersecting)
auto transform {gp_Trsf()};
transform.SetTranslation(gp_Pnt(0.0, 0.0, 0.0), gp_Pnt(0.5, 0.5, 0.0));
cube2.Move(TopLoc_Location(transform));
// Arrange
Part::TopoShape topoShape {cube1};
std::vector<Part::TopoShape> shapes;
for (const auto& face : topoShape.getSubShapes(TopAbs_FACE)) {
@@ -655,7 +654,7 @@ TEST_F(TopoShapeExpansionTest, makeElementShellIntersecting)
// Act
Part::TopoShape topoShape1 {1L};
topoShape1.makeElementCompound(shapes, "D");
// Act / Assert
// Assert
EXPECT_THROW(topoShape1.makeElementShell(false, nullptr), Base::CADKernelError);
}

View File

@@ -0,0 +1,53 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
#include "gtest/gtest.h"
#include <src/App/InitApplication.h>
#include "PartTestHelpers.h"
class FeaturePartMakeElementRefineTest: public ::testing::Test,
public PartTestHelpers::PartTestHelperClass
{
protected:
static void SetUpTestSuite()
{
tests::initApplication();
}
void SetUp() override
{
createTestDoc();
}
void TearDown() override
{}
};
TEST_F(FeaturePartMakeElementRefineTest, makeElementRefineBoxes)
{
// Arrange
auto _doc = App::GetApplication().getActiveDocument();
auto _fuse = dynamic_cast<Part::Fuse*>(_doc->addObject("Part::Fuse"));
_fuse->Base.setValue(_boxes[0]);
_fuse->Tool.setValue(_boxes[3]);
// Act
_fuse->execute();
Part::TopoShape ts = _fuse->Shape.getValue();
Part::TopoShape refined = ts.makeElementRefine();
double volume = PartTestHelpers::getVolume(ts.getShape());
double refinedVolume = PartTestHelpers::getVolume(refined.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_TRUE(bb.IsValid());
EXPECT_DOUBLE_EQ(volume, 12.0);
EXPECT_DOUBLE_EQ(refinedVolume, 12.0); // Refine shouldn't change the volume
EXPECT_EQ(ts.countSubElements("Face"), 10); // Two boxes touching each loose one face
EXPECT_EQ(ts.countSubElements("Edge"), 20); // Two boxes touching loose 4 edges
EXPECT_EQ(refined.countSubElements("Face"), 6); // After refining it is one box
EXPECT_EQ(refined.countSubElements("Edge"), 12); // 12 edges in a box
// TODO: Make sure we have an elementMap for the refine.
// Refine doesn't work on compounds, so we're going to need a binary operation or the
// like, and those don't exist yet. Once they do, this test can be expanded
}