Merge branch 'main' into bgbsww-toponamingMakeElementSliceMirror
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// SPDX-License-Identifier: LGPL-2.1-or-later
|
||||
|
||||
#include <regex>
|
||||
#include "PartTestHelpers.h"
|
||||
|
||||
// NOLINTBEGIN(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
@@ -137,6 +138,32 @@ std::map<IndexedName, MappedName> elementMap(const TopoShape& shape)
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string mappedElementVectorToString(std::vector<MappedElement>& elements)
|
||||
{
|
||||
std::stringstream output;
|
||||
output << "{";
|
||||
for (const auto& element : elements) {
|
||||
output << "\"" << element.name.toString() << "\", ";
|
||||
}
|
||||
output << "}";
|
||||
return output.str();
|
||||
}
|
||||
|
||||
bool matchStringsWithoutClause(std::string first, std::string second, std::string regex)
|
||||
{
|
||||
first = std::regex_replace(first, std::regex(regex), "");
|
||||
second = std::regex_replace(second, std::regex(regex), "");
|
||||
return first == second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the elementMap in a shape contains all the names in a list
|
||||
* The "Duplicate" clause in a name - ";Dnnn" can contain a random number, so we need to
|
||||
* exclude those.
|
||||
* @param shape The Shape
|
||||
* @param names The vector of names
|
||||
* @return An assertion usable by the gtest framework
|
||||
*/
|
||||
testing::AssertionResult elementsMatch(const TopoShape& shape,
|
||||
const std::vector<std::string>& names)
|
||||
{
|
||||
@@ -147,16 +174,12 @@ testing::AssertionResult elementsMatch(const TopoShape& shape,
|
||||
names.begin(),
|
||||
names.end(),
|
||||
[&](const Data::MappedElement& element, const std::string& name) {
|
||||
return element.name.toString() == name;
|
||||
return matchStringsWithoutClause(element.name.toString(),
|
||||
name,
|
||||
";D[a-fA-F0-9]+");
|
||||
})
|
||||
== elements.end()) {
|
||||
std::stringstream output;
|
||||
output << "{";
|
||||
for (const auto& element : elements) {
|
||||
output << "\"" << element.name.toString() << "\", ";
|
||||
}
|
||||
output << "}";
|
||||
return testing::AssertionFailure() << output.str();
|
||||
return testing::AssertionFailure() << mappedElementVectorToString(elements);
|
||||
}
|
||||
}
|
||||
return testing::AssertionSuccess();
|
||||
@@ -168,7 +191,8 @@ testing::AssertionResult allElementsMatch(const TopoShape& shape,
|
||||
auto elements = shape.getElementMap();
|
||||
if (elements.size() != names.size()) {
|
||||
return testing::AssertionFailure()
|
||||
<< elements.size() << " != " << names.size() << " elements in map";
|
||||
<< elements.size() << " != " << names.size()
|
||||
<< " elements: " << mappedElementVectorToString(elements);
|
||||
}
|
||||
return elementsMatch(shape, names);
|
||||
}
|
||||
|
||||
@@ -1523,7 +1523,6 @@ TEST_F(TopoShapeExpansionTest, makeElementThickSolid)
|
||||
EXPECT_EQ(elements[IndexedName("Edge", 1)], MappedName("Edge11;THK;:H1:4,E"));
|
||||
}
|
||||
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementGeneralFuse)
|
||||
{
|
||||
// Arrange
|
||||
@@ -1860,19 +1859,19 @@ TEST_F(TopoShapeExpansionTest, makeElementSlice)
|
||||
EXPECT_EQ(TopAbs_ShapeEnum::TopAbs_WIRE, result.getShape().ShapeType());
|
||||
// Assert that we're creating a correct element map
|
||||
EXPECT_TRUE(result.getMappedChildElements().empty());
|
||||
EXPECT_TRUE(allElementsMatch(result,
|
||||
{
|
||||
"Edge1;SLC;D1;MAK",
|
||||
"Edge1;SLC;D2;MAK",
|
||||
"Edge1;SLC;D3;MAK",
|
||||
"Edge1;SLC;MAK",
|
||||
"Vertex1;SLC;D1;MAK",
|
||||
"Vertex1;SLC;D2;MAK",
|
||||
"Vertex1;SLC;MAK",
|
||||
"Vertex2;SLC;D1;MAK",
|
||||
"Vertex2;SLC;D2;MAK",
|
||||
"Vertex2;SLC;MAK",
|
||||
}));
|
||||
EXPECT_TRUE(elementsMatch(result,
|
||||
{
|
||||
"Edge1;SLC;D1;MAK",
|
||||
"Edge1;SLC;D2;MAK",
|
||||
"Edge1;SLC;D3;MAK",
|
||||
"Edge1;SLC;MAK",
|
||||
"Vertex1;SLC;D1;MAK",
|
||||
"Vertex1;SLC;D2;MAK",
|
||||
"Vertex1;SLC;MAK",
|
||||
"Vertex2;SLC;D1;MAK",
|
||||
"Vertex2;SLC;D2;MAK",
|
||||
"Vertex2;SLC;MAK",
|
||||
}));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementSlices)
|
||||
@@ -1954,4 +1953,99 @@ TEST_F(TopoShapeExpansionTest, makeElementMirror)
|
||||
"Vertex7;:M;MIR;:H1:7,V", "Vertex8;:M;MIR;:H1:7,V"}));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementTransformWithoutMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = CreateTwoCubes();
|
||||
auto tr {gp_Trsf()};
|
||||
tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0)));
|
||||
TopoShape topoShape1 {cube1, 1L};
|
||||
// Act
|
||||
TopoShape& result = topoShape1.makeElementTransform(topoShape1, tr);
|
||||
auto elements = elementMap(result);
|
||||
Base::BoundBox3d bb = result.getBoundBox();
|
||||
// Assert shape is correct
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -0.5, 0.0, 0.5, 0.5, 1.0)));
|
||||
EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1);
|
||||
// Assert elementMap is correct
|
||||
EXPECT_EQ(elements.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementTransformWithMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = CreateTwoCubes();
|
||||
auto tr {gp_Trsf()};
|
||||
tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0)));
|
||||
cube2.Move(TopLoc_Location(tr));
|
||||
TopoShape topoShape1 {cube1, 1L};
|
||||
TopoShape topoShape2 {cube2, 2L};
|
||||
// Act
|
||||
TopoShape& result = topoShape1.makeElementFuse({topoShape1, topoShape2}); // op, tolerance
|
||||
topoShape1.makeElementTransform(result, tr);
|
||||
auto elements = elementMap(result);
|
||||
Base::BoundBox3d bb = result.getBoundBox();
|
||||
// Assert shape is correct
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -1.0, 0.0, 1.0, 0.5, 1.0)));
|
||||
EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1.75);
|
||||
// Assert elementMap is correct
|
||||
EXPECT_EQ(elements.size(), 66);
|
||||
EXPECT_EQ(elements.count(IndexedName("Face", 1)), 1);
|
||||
EXPECT_EQ(
|
||||
elements[IndexedName("Face", 1)],
|
||||
MappedName(
|
||||
"Face3;:M;FUS;:H1:7,F;:U;FUS;:H1:7,E;:L(Face5;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E|Face5;:M;"
|
||||
"FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;FUS;:H1:7,V;:L(Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;"
|
||||
"FUS;:H1:7,V);FUS;:H1:3c,E|Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E);FUS;:H1:cb,F"));
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementGTransformWithoutMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = CreateTwoCubes();
|
||||
auto tr {gp_Trsf()};
|
||||
tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0)));
|
||||
TopoShape topoShape1 {cube1, 1L};
|
||||
// Act
|
||||
TopoShape& result = topoShape1.makeElementGTransform(topoShape1, TopoShape::convert(tr));
|
||||
auto elements = elementMap(result);
|
||||
Base::BoundBox3d bb = result.getBoundBox();
|
||||
// Assert shape is correct
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -0.5, 0.0, 0.5, 0.5, 1.0)));
|
||||
EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1);
|
||||
// Assert elementMap is correct
|
||||
EXPECT_EQ(elements.size(), 0);
|
||||
}
|
||||
|
||||
TEST_F(TopoShapeExpansionTest, makeElementGTransformWithMap)
|
||||
{
|
||||
// Arrange
|
||||
auto [cube1, cube2] = CreateTwoCubes();
|
||||
auto tr {gp_Trsf()};
|
||||
tr.SetTranslation(gp_Vec(gp_XYZ(-0.5, -0.5, 0)));
|
||||
cube2.Move(TopLoc_Location(tr));
|
||||
TopoShape topoShape1 {cube1, 1L};
|
||||
TopoShape topoShape2 {cube2, 2L};
|
||||
// Act
|
||||
TopoShape& result = topoShape1.makeElementFuse({topoShape1, topoShape2}); // op, tolerance
|
||||
topoShape1.makeElementGTransform(result, TopoShape::convert(tr));
|
||||
auto elements = elementMap(result);
|
||||
Base::BoundBox3d bb = result.getBoundBox();
|
||||
// Assert shape is correct
|
||||
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(-0.5, -1.0, 0.0, 1.0, 0.5, 1.0)));
|
||||
EXPECT_FLOAT_EQ(getVolume(result.getShape()), 1.75);
|
||||
// Assert elementMap is correct
|
||||
EXPECT_EQ(elements.size(), 66);
|
||||
EXPECT_EQ(elements.count(IndexedName("Face", 1)), 1);
|
||||
EXPECT_EQ(
|
||||
elements[IndexedName("Face", 1)],
|
||||
MappedName(
|
||||
"Face3;:M;FUS;:H1:7,F;:U;FUS;:H1:7,E;:L(Face5;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E|Face5;:M;"
|
||||
"FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;FUS;:H1:7,V;:L(Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E;:U;"
|
||||
"FUS;:H1:7,V);FUS;:H1:3c,E|Face6;:M;FUS;:H1:7,F;:U2;FUS;:H1:8,E);FUS;:H1:cb,F"));
|
||||
}
|
||||
|
||||
// Not testing _makeElementTransform as it is a thin wrapper that calls the same places as the four
|
||||
// preceding tests.
|
||||
|
||||
// NOLINTEND(readability-magic-numbers,cppcoreguidelines-avoid-magic-numbers)
|
||||
|
||||
@@ -48,6 +48,6 @@ TEST_F(FeaturePartMakeElementRefineTest, makeElementRefineBoxes)
|
||||
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
|
||||
// TODO: 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user