Part: Use std::numeric_limits and std::numbers instead of defines

This commit is contained in:
Benjamin Nauck
2025-03-27 19:01:46 +01:00
parent 9086f0ff14
commit aad5e58955
38 changed files with 259 additions and 247 deletions

View File

@@ -172,7 +172,7 @@ TEST_F(FeatureExtrusionTest, testExecuteAngled)
{
// Arrange
const double ang = 30;
const double tangent = tan(ang / 180.0 * M_PI);
const double tangent = tan(ang / 180.0 * std::numbers::pi);
// The shape is a truncated pyramid elongated by a truncated triangular prism in the middle.
// Calc the volume of full size pyramid and prism, and subtract top volumes to truncate.
@@ -209,7 +209,7 @@ TEST_F(FeatureExtrusionTest, testExecuteAngledRev)
{
// Arrange
const double ang = 30;
const double tangent = tan(ang / 180.0 * M_PI);
const double tangent = tan(ang / 180.0 * std::numbers::pi);
// The shape is a truncated pyramid elongated by a truncated triangular prism in the middle,
// plus a rectangular prism.
// Calc the volume of full size pyramid and prism, and subtract top volumes to truncate.
@@ -249,7 +249,7 @@ TEST_F(FeatureExtrusionTest, testExecuteEdge)
{
// Arrange
const double ang = 30;
const double tangent = tan(ang / 180.0 * M_PI);
const double tangent = tan(ang / 180.0 * std::numbers::pi);
BRepBuilderAPI_MakeEdge e1(gp_Pnt(0, 0, 0), gp_Pnt(ext1, ext1, ext1));
auto edge = _doc->addObject<Part::Feature>("Edge");
edge->Shape.setValue(e1);
@@ -270,7 +270,7 @@ TEST_F(FeatureExtrusionTest, testExecuteEdge)
TEST_F(FeatureExtrusionTest, testExecuteDir)
{
// Arrange
const double sin45 = sin(45 / 180.0 * M_PI);
const double sin45 = sin(45 / 180.0 * std::numbers::pi);
_extrusion->Dir.setValue(Base::Vector3d(0, 1, 1));
_extrusion->DirMode.setValue((long)0);
// Act
@@ -319,8 +319,10 @@ TEST_F(FeatureExtrusionTest, testFaceWithHoles)
double volume = PartTestHelpers::getVolume(ts.getShape());
Base::BoundBox3d bb = ts.getBoundBox();
// Assert
EXPECT_FLOAT_EQ(volume, len * wid * ext1 - radius * radius * M_PI * ext1);
EXPECT_FLOAT_EQ(volume, len * wid * ext1 - radius * radius * std::numbers::pi * ext1);
EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0, 0, 0, len, wid, ext1)));
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face1), len * wid + radius * radius * M_PI);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face2), len * wid - radius * radius * M_PI);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face1),
len * wid + radius * radius * std::numbers::pi);
EXPECT_FLOAT_EQ(PartTestHelpers::getArea(face2),
len * wid - radius * radius * std::numbers::pi);
}

View File

@@ -46,7 +46,7 @@ protected:
TEST_F(FeatureRevolutionTest, testExecute)
{
// Arrange
double puckVolume = len * len * M_PI * wid; // Area is PIr2; apply height
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2; apply height
// Act
_revolution->execute();
Part::TopoShape ts = _revolution->Shape.getValue();
@@ -62,8 +62,8 @@ TEST_F(FeatureRevolutionTest, testExecuteBase)
// Arrange
double rad = len + 1.0;
double rad2 = 1.0;
double outerPuckVolume = rad * rad * M_PI * wid; // Area is PIr2; apply height
double innerPuckVolume = rad2 * rad2 * M_PI * wid; // Area is PIr2; apply height
double outerPuckVolume = rad * rad * std::numbers::pi * wid; // Area is PIr2; apply height
double innerPuckVolume = rad2 * rad2 * std::numbers::pi * wid; // Area is PIr2; apply height
_revolution->Base.setValue(Base::Vector3d(len + 1, 0, 0));
// Act
_revolution->execute();
@@ -79,7 +79,7 @@ TEST_F(FeatureRevolutionTest, testExecuteBase)
TEST_F(FeatureRevolutionTest, testAxis)
{
// Arrange
double puckVolume = wid * wid * M_PI * len; // Area is PIr2 times height
double puckVolume = wid * wid * std::numbers::pi * len; // Area is PIr2 times height
_revolution->Axis.setValue(Base::Vector3d(1, 0, 0));
// Act
_revolution->execute();
@@ -98,7 +98,7 @@ TEST_F(FeatureRevolutionTest, testAxisLink)
auto edge = _doc->addObject<Part::Feature>("Edge");
edge->Shape.setValue(e1);
_revolution->AxisLink.setValue(edge);
// double puckVolume = wid * wid * M_PI * len; // Area is PIr2; apply height
// double puckVolume = wid * wid * std::numbers::pi * len; // Area is PIr2; apply height
// Act
_revolution->execute();
Part::TopoShape ts = _revolution->Shape.getValue();
@@ -115,7 +115,7 @@ TEST_F(FeatureRevolutionTest, testAxisLink)
TEST_F(FeatureRevolutionTest, testSymmetric)
{
// Arrange
double puckVolume = len * len * M_PI * wid; // Area is PIr2 times height
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2 times height
_revolution->Symmetric.setValue(true);
// Act
_revolution->execute();
@@ -130,8 +130,8 @@ TEST_F(FeatureRevolutionTest, testSymmetric)
TEST_F(FeatureRevolutionTest, testAngle)
{
// Arrange
double puckVolume = len * len * M_PI * wid; // Area is PIr2 times height
_revolution->Angle.setValue(90); // NOLINT magic number
double puckVolume = len * len * std::numbers::pi * wid; // Area is PIr2 times height
_revolution->Angle.setValue(90); // NOLINT magic number
// Act
_revolution->execute();
Part::TopoShape ts = _revolution->Shape.getValue();

View File

@@ -608,10 +608,10 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceNull)
double area3 = getArea(topoShape.getShape());
// Assert
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid - M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid - std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
}
@@ -632,8 +632,8 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceSimple)
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid);
EXPECT_DOUBLE_EQ(area3, Len * Wid);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
@@ -656,8 +656,8 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceParams)
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid);
EXPECT_DOUBLE_EQ(area3, Len * Wid);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
@@ -680,10 +680,10 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceFromFace)
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid - M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, Len * Wid - M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid - std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, Len * Wid - std::numbers::pi * Rad * Rad);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
}
@@ -705,8 +705,8 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceOpenWire)
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, 0); // Len * Wid - M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, 0); // Len * Wid - std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, Len * Wid);
EXPECT_DOUBLE_EQ(area3, Len * Wid);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
@@ -730,10 +730,10 @@ TEST_F(TopoShapeExpansionTest, makeElementFaceClosedWire)
// Assert
EXPECT_TRUE(newFace.getShape().IsEqual(topoShape.getShape())); // topoShape was altered
EXPECT_FALSE(face1.IsEqual(newFace.getShape()));
EXPECT_DOUBLE_EQ(area, Len * Wid + M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, 0); // Len * Wid - M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, M_PI * Rad * Rad);
EXPECT_DOUBLE_EQ(area, Len * Wid + std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area1, 0); // Len * Wid - std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area2, std::numbers::pi * Rad * Rad);
EXPECT_DOUBLE_EQ(area3, std::numbers::pi * Rad * Rad);
EXPECT_STREQ(newFace.shapeName().c_str(), "Face");
}
@@ -837,7 +837,7 @@ TEST_F(TopoShapeExpansionTest, splitWires)
// Assert
EXPECT_EQ(inner.size(), 1);
EXPECT_DOUBLE_EQ(getLength(wire.getShape()), 2 + 2 + 3 + 3);
EXPECT_DOUBLE_EQ(getLength(inner.front().getShape()), M_PI * Rad * 2);
EXPECT_DOUBLE_EQ(getLength(inner.front().getShape()), std::numbers::pi * Rad * 2);
EXPECT_EQ(wire.getShape().Orientation(), TopAbs_REVERSED);
for (TopoShape& shape : inner) {
EXPECT_EQ(shape.getShape().Orientation(), TopAbs_FORWARD);
@@ -1284,7 +1284,7 @@ TEST_F(TopoShapeExpansionTest, makeElementShellOpen)
const float Wid = 2;
auto [face1, wire1, edge1, edge2, edge3, edge4] = CreateRectFace(Len, Wid);
auto transform {gp_Trsf()};
transform.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), M_PI / 2);
transform.SetRotation(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(1, 0, 0)), std::numbers::pi / 2);
auto face2 = face1; // Shallow copy
face2.Move(TopLoc_Location(transform));
TopoDS_Compound compound1;
@@ -1562,7 +1562,7 @@ TEST_F(TopoShapeExpansionTest, makeElementDraft)
std::vector<TopoShape> subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE);
std::vector<TopoShape> faces {subShapes[0], subShapes[1], subShapes[2], subShapes[3]};
const gp_Dir pullDirection {0, 0, 1};
double angle {M_PI * 10
double angle {std::numbers::pi * 10
/ 8}; // Angle should be between Pi and Pi * 1.5 ( 180 and 270 degrees )
const gp_Pln plane {};
// Act
@@ -1580,7 +1580,7 @@ TEST_F(TopoShapeExpansionTest, makeElementDraftTopoShapes)
// Arrange
auto [cube1TS, cube2TS] = CreateTwoTopoShapeCubes();
const gp_Dir pullDirection {0, 0, 1};
double angle {M_PI * 10
double angle {std::numbers::pi * 10
/ 8}; // Angle should be between Pi and Pi * 1.5 ( 180 and 270 degrees )
const gp_Pln plane {};
// Act