PartDesign: Use std::numeric_limits and std::numbers instead of defines
This commit is contained in:
@@ -35,6 +35,8 @@
|
||||
# include <Standard_Version.hxx>
|
||||
#endif
|
||||
|
||||
#include <limits>
|
||||
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Reader.h>
|
||||
#include <Base/Tools.h>
|
||||
@@ -49,7 +51,7 @@ using namespace PartDesign;
|
||||
PROPERTY_SOURCE(PartDesign::Chamfer, PartDesign::DressUp)
|
||||
|
||||
const char* ChamferTypeEnums[] = {"Equal distance", "Two distances", "Distance and Angle", nullptr};
|
||||
const App::PropertyQuantityConstraint::Constraints Chamfer::floatSize = {0.0, FLT_MAX, 0.1};
|
||||
const App::PropertyQuantityConstraint::Constraints Chamfer::floatSize = {0.0, std::numeric_limits<float>::max(), 0.1};
|
||||
const App::PropertyAngle::Constraints Chamfer::floatAngle = {0.0, 180.0, 1.0};
|
||||
|
||||
static App::DocumentObjectExecReturn *validateParameters(int chamferType, double size, double size2, double angle);
|
||||
|
||||
@@ -244,7 +244,7 @@ App::DocumentObjectExecReturn *Draft::execute()
|
||||
if (c.GetType() != GeomAbs_Line)
|
||||
throw Base::TypeError("Neutral plane reference edge must be linear");
|
||||
double a = c.Line().Angle(gp_Lin(c.Value(c.FirstParameter()), pullDirection));
|
||||
if (std::fabs(a - M_PI_2) > Precision::Confusion())
|
||||
if (std::fabs(a - std::numbers::pi/2) > Precision::Confusion())
|
||||
throw Base::ValueError("Neutral plane reference edge must be normal to pull direction");
|
||||
neutralPlane = gp_Pln(c.Value(c.FirstParameter()), pullDirection);
|
||||
} else {
|
||||
|
||||
@@ -50,7 +50,8 @@ using namespace PartDesign;
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::FeatureExtrude, PartDesign::ProfileBased)
|
||||
|
||||
App::PropertyQuantityConstraint::Constraints FeatureExtrude::signedLengthConstraint = { -DBL_MAX, DBL_MAX, 1.0 };
|
||||
App::PropertyQuantityConstraint::Constraints FeatureExtrude::signedLengthConstraint = {
|
||||
-std::numeric_limits<double>::max(), std::numeric_limits<double>::max(), 1.0 };
|
||||
double FeatureExtrude::maxAngle = 90 - Base::toDegrees<double>(Precision::Angular());
|
||||
App::PropertyAngle::Constraints FeatureExtrude::floatAngle = { -maxAngle, maxAngle, 1.0 };
|
||||
|
||||
@@ -714,11 +715,13 @@ App::DocumentObjectExecReturn* FeatureExtrude::buildExtrusion(ExtrudeOptions opt
|
||||
}
|
||||
}
|
||||
else {
|
||||
using std::numbers::pi;
|
||||
|
||||
Part::ExtrusionParameters params;
|
||||
params.dir = dir;
|
||||
params.solid = makeface;
|
||||
params.taperAngleFwd = this->TaperAngle.getValue() * M_PI / 180.0;
|
||||
params.taperAngleRev = this->TaperAngle2.getValue() * M_PI / 180.0;
|
||||
params.taperAngleFwd = this->TaperAngle.getValue() * pi / 180.0;
|
||||
params.taperAngleRev = this->TaperAngle2.getValue() * pi / 180.0;
|
||||
if (L2 == 0.0 && Midplane.getValue()) {
|
||||
params.lengthFwd = L / 2;
|
||||
params.lengthRev = L / 2;
|
||||
@@ -732,8 +735,8 @@ App::DocumentObjectExecReturn* FeatureExtrude::buildExtrusion(ExtrudeOptions opt
|
||||
}
|
||||
if (std::fabs(params.taperAngleFwd) >= Precision::Angular()
|
||||
|| std::fabs(params.taperAngleRev) >= Precision::Angular()) {
|
||||
if (fabs(params.taperAngleFwd) > M_PI * 0.5 - Precision::Angular()
|
||||
|| fabs(params.taperAngleRev) > M_PI * 0.5 - Precision::Angular()) {
|
||||
if (fabs(params.taperAngleFwd) > pi * 0.5 - Precision::Angular()
|
||||
|| fabs(params.taperAngleRev) > pi * 0.5 - Precision::Angular()) {
|
||||
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP(
|
||||
"Exception",
|
||||
"Magnitude of taper angle matches or exceeds 90 degrees"));
|
||||
|
||||
@@ -44,7 +44,7 @@ using namespace PartDesign;
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::Fillet, PartDesign::DressUp)
|
||||
|
||||
const App::PropertyQuantityConstraint::Constraints floatRadius = {0.0,FLT_MAX,0.1};
|
||||
const App::PropertyQuantityConstraint::Constraints floatRadius = {0.0, std::numeric_limits<float>::max(), 0.1};
|
||||
|
||||
Fillet::Fillet()
|
||||
{
|
||||
|
||||
@@ -270,7 +270,7 @@ void Groove::generateRevolution(TopoDS_Shape& revol,
|
||||
angleOffset = angle2 * -1.0;
|
||||
}
|
||||
else if (method == RevolMethod::ThroughAll) {
|
||||
angleTotal = 2 * M_PI;
|
||||
angleTotal = 2 * std::numbers::pi;
|
||||
}
|
||||
else if (midplane) {
|
||||
// Rotate the face by half the angle to get Groove symmetric to sketch plane
|
||||
|
||||
@@ -61,8 +61,8 @@ const char* Helix::ModeEnums[] = { "pitch-height-angle", "pitch-turns-angle", "h
|
||||
PROPERTY_SOURCE(PartDesign::Helix, PartDesign::ProfileBased)
|
||||
|
||||
// we purposely use not FLT_MAX because this would not be computable
|
||||
const App::PropertyFloatConstraint::Constraints Helix::floatTurns = { Precision::Confusion(), INT_MAX, 1.0 };
|
||||
const App::PropertyFloatConstraint::Constraints Helix::floatTolerance = { 0.1, INT_MAX, 1.0 };
|
||||
const App::PropertyFloatConstraint::Constraints Helix::floatTurns = { Precision::Confusion(), std::numeric_limits<int>::max(), 1.0 };
|
||||
const App::PropertyFloatConstraint::Constraints Helix::floatTolerance = { 0.1, std::numeric_limits<int>::max(), 1.0 };
|
||||
const App::PropertyAngle::Constraints Helix::floatAngle = { -89.0, 89.0, 1.0 };
|
||||
|
||||
Helix::Helix()
|
||||
@@ -442,13 +442,13 @@ TopoDS_Shape Helix::generateHelixPath(double breakAtTurn)
|
||||
// because of the radius factor we used above, we must reverse after the
|
||||
// startOffset movement (that brings the path back to the desired position)
|
||||
if (reversed) {
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), M_PI);
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), std::numbers::pi);
|
||||
TopLoc_Location loc(mov);
|
||||
path.Move(loc);
|
||||
}
|
||||
|
||||
if (turned) { // turn the helix so that the starting point aligns with the profile
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis1), M_PI);
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis1), std::numbers::pi);
|
||||
TopLoc_Location loc(mov);
|
||||
path.Move(loc);
|
||||
}
|
||||
@@ -495,7 +495,7 @@ double Helix::safePitch()
|
||||
}
|
||||
}
|
||||
|
||||
double angle = Angle.getValue() / 180.0 * M_PI;
|
||||
double angle = Angle.getValue() / 180.0 * std::numbers::pi;
|
||||
gp_Dir direction(axisVec.x, axisVec.y, axisVec.z);
|
||||
gp_Dir directionStart(startVec.x, startVec.y, startVec.z);
|
||||
TopoDS_Shape sketchshape = getVerifiedFace();
|
||||
|
||||
@@ -732,7 +732,7 @@ PROPERTY_SOURCE(PartDesign::Hole, PartDesign::ProfileBased)
|
||||
|
||||
const App::PropertyAngle::Constraints Hole::floatAngle = { Base::toDegrees<double>(Precision::Angular()), 180.0 - Base::toDegrees<double>(Precision::Angular()), 1.0 };
|
||||
// OCC can only create holes with a min diameter of 10 times the Precision::Confusion()
|
||||
const App::PropertyQuantityConstraint::Constraints diameterRange = { 10 * Precision::Confusion(), FLT_MAX, 1.0 };
|
||||
const App::PropertyQuantityConstraint::Constraints diameterRange = { 10 * Precision::Confusion(), std::numeric_limits<float>::max(), 1.0 };
|
||||
|
||||
Hole::Hole()
|
||||
{
|
||||
@@ -2244,7 +2244,7 @@ TopoDS_Shape Hole::makeThread(const gp_Vec& xDir, const gp_Vec& zDir, double len
|
||||
// | base-sharpV Rmaj H
|
||||
|
||||
// the little adjustment of p1 and p4 is here to prevent coincidencies
|
||||
double marginX = std::tan(62.5 * M_PI / 180.0) * marginZ;
|
||||
double marginX = std::tan(62.5 * std::numbers::pi / 180.0) * marginZ;
|
||||
|
||||
gp_Pnt p1 = toPnt(
|
||||
(RmajC - 5 * H / 6 + marginX) * xDir
|
||||
@@ -2281,7 +2281,7 @@ TopoDS_Shape Hole::makeThread(const gp_Vec& xDir, const gp_Vec& zDir, double len
|
||||
// | base-sharpV Rmaj
|
||||
|
||||
// the little adjustment of p1 and p4 is here to prevent coincidencies
|
||||
double marginX = std::tan(60.0 * M_PI / 180.0) * marginZ;
|
||||
double marginX = std::tan(60.0 * std::numbers::pi / 180.0) * marginZ;
|
||||
gp_Pnt p1 = toPnt(
|
||||
(RmajC - h + marginX) * xDir
|
||||
+ marginZ * zDir
|
||||
@@ -2343,7 +2343,7 @@ TopoDS_Shape Hole::makeThread(const gp_Vec& xDir, const gp_Vec& zDir, double len
|
||||
|
||||
// Reverse the direction of the helix. So that it goes into the material
|
||||
gp_Trsf mov;
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), M_PI);
|
||||
mov.SetRotation(gp_Ax1(origo, dir_axis2), std::numbers::pi);
|
||||
TopLoc_Location loc1(mov);
|
||||
helix.Move(loc1);
|
||||
|
||||
|
||||
@@ -49,7 +49,8 @@ namespace PartDesign {
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::LinearPattern, PartDesign::Transformed)
|
||||
|
||||
const App::PropertyIntegerConstraint::Constraints LinearPattern::intOccurrences = { 1, INT_MAX, 1 };
|
||||
const App::PropertyIntegerConstraint::Constraints LinearPattern::intOccurrences = {
|
||||
1, std::numeric_limits<int>::max(), 1 };
|
||||
|
||||
const char* LinearPattern::ModeEnums[] = { "length", "offset", nullptr };
|
||||
|
||||
|
||||
@@ -48,7 +48,8 @@ namespace PartDesign {
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::PolarPattern, PartDesign::Transformed)
|
||||
|
||||
const App::PropertyIntegerConstraint::Constraints PolarPattern::intOccurrences = { 1, INT_MAX, 1 };
|
||||
const App::PropertyIntegerConstraint::Constraints PolarPattern::intOccurrences = {
|
||||
1, std::numeric_limits<int>::max(), 1 };
|
||||
const App::PropertyAngle::Constraints PolarPattern::floatAngle = { Base::toDegrees<double>(Precision::Angular()), 360.0, 1.0 };
|
||||
|
||||
const char* PolarPattern::ModeEnums[] = {"angle", "offset", nullptr};
|
||||
|
||||
@@ -56,8 +56,8 @@ const App::PropertyQuantityConstraint::Constraints angleRangeU = { 0.0, 360.0, 1
|
||||
const App::PropertyQuantityConstraint::Constraints angleRangeV = { -90.0, 90.0, 1.0 };
|
||||
// it turned out that OCC cannot e.g. create a box with a width of Precision::Confusion()
|
||||
// with two times Precision::Confusion() all geometric primitives can be created
|
||||
const App::PropertyQuantityConstraint::Constraints quantityRange = { 2 * Precision::Confusion(), FLT_MAX, 0.1 };
|
||||
const App::PropertyQuantityConstraint::Constraints quantityRangeZero = { 0.0, FLT_MAX, 0.1 };
|
||||
const App::PropertyQuantityConstraint::Constraints quantityRange = { 2 * Precision::Confusion(), std::numeric_limits<float>::max(), 0.1 };
|
||||
const App::PropertyQuantityConstraint::Constraints quantityRangeZero = { 0.0, std::numeric_limits<float>::max(), 0.1 };
|
||||
|
||||
PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesign::FeaturePrimitive, PartDesign::FeatureAddSub)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user