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)
|
||||
|
||||
|
||||
@@ -222,26 +222,26 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent)
|
||||
ui->wedgeZ2max->bind(getObject<PartDesign::Wedge>()->Z2max);
|
||||
ui->wedgeZ2min->setValue(getObject<PartDesign::Wedge>()->Z2min.getValue());
|
||||
ui->wedgeZ2min->bind(getObject<PartDesign::Wedge>()->Z2min);
|
||||
ui->wedgeXmin->setMinimum(INT_MIN);
|
||||
ui->wedgeXmin->setMinimum(std::numeric_limits<int>::min());
|
||||
ui->wedgeXmin->setMaximum(ui->wedgeXmax->rawValue()); // must be < than wedgeXmax
|
||||
ui->wedgeYmin->setMinimum(INT_MIN);
|
||||
ui->wedgeYmin->setMinimum(std::numeric_limits<int>::min());
|
||||
ui->wedgeYmin->setMaximum(ui->wedgeYmax->rawValue()); // must be < than wedgeYmax
|
||||
ui->wedgeZmin->setMinimum(INT_MIN);
|
||||
ui->wedgeZmin->setMinimum(std::numeric_limits<int>::min());
|
||||
ui->wedgeZmin->setMaximum(ui->wedgeZmax->rawValue()); // must be < than wedgeZmax
|
||||
ui->wedgeX2min->setMinimum(INT_MIN);
|
||||
ui->wedgeX2min->setMinimum(std::numeric_limits<int>::min());;
|
||||
ui->wedgeX2min->setMaximum(ui->wedgeX2max->rawValue()); // must be <= than wedgeXmax
|
||||
ui->wedgeZ2min->setMinimum(INT_MIN);
|
||||
ui->wedgeZ2min->setMinimum(std::numeric_limits<int>::min());;
|
||||
ui->wedgeZ2min->setMaximum(ui->wedgeZ2max->rawValue()); // must be <= than wedgeXmax
|
||||
ui->wedgeXmax->setMinimum(ui->wedgeXmin->rawValue());
|
||||
ui->wedgeXmax->setMaximum(INT_MAX);
|
||||
ui->wedgeXmax->setMaximum(std::numeric_limits<int>::max());
|
||||
ui->wedgeYmax->setMinimum(ui->wedgeYmin->rawValue());
|
||||
ui->wedgeYmax->setMaximum(INT_MAX);
|
||||
ui->wedgeYmax->setMaximum(std::numeric_limits<int>::max());
|
||||
ui->wedgeZmax->setMinimum(ui->wedgeZmin->rawValue());
|
||||
ui->wedgeZmax->setMaximum(INT_MAX);
|
||||
ui->wedgeZmax->setMaximum(std::numeric_limits<int>::max());
|
||||
ui->wedgeX2max->setMinimum(ui->wedgeX2min->rawValue());
|
||||
ui->wedgeX2max->setMaximum(INT_MAX);
|
||||
ui->wedgeX2max->setMaximum(std::numeric_limits<int>::max());
|
||||
ui->wedgeZ2max->setMinimum(ui->wedgeZ2min->rawValue());
|
||||
ui->wedgeZ2max->setMaximum(INT_MAX);
|
||||
ui->wedgeZ2max->setMaximum(std::numeric_limits<int>::max());
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,7 +78,7 @@ void TaskScaledParameters::setupParameterUI(QWidget* widget)
|
||||
auto pcScaled = getObject<PartDesign::Scaled>();
|
||||
|
||||
ui->spinFactor->bind(pcScaled->Factor);
|
||||
ui->spinOccurrences->setMaximum(INT_MAX);
|
||||
ui->spinOccurrences->setMaximum(std::numeric_limits<int>::max());
|
||||
ui->spinOccurrences->bind(pcScaled->Occurrences);
|
||||
ui->spinFactor->setEnabled(true);
|
||||
ui->spinOccurrences->setEnabled(true);
|
||||
|
||||
@@ -327,7 +327,7 @@ void fixSketchSupport (Sketcher::SketchObject* sketch)
|
||||
// Offset to base plane
|
||||
// Find out which direction we need to offset
|
||||
double a = sketchVector.GetAngle(pnt);
|
||||
if ((a < -M_PI_2) || (a > M_PI_2))
|
||||
if ((a < -std::numbers::pi/2) || (a > std::numbers::pi/2))
|
||||
offset *= -1.0;
|
||||
|
||||
std::string Datum = doc->getUniqueObjectName("DatumPlane");
|
||||
|
||||
@@ -121,7 +121,7 @@ void ViewProviderAddSub::updateAddSubShapeIndicator() {
|
||||
Standard_Real deflection = ((xMax-xMin)+(yMax-yMin)+(zMax-zMin))/300.0 * Deviation.getValue();
|
||||
|
||||
// create or use the mesh on the data structure
|
||||
Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * M_PI;
|
||||
Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * std::numbers::pi;
|
||||
BRepMesh_IncrementalMesh(cShape, deflection, Standard_False, AngDeflectionRads, Standard_True);
|
||||
|
||||
// We must reset the location here because the transformation data
|
||||
|
||||
@@ -45,8 +45,10 @@ using namespace PartDesignGui;
|
||||
|
||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderDatumCoordinateSystem,PartDesignGui::ViewProviderDatum)
|
||||
|
||||
const App::PropertyFloatConstraint::Constraints ZoomConstraint = {0.0,DBL_MAX,0.2};
|
||||
const App::PropertyIntegerConstraint::Constraints FontConstraint = {1,INT_MAX,1};
|
||||
const App::PropertyFloatConstraint::Constraints ZoomConstraint = {
|
||||
0.0, std::numeric_limits<double>::max(), 0.2};
|
||||
const App::PropertyIntegerConstraint::Constraints FontConstraint = {
|
||||
1,std::numeric_limits<int>::max(), 1};
|
||||
|
||||
ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem()
|
||||
{
|
||||
|
||||
@@ -228,7 +228,7 @@ void ViewProviderTransformed::showRejectedShape(TopoDS_Shape shape)
|
||||
|
||||
// create or use the mesh on the data structure
|
||||
// Note: This DOES have an effect on shape
|
||||
Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * M_PI;
|
||||
Standard_Real AngDeflectionRads = AngularDeflection.getValue() / 180.0 * std::numbers::pi;
|
||||
BRepMesh_IncrementalMesh(shape, deflection, Standard_False, AngDeflectionRads, Standard_True);
|
||||
|
||||
// We must reset the location here because the transformation data
|
||||
|
||||
Reference in New Issue
Block a user