diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index f595277856..0d315ed859 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -33,10 +33,6 @@ #include "Datums.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - using namespace App; PROPERTY_SOURCE(App::DatumElement, App::GeoFeature) @@ -243,14 +239,16 @@ App::DocumentObjectExecReturn* LocalCoordinateSystem::execute() const std::vector& LocalCoordinateSystem::getSetupData() { + using std::numbers::pi; + static const std::vector setupData = { // clang-format off {App::Line::getClassTypeId(), AxisRoles[0], tr("X-axis"), Base::Rotation()}, - {App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)}, - {App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation(Base::Vector3d(1,-1, 1), M_PI * 2 / 3)}, + {App::Line::getClassTypeId(), AxisRoles[1], tr("Y-axis"), Base::Rotation(Base::Vector3d(1, 1, 1), pi * 2 / 3)}, + {App::Line::getClassTypeId(), AxisRoles[2], tr("Z-axis"), Base::Rotation(Base::Vector3d(1,-1, 1), pi * 2 / 3)}, {App::Plane::getClassTypeId(), PlaneRoles[0], tr("XY-plane"), Base::Rotation()}, {App::Plane::getClassTypeId(), PlaneRoles[1], tr("XZ-plane"), Base::Rotation(1.0, 0.0, 0.0, 1.0)}, - {App::Plane::getClassTypeId(), PlaneRoles[2], tr("YZ-plane"), Base::Rotation(Base::Vector3d(1, 1, 1), M_PI * 2 / 3)}, + {App::Plane::getClassTypeId(), PlaneRoles[2], tr("YZ-plane"), Base::Rotation(Base::Vector3d(1, 1, 1), pi * 2 / 3)}, {App::Point::getClassTypeId(), PointRoles[0], tr("Origin"), Base::Rotation()} // clang-format on }; diff --git a/src/App/Expression.cpp b/src/App/Expression.cpp index 9f16fdbf3a..a081b351d4 100644 --- a/src/App/Expression.cpp +++ b/src/App/Expression.cpp @@ -34,6 +34,8 @@ #include #include +#include +#include #include #include #include @@ -57,19 +59,6 @@ using namespace App; FC_LOG_LEVEL_INIT("Expression", true, true) -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif -#ifndef M_E -#define M_E 2.71828182845904523536 -#endif -#ifndef DOUBLE_MAX -# define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif -#ifndef DOUBLE_MIN -# define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif - #if defined(_MSC_VER) #define strtoll _strtoi64 #pragma warning(disable : 4003) @@ -331,22 +320,22 @@ static inline int essentiallyInteger(double a, long &l, int &i) { double intpart; if (std::modf(a,&intpart) == 0.0) { if (intpart<0.0) { - if (intpart >= INT_MIN) { + if (intpart >= std::numeric_limits::min()) { i = static_cast(intpart); l = i; return 1; } - if (intpart >= LONG_MIN) { + if (intpart >= std::numeric_limits::min()) { l = static_cast(intpart); return 2; } } - else if (intpart <= INT_MAX) { + else if (intpart <= std::numeric_limits::max()) { i = static_cast(intpart); l = i; return 1; } - else if (intpart <= static_cast(LONG_MAX)) { + else if (intpart <= static_cast(std::numeric_limits::max())) { l = static_cast(intpart); return 2; } @@ -358,12 +347,12 @@ static inline bool essentiallyInteger(double a, long &l) { double intpart; if (std::modf(a,&intpart) == 0.0) { if (intpart<0.0) { - if (intpart >= LONG_MIN) { + if (intpart >= std::numeric_limits::min()) { l = static_cast(intpart); return true; } } - else if (intpart <= static_cast(LONG_MAX)) { + else if (intpart <= static_cast(std::numeric_limits::max())) { l = static_cast(intpart); return true; } @@ -2145,6 +2134,8 @@ Base::Vector3d FunctionExpression::extractVectorArgument( Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std::vector &args) { + using std::numbers::pi; + if(!expr || !expr->getOwner()) _EXPR_THROW("Invalid owner.", expr); @@ -2181,7 +2172,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std Py::Object pyobj = args[0]->getPyValue(); if (PyObject_TypeCheck(pyobj.ptr(), &Base::MatrixPy::Type)) { auto m = static_cast(pyobj.ptr())->value(); - if (fabs(m.determinant()) <= DBL_EPSILON) + if (fabs(m.determinant()) <= std::numeric_limits::epsilon()) _EXPR_THROW("Cannot invert singular matrix.", expr); m.inverseGauss(); return Py::asObject(new Base::MatrixPy(m)); @@ -2222,7 +2213,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std Rotation rotation = Base::Rotation( Vector3d(static_cast(f == MROTATEX), static_cast(f == MROTATEY), static_cast(f == MROTATEZ)), - rotationAngle.getValue() * M_PI / 180.0); + rotationAngle.getValue() * pi / 180.0); Base::Matrix4D rotationMatrix; rotation.getValue(rotationMatrix); @@ -2361,7 +2352,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std switch (f) { case VANGLE: - return Py::asObject(new QuantityPy(new Quantity(vector1.GetAngle(vector2) * 180 / M_PI, Unit::Angle))); + return Py::asObject(new QuantityPy(new Quantity(vector1.GetAngle(vector2) * 180 / pi, Unit::Angle))); case VCROSS: return Py::asObject(new Base::VectorPy(vector1.Cross(vector2))); case VDOT: @@ -2420,7 +2411,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std _EXPR_THROW("Unit must be either empty or an angle.", expr); // Convert value to radians - value *= M_PI / 180.0; + value *= pi / 180.0; unit = Unit(); break; case ACOS: @@ -2429,7 +2420,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std if (!v1.isDimensionless()) _EXPR_THROW("Unit must be empty.", expr); unit = Unit::Angle; - scaler = 180.0 / M_PI; + scaler = 180.0 / pi; break; case EXP: case LOG: @@ -2461,7 +2452,7 @@ Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std if (v1.getUnit() != v2.getUnit()) _EXPR_THROW("Units must be equal.",expr); unit = Unit::Angle; - scaler = 180.0 / M_PI; + scaler = 180.0 / pi; break; case MOD: if (e2.isNone()) diff --git a/src/App/ExpressionParser.l b/src/App/ExpressionParser.l index 49e6e3672c..566dab95e0 100644 --- a/src/App/ExpressionParser.l +++ b/src/App/ExpressionParser.l @@ -341,15 +341,15 @@ EXPO [eE][-+]?[0-9]+ {DIGIT}+{EXPO} COUNTCHARS; yylval.fvalue = num_change(yytext,',','.'); return yylval.fvalue == 1 ? ONE : NUM; {DIGIT}+ { COUNTCHARS; yylval.ivalue = strtoll( yytext, NULL, 10 ); - if (yylval.ivalue == LLONG_MIN) + if (yylval.ivalue == std::numeric_limits::min()) throw Base::UnderflowError("Integer underflow"); - else if (yylval.ivalue == LLONG_MAX) + else if (yylval.ivalue == std::numeric_limits::max()) throw Base::OverflowError("Integer overflow"); if (yylval.ivalue == 1) { yylval.fvalue = 1; return ONE; } else return INTEGER; } -"pi" COUNTCHARS; yylval.constant.fvalue = M_PI; yylval.constant.name = "pi"; return CONSTANT; // constant pi -"e" COUNTCHARS; yylval.constant.fvalue = M_E; yylval.constant.name = "e"; return CONSTANT; // constant e +"pi" COUNTCHARS; yylval.constant.fvalue = std::numbers::pi; yylval.constant.name = "pi"; return CONSTANT; // constant pi +"e" COUNTCHARS; yylval.constant.fvalue = std::numbers::e; yylval.constant.name = "e"; return CONSTANT; // constant e "None" COUNTCHARS; yylval.constant.fvalue = 0; yylval.constant.name = "None"; return CONSTANT; "True" COUNTCHARS; yylval.constant.fvalue = 1; yylval.constant.name = "True"; return CONSTANT; diff --git a/src/App/Link.cpp b/src/App/Link.cpp index 2762040d42..9312aa13d2 100644 --- a/src/App/Link.cpp +++ b/src/App/Link.cpp @@ -2624,7 +2624,8 @@ Link::Link() { LINK_PROPS_ADD(LINK_PARAMS_LINK); LinkExtension::initExtension(this); - static const PropertyIntegerConstraint::Constraints s_constraints = {0, INT_MAX, 1}; + static const PropertyIntegerConstraint::Constraints s_constraints = { + 0, std::numeric_limits::max(), 1}; ElementCount.setConstraints(&s_constraints); } diff --git a/src/App/ObjectIdentifier.cpp b/src/App/ObjectIdentifier.cpp index 28637d638a..0c80b13672 100644 --- a/src/App/ObjectIdentifier.cpp +++ b/src/App/ObjectIdentifier.cpp @@ -130,7 +130,7 @@ ObjectIdentifier::ObjectIdentifier(const App::PropertyContainer* _owner, } if (!property.empty()) { addComponent(SimpleComponent(property)); - if (index != INT_MAX) { + if (index != std::numeric_limits::max()) { addComponent(ArrayComponent(index)); } } @@ -179,7 +179,7 @@ ObjectIdentifier::ObjectIdentifier(const Property& prop, int index) setDocumentObjectName(docObj); addComponent(SimpleComponent(String(prop.getName()))); - if (index != INT_MAX) { + if (index != std::numeric_limits::max()) { addComponent(ArrayComponent(index)); } } @@ -703,8 +703,9 @@ Py::Object ObjectIdentifier::Component::get(const Py::Object& pyobj) const } else { assert(isRange()); + constexpr int max = std::numeric_limits::max(); Py::Object slice(PySlice_New(Py::Long(begin).ptr(), - end != INT_MAX ? Py::Long(end).ptr() : nullptr, + end != max ? Py::Long(end).ptr() : nullptr, step != 1 ? Py::Long(step).ptr() : nullptr), true); PyObject* r = PyObject_GetItem(pyobj.ptr(), slice.ptr()); @@ -742,8 +743,9 @@ void ObjectIdentifier::Component::set(Py::Object& pyobj, const Py::Object& value } else { assert(isRange()); + constexpr int max = std::numeric_limits::max(); Py::Object slice(PySlice_New(Py::Long(begin).ptr(), - end != INT_MAX ? Py::Long(end).ptr() : nullptr, + end != max ? Py::Long(end).ptr() : nullptr, step != 1 ? Py::Long(step).ptr() : nullptr), true); if (PyObject_SetItem(pyobj.ptr(), slice.ptr(), value.ptr()) < 0) { @@ -770,8 +772,9 @@ void ObjectIdentifier::Component::del(Py::Object& pyobj) const } else { assert(isRange()); + constexpr int max = std::numeric_limits::max(); Py::Object slice(PySlice_New(Py::Long(begin).ptr(), - end != INT_MAX ? Py::Long(end).ptr() : nullptr, + end != max ? Py::Long(end).ptr() : nullptr, step != 1 ? Py::Long(step).ptr() : nullptr), true); if (PyObject_DelItem(pyobj.ptr(), slice.ptr()) < 0) { @@ -897,11 +900,11 @@ void ObjectIdentifier::Component::toString(std::ostream& ss, bool toPython) cons break; case Component::RANGE: ss << '['; - if (begin != INT_MAX) { + if (begin != std::numeric_limits::max()) { ss << begin; } ss << ':'; - if (end != INT_MAX) { + if (end != std::numeric_limits::max()) { ss << end; } if (step != 1) { diff --git a/src/App/ObjectIdentifier.h b/src/App/ObjectIdentifier.h index c62f69c47c..60cb5e19c6 100644 --- a/src/App/ObjectIdentifier.h +++ b/src/App/ObjectIdentifier.h @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -211,13 +212,13 @@ public: Component(const String& _name = String(), typeEnum _type = SIMPLE, - int begin = INT_MAX, - int end = INT_MAX, + int begin = std::numeric_limits::max(), + int end = std::numeric_limits::max(), int step = 1); // explicit bombs Component(String&& _name, typeEnum _type = SIMPLE, - int begin = INT_MAX, - int end = INT_MAX, + int begin = std::numeric_limits::max(), + int end = std::numeric_limits::max(), int step = 1); // explicit bombs static Component SimpleComponent(const char* _component); @@ -227,7 +228,9 @@ public: static Component ArrayComponent(int _index); - static Component RangeComponent(int _begin, int _end = INT_MAX, int _step = 1); + static Component RangeComponent(int _begin, + int _end = std::numeric_limits::max(), + int _step = 1); static Component MapComponent(const String& _key); static Component MapComponent(String&& _key); @@ -325,7 +328,9 @@ public: return Component::ArrayComponent(_index); } - static Component RangeComponent(int _begin, int _end = INT_MAX, int _step = 1) + static Component RangeComponent(int _begin, + int _end = std::numeric_limits::max(), + int _step = 1) { return Component::RangeComponent(_begin, _end, _step); } @@ -342,11 +347,12 @@ public: explicit ObjectIdentifier(const App::PropertyContainer* _owner = nullptr, const std::string& property = std::string(), - int index = INT_MAX); + int index = std::numeric_limits::max()); ObjectIdentifier(const App::PropertyContainer* _owner, bool localProperty); - ObjectIdentifier(const App::Property& prop, int index = INT_MAX); // explicit bombs + ObjectIdentifier(const App::Property& prop, + int index = std::numeric_limits::max()); // explicit bombs FC_DEFAULT_CTORS(ObjectIdentifier) { diff --git a/src/App/PreCompiled.h b/src/App/PreCompiled.h index 38d675970a..bd32e3058f 100644 --- a/src/App/PreCompiled.h +++ b/src/App/PreCompiled.h @@ -50,7 +50,6 @@ #include #include #include -#include #ifdef FC_OS_WIN32 #include @@ -74,6 +73,7 @@ #include #include #include +#include #include #include #include diff --git a/src/App/PropertyStandard.cpp b/src/App/PropertyStandard.cpp index 77f12cd513..4ef6b2e335 100644 --- a/src/App/PropertyStandard.cpp +++ b/src/App/PropertyStandard.cpp @@ -1250,7 +1250,7 @@ void PropertyFloatConstraint::setPyObject(PyObject* value) double stepSize = valConstr[3]; // need a value > 0 - if (stepSize < DBL_EPSILON) { + if (stepSize < std::numeric_limits::epsilon()) { throw Base::ValueError("Step size must be greater than zero"); } @@ -1282,7 +1282,8 @@ TYPESYSTEM_SOURCE(App::PropertyPrecision, App::PropertyFloatConstraint) //************************************************************************** // Construction/Destruction // -const PropertyFloatConstraint::Constraints PrecisionStandard = {0.0, DBL_MAX, 0.001}; +const PropertyFloatConstraint::Constraints PrecisionStandard = { + 0.0, std::numeric_limits::max(), 0.001}; PropertyPrecision::PropertyPrecision() { diff --git a/src/App/PropertyUnits.cpp b/src/App/PropertyUnits.cpp index f2c30c6dce..153b64bfa2 100644 --- a/src/App/PropertyUnits.cpp +++ b/src/App/PropertyUnits.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #endif #include @@ -37,7 +36,8 @@ using namespace Base; using namespace std; -const PropertyQuantityConstraint::Constraints LengthStandard = {0.0, DBL_MAX, 1.0}; +const PropertyQuantityConstraint::Constraints LengthStandard = { + 0.0, std::numeric_limits::max(), 1.0}; const PropertyQuantityConstraint::Constraints AngleStandard = {-360, 360, 1.0}; //************************************************************************** diff --git a/src/App/lex.ExpressionParser.c b/src/App/lex.ExpressionParser.c index 2916336b02..cc9777e092 100644 --- a/src/App/lex.ExpressionParser.c +++ b/src/App/lex.ExpressionParser.c @@ -9583,12 +9583,12 @@ YY_RULE_SETUP case 138: YY_RULE_SETUP #line 351 "ExpressionParser.l" -COUNTCHARS; yylval.constant.fvalue = M_PI; yylval.constant.name = "pi"; return CONSTANT; // constant pi +COUNTCHARS; yylval.constant.fvalue = std::numbers::pi; yylval.constant.name = "pi"; return CONSTANT; // constant pi YY_BREAK case 139: YY_RULE_SETUP #line 352 "ExpressionParser.l" -COUNTCHARS; yylval.constant.fvalue = M_E; yylval.constant.name = "e"; return CONSTANT; // constant e +COUNTCHARS; yylval.constant.fvalue = std::numbers::e; yylval.constant.name = "e"; return CONSTANT; // constant e YY_BREAK case 140: YY_RULE_SETUP diff --git a/src/Base/FileInfo.cpp b/src/Base/FileInfo.cpp index a466d41ef2..024a190efd 100644 --- a/src/Base/FileInfo.cpp +++ b/src/Base/FileInfo.cpp @@ -32,7 +32,6 @@ #if defined(FC_OS_LINUX) || defined(FC_OS_CYGWIN) || defined(FC_OS_MACOSX) || defined(FC_OS_BSD) #include #include -#include #elif defined(FC_OS_WIN32) #include #include diff --git a/src/Base/Matrix.cpp b/src/Base/Matrix.cpp index 065fc1b569..aa0623b2b7 100644 --- a/src/Base/Matrix.cpp +++ b/src/Base/Matrix.cpp @@ -429,7 +429,7 @@ bool Matrix4D::toAxisAngle(Vector3d& rclBase, rfAngle = acos(fCos); // in [0,PI] if (rfAngle > 0.0) { - if (rfAngle < D_PI) { + if (rfAngle < std::numbers::pi) { rclDir.x = (dMtrx4D[2][1] - dMtrx4D[1][2]); rclDir.y = (dMtrx4D[0][2] - dMtrx4D[2][0]); rclDir.z = (dMtrx4D[1][0] - dMtrx4D[0][1]); @@ -1013,8 +1013,8 @@ std::array Matrix4D::decompose() const residualMatrix = rotationMatrix * residualMatrix; // To keep signs of the scale factors equal if (residualMatrix.determinant() < 0) { - rotationMatrix.rotZ(D_PI); - residualMatrix.rotZ(D_PI); + rotationMatrix.rotZ(std::numbers::pi); + residualMatrix.rotZ(std::numbers::pi); } rotationMatrix.inverseGauss(); // extract scale diff --git a/src/Base/MatrixPyImp.cpp b/src/Base/MatrixPyImp.cpp index 029f57af2c..9aaa9e8d63 100644 --- a/src/Base/MatrixPyImp.cpp +++ b/src/Base/MatrixPyImp.cpp @@ -218,7 +218,7 @@ PyObject* MatrixPy::number_power_handler(PyObject* self, PyObject* other, PyObje } if (b < 0) { - if (fabs(a.determinant()) > DBL_EPSILON) { + if (fabs(a.determinant()) > std::numeric_limits::epsilon()) { a.inverseGauss(); } else { @@ -667,7 +667,7 @@ PyObject* MatrixPy::invert() { PY_TRY { - if (fabs(getMatrixPtr()->determinant()) > DBL_EPSILON) { + if (fabs(getMatrixPtr()->determinant()) > std::numeric_limits::epsilon()) { getMatrixPtr()->inverseGauss(); Py_Return; } @@ -682,7 +682,7 @@ PyObject* MatrixPy::inverse() { PY_TRY { - if (fabs(getMatrixPtr()->determinant()) > DBL_EPSILON) { + if (fabs(getMatrixPtr()->determinant()) > std::numeric_limits::epsilon()) { Base::Matrix4D m = *getMatrixPtr(); m.inverseGauss(); return new MatrixPy(m); diff --git a/src/Base/PlacementPyImp.cpp b/src/Base/PlacementPyImp.cpp index d57791d69f..8513895157 100644 --- a/src/Base/PlacementPyImp.cpp +++ b/src/Base/PlacementPyImp.cpp @@ -99,7 +99,8 @@ int PlacementPy::PyInit(PyObject* args, PyObject* /*kwd*/) &angle)) { // NOTE: The first parameter defines the translation, the second the rotation axis // and the last parameter defines the rotation angle in degree. - Base::Rotation rot(static_cast(d)->value(), angle / 180.0 * D_PI); + Base::Rotation rot(static_cast(d)->value(), + angle / 180.0 * std::numbers::pi); *getPlacementPtr() = Base::Placement(static_cast(o)->value(), rot); return 0; } diff --git a/src/Base/PreCompiled.h b/src/Base/PreCompiled.h index 1e5fa96dbb..5a26c2e4f6 100644 --- a/src/Base/PreCompiled.h +++ b/src/Base/PreCompiled.h @@ -36,13 +36,8 @@ #include #include #include -#include #include -#ifdef FC_OS_WIN32 -#define _USE_MATH_DEFINES -#endif // FC_OS_WIN32 #include -#include #include #ifdef FC_OS_WIN32 @@ -61,7 +56,6 @@ #include #include #include -#include #endif // STL @@ -69,6 +63,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Base/Quantity.cpp b/src/Base/Quantity.cpp index 41002c6f66..e566227b17 100644 --- a/src/Base/Quantity.cpp +++ b/src/Base/Quantity.cpp @@ -22,9 +22,9 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#define _USE_MATH_DEFINES #include #include +#include #endif #include @@ -443,8 +443,8 @@ const Quantity Quantity::AngSecond(1.0 / 3600.0, Unit(0, 0, 0, 0, 0, 0, 0, 1)); const Quantity Quantity::Degree(1.0, Unit(0, 0, 0, 0, 0, 0, 0, 1)); // degree (internal standard angle) -const Quantity Quantity::Radian(180 / M_PI, Unit(0, 0, 0, 0, 0, 0, 0, 1)); // radian -const Quantity Quantity::Gon(360.0 / 400.0, Unit(0, 0, 0, 0, 0, 0, 0, 1)); // gon +const Quantity Quantity::Radian(180 / std::numbers::pi, Unit(0, 0, 0, 0, 0, 0, 0, 1)); // radian +const Quantity Quantity::Gon(360.0 / 400.0, Unit(0, 0, 0, 0, 0, 0, 0, 1)); // gon // === Parser & Scanner stuff =============================================== @@ -568,7 +568,7 @@ Quantity Quantity::parse(const std::string& string) QuantityParser::yy_scan_string(string.c_str()); QuantityParser::StringBufferCleaner cleaner(my_string_buffer); // set the global return variables - QuantResult = Quantity(DOUBLE_MIN); + QuantResult = Quantity(std::numeric_limits::min()); // run the parser QuantityParser::yyparse(); diff --git a/src/Base/Quantity.h b/src/Base/Quantity.h index 94351aa6ea..ccfc33cb96 100644 --- a/src/Base/Quantity.h +++ b/src/Base/Quantity.h @@ -27,15 +27,6 @@ #include "Unit.h" #include -// NOLINTBEGIN -#ifndef DOUBLE_MAX -#define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif -#ifndef DOUBLE_MIN -#define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif -// NOLINTEND - namespace Base { class UnitsSchema; diff --git a/src/Base/QuantityLexer.c b/src/Base/QuantityLexer.c index c21f3d9fa8..547916b50b 100644 --- a/src/Base/QuantityLexer.c +++ b/src/Base/QuantityLexer.c @@ -1613,12 +1613,12 @@ YY_RULE_SETUP case 135: YY_RULE_SETUP #line 228 "QuantityParser.l" -{yylval = Quantity(M_PI) ; return NUM;} // constant pi +{yylval = Quantity(std::numbers::pi) ; return NUM;} // constant pi YY_BREAK case 136: YY_RULE_SETUP #line 229 "QuantityParser.l" -{yylval = Quantity(M_E) ; return NUM;} // constant e +{yylval = Quantity(std::numbers::e) ; return NUM;} // constant e YY_BREAK case 137: YY_RULE_SETUP diff --git a/src/Base/QuantityParser.c b/src/Base/QuantityParser.c index bb8ae3915b..e38a289ab8 100644 --- a/src/Base/QuantityParser.c +++ b/src/Base/QuantityParser.c @@ -68,12 +68,12 @@ #define YYSTYPE Quantity #define yyparse Quantity_yyparse #define yyerror Quantity_yyerror - #ifndef DOUBLE_MAX - # define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ - #endif - #ifndef DOUBLE_MIN - # define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ - #endif + + + + + + #line 79 "QuantityParser.c" /* yacc.c:339 */ @@ -1301,7 +1301,7 @@ yyreduce: { case 2: #line 34 "QuantityParser.y" /* yacc.c:1646 */ - { QuantResult = Quantity(DOUBLE_MIN); /* empty input */ } + { QuantResult = Quantity(std::numeric_limits::min()); /* empty input */ } #line 1305 "QuantityParser.c" /* yacc.c:1646 */ break; diff --git a/src/Base/QuantityParser.l b/src/Base/QuantityParser.l index 1a52592715..bd697d4dea 100644 --- a/src/Base/QuantityParser.l +++ b/src/Base/QuantityParser.l @@ -225,8 +225,8 @@ CGRP '\,'[0-9][0-9][0-9] ","?{DIGIT}+{EXPO}? { yylval = Quantity(num_change(yytext,',','.'));return NUM; } -"pi" {yylval = Quantity(M_PI) ; return NUM;} // constant pi -"e" {yylval = Quantity(M_E) ; return NUM;} // constant e +"pi" {yylval = Quantity(std::numbers::pi) ; return NUM;} // constant pi +"e" {yylval = Quantity(std::numbers::e) ; return NUM;} // constant e "acos" return ACOS; "asin" return ASIN; diff --git a/src/Base/QuantityParser.y b/src/Base/QuantityParser.y index 906b9cab6f..b652151c81 100644 --- a/src/Base/QuantityParser.y +++ b/src/Base/QuantityParser.y @@ -25,12 +25,12 @@ #define YYSTYPE Quantity #define yyparse Quantity_yyparse #define yyerror Quantity_yyerror - #ifndef DOUBLE_MAX - # define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ - #endif - #ifndef DOUBLE_MIN - # define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ - #endif + + + + + + %} @@ -49,7 +49,7 @@ %% - input: { QuantResult = Quantity(DOUBLE_MIN); /* empty input */ } + input: { QuantResult = Quantity(std::numeric_limits::min()); /* empty input */ } | num { QuantResult = $1 ; } | unit { QuantResult = $1 ; } | quantity { QuantResult = $1 ; } diff --git a/src/Base/QuantityPyImp.cpp b/src/Base/QuantityPyImp.cpp index 85078c38f6..5b999d6aaa 100644 --- a/src/Base/QuantityPyImp.cpp +++ b/src/Base/QuantityPyImp.cpp @@ -88,7 +88,7 @@ int QuantityPy::PyInit(PyObject* args, PyObject* /*kwd*/) } PyErr_Clear(); // set by PyArg_ParseTuple() - double f = DOUBLE_MAX; + double f = std::numeric_limits::max(); if (PyArg_ParseTuple(args, "dO!", &f, &(Base::UnitPy::Type), &object)) { *self = Quantity(f, *(static_cast(object)->getUnitPtr())); return 0; @@ -110,7 +110,7 @@ int QuantityPy::PyInit(PyObject* args, PyObject* /*kwd*/) int i8 = 0; PyErr_Clear(); // set by PyArg_ParseTuple() if (PyArg_ParseTuple(args, "|diiiiiiii", &f, &i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8)) { - if (f < DOUBLE_MAX) { + if (f < std::numeric_limits::max()) { *self = Quantity(f, Unit {static_cast(i1), static_cast(i2), @@ -207,7 +207,7 @@ PyObject* QuantityPy::getValueAs(PyObject* args) } if (!quant.isValid()) { - double f = DOUBLE_MAX; + double f = std::numeric_limits::max(); int i1 = 0; int i2 = 0; int i3 = 0; @@ -218,7 +218,7 @@ PyObject* QuantityPy::getValueAs(PyObject* args) int i8 = 0; PyErr_Clear(); if (PyArg_ParseTuple(args, "d|iiiiiiii", &f, &i1, &i2, &i3, &i4, &i5, &i6, &i7, &i8)) { - if (f < DOUBLE_MAX) { + if (f < std::numeric_limits::max()) { quant = Quantity(f, Unit {static_cast(i1), static_cast(i2), diff --git a/src/Base/Rotation.cpp b/src/Base/Rotation.cpp index da65a99808..e9e1776e80 100644 --- a/src/Base/Rotation.cpp +++ b/src/Base/Rotation.cpp @@ -245,11 +245,12 @@ void Rotation::setValue(const Matrix4D& m) void Rotation::setValue(const Vector3d& axis, double fAngle) { + using std::numbers::pi; // Taken from // // normalization of the angle to be in [0, 2pi[ _angle = fAngle; - double theAngle = fAngle - floor(fAngle / (2.0 * D_PI)) * (2.0 * D_PI); + double theAngle = fAngle - floor(fAngle / (2.0 * pi)) * (2.0 * pi); this->quat[3] = cos(theAngle / 2.0); Vector3d norm = axis; @@ -691,9 +692,9 @@ void Rotation::setYawPitchRoll(double y, double p, double r) { // The Euler angles (yaw,pitch,roll) are in XY'Z''-notation // convert to radians - y = (y / 180.0) * D_PI; - p = (p / 180.0) * D_PI; - r = (r / 180.0) * D_PI; + y = (y / 180.0) * std::numbers::pi; + p = (p / 180.0) * std::numbers::pi; + r = (r / 180.0) * std::numbers::pi; double c1 = cos(y / 2.0); double s1 = sin(y / 2.0); @@ -710,6 +711,8 @@ void Rotation::setYawPitchRoll(double y, double p, double r) void Rotation::getYawPitchRoll(double& y, double& p, double& r) const { + using std::numbers::pi; + double q00 = quat[0] * quat[0]; double q11 = quat[1] * quat[1]; double q22 = quat[2] * quat[2]; @@ -722,30 +725,31 @@ void Rotation::getYawPitchRoll(double& y, double& p, double& r) const double q23 = quat[2] * quat[3]; double qd2 = 2.0 * (q13 - q02); + // Tolerance copied from OCC "gp_Quaternion.cxx" + constexpr double tolerance = 16 * std::numeric_limits::epsilon(); // handle gimbal lock - if (fabs(qd2 - 1.0) <= 16 * DBL_EPSILON) { // Tolerance copied from OCC "gp_Quaternion.cxx" + if (fabs(qd2 - 1.0) <= tolerance) { // north pole y = 0.0; - p = D_PI / 2.0; + p = pi / 2.0; r = 2.0 * atan2(quat[0], quat[3]); } - else if (fabs(qd2 + 1.0) - <= 16 * DBL_EPSILON) { // Tolerance copied from OCC "gp_Quaternion.cxx" + else if (fabs(qd2 + 1.0) <= tolerance) { // south pole y = 0.0; - p = -D_PI / 2.0; + p = -pi / 2.0; r = 2.0 * atan2(quat[0], quat[3]); } else { y = atan2(2.0 * (q01 + q23), (q00 + q33) - (q11 + q22)); - p = qd2 > 1.0 ? D_PI / 2.0 : (qd2 < -1.0 ? -D_PI / 2.0 : asin(qd2)); + p = qd2 > 1.0 ? pi / 2.0 : (qd2 < -1.0 ? -pi / 2.0 : asin(qd2)); r = atan2(2.0 * (q12 + q03), (q22 + q33) - (q00 + q11)); } // convert to degree - y = (y / D_PI) * 180; - p = (p / D_PI) * 180; - r = (r / D_PI) * 180; + y = (y / pi) * 180; + p = (p / pi) * 180; + r = (r / pi) * 180; } bool Rotation::isSame(const Rotation& q) const @@ -978,15 +982,17 @@ void Rotation::setEulerAngles(EulerSequence theOrder, double theBeta, double theGamma) { + using std::numbers::pi; + if (theOrder == Invalid || theOrder >= EulerSequenceLast) { throw Base::ValueError("invalid euler sequence"); } EulerSequence_Parameters o = translateEulerSequence(theOrder); - theAlpha *= D_PI / 180.0; - theBeta *= D_PI / 180.0; - theGamma *= D_PI / 180.0; + theAlpha *= pi / 180.0; + theBeta *= pi / 180.0; + theGamma *= pi / 180.0; double a = theAlpha; double b = theBeta; @@ -1048,7 +1054,7 @@ void Rotation::getEulerAngles(EulerSequence theOrder, EulerSequence_Parameters o = translateEulerSequence(theOrder); if (o.isTwoAxes) { double sy = sqrt(M(o.i, o.j) * M(o.i, o.j) + M(o.i, o.k) * M(o.i, o.k)); - if (sy > 16 * DBL_EPSILON) { + if (sy > 16 * std::numeric_limits::epsilon()) { theAlpha = atan2(M(o.i, o.j), M(o.i, o.k)); theGamma = atan2(M(o.j, o.i), -M(o.k, o.i)); } @@ -1060,7 +1066,7 @@ void Rotation::getEulerAngles(EulerSequence theOrder, } else { double cy = sqrt(M(o.i, o.i) * M(o.i, o.i) + M(o.j, o.i) * M(o.j, o.i)); - if (cy > 16 * DBL_EPSILON) { + if (cy > 16 * std::numeric_limits::epsilon()) { theAlpha = atan2(M(o.k, o.j), M(o.k, o.k)); theGamma = atan2(M(o.j, o.i), M(o.i, o.i)); } @@ -1081,7 +1087,7 @@ void Rotation::getEulerAngles(EulerSequence theOrder, theGamma = aFirst; } - theAlpha *= 180.0 / D_PI; - theBeta *= 180.0 / D_PI; - theGamma *= 180.0 / D_PI; + theAlpha *= 180.0 / std::numbers::pi; + theBeta *= 180.0 / std::numbers::pi; + theGamma *= 180.0 / std::numbers::pi; } diff --git a/src/Base/Tools.h b/src/Base/Tools.h index f0d767ab00..182d804000 100644 --- a/src/Base/Tools.h +++ b/src/Base/Tools.h @@ -28,6 +28,7 @@ #include #endif #include +#include #include #include #include @@ -127,20 +128,16 @@ inline T sgn(T t) return (t > 0) ? T(1) : T(-1); } -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - template inline T toRadians(T d) { - return static_cast((d * M_PI) / 180.0); + return static_cast((d * std::numbers::pi) / 180.0); } template inline T toDegrees(T r) { - return static_cast((r / M_PI) * 180.0); + return static_cast((r / std::numbers::pi) * 180.0); } inline float fromPercent(const long value) diff --git a/src/Base/Tools2D.cpp b/src/Base/Tools2D.cpp index 625f152ca5..59bc296830 100644 --- a/src/Base/Tools2D.cpp +++ b/src/Base/Tools2D.cpp @@ -43,7 +43,7 @@ double Vector2d::GetAngle(const Vector2d& vec) const if ((fDivid < -1e-10) || (fDivid > 1e-10)) { fNum = (*this * vec) / fDivid; if (fNum < -1) { - return D_PI; + return std::numbers::pi; } if (fNum > 1) { return 0.0; @@ -52,7 +52,7 @@ double Vector2d::GetAngle(const Vector2d& vec) const return acos(fNum); } - return -FLOAT_MAX; // division by zero + return -std::numeric_limits::max(); // division by zero } void Vector2d::ProjectToLine(const Vector2d& point, const Vector2d& line) @@ -173,13 +173,13 @@ bool Line2d::Intersect(const Line2d& rclLine, Vector2d& rclV) const m1 = (clV2.y - clV1.y) / (clV2.x - clV1.x); } else { - m1 = DOUBLE_MAX; + m1 = std::numeric_limits::max(); } if (fabs(rclLine.clV2.x - rclLine.clV1.x) > 1e-10) { m2 = (rclLine.clV2.y - rclLine.clV1.y) / (rclLine.clV2.x - rclLine.clV1.x); } else { - m2 = DOUBLE_MAX; + m2 = std::numeric_limits::max(); } if (m1 == m2) { /****** RETURN ERR (parallel lines) *************/ return false; @@ -189,11 +189,11 @@ bool Line2d::Intersect(const Line2d& rclLine, Vector2d& rclV) const b2 = rclLine.clV1.y - m2 * rclLine.clV1.x; // calc intersection - if (m1 == DOUBLE_MAX) { + if (m1 == std::numeric_limits::max()) { rclV.x = clV1.x; rclV.y = m2 * rclV.x + b2; } - else if (m2 == DOUBLE_MAX) { + else if (m2 == std::numeric_limits::max()) { rclV.x = rclLine.clV1.x; rclV.y = m1 * rclV.x + b1; } diff --git a/src/Base/Tools2D.h b/src/Base/Tools2D.h index 9bc10d19c3..a76fd88bb2 100644 --- a/src/Base/Tools2D.h +++ b/src/Base/Tools2D.h @@ -32,15 +32,6 @@ #include #endif -// NOLINTBEGIN -#ifndef DOUBLE_MAX -#define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif -#ifndef DOUBLE_MIN -#define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif -// NOLINTEND - namespace Base { @@ -462,8 +453,8 @@ inline bool Line2d::Contains(const Vector2d& rclV) const inline BoundBox2d::BoundBox2d() { - MinX = MinY = DOUBLE_MAX; - MaxX = MaxY = -DOUBLE_MAX; + MinX = MinY = std::numeric_limits::max(); + MaxX = MaxY = -std::numeric_limits::max(); } inline BoundBox2d::BoundBox2d(double fX1, double fY1, double fX2, double fY2) @@ -480,7 +471,8 @@ inline bool BoundBox2d::IsValid() const inline bool BoundBox2d::IsInfinite() const { - return MaxX >= DOUBLE_MAX && MaxY >= DOUBLE_MAX && MinX <= -DOUBLE_MAX && MinY <= -DOUBLE_MAX; + constexpr double max = std::numeric_limits::max(); + return MaxX >= max && MaxY >= max && MinX <= -max && MinY <= -max; } inline bool BoundBox2d::IsEqual(const BoundBox2d& bbox, double tolerance) const @@ -525,8 +517,8 @@ inline Vector2d BoundBox2d::GetCenter() const inline void BoundBox2d::SetVoid() { - MinX = MinY = DOUBLE_MAX; - MaxX = MaxY = -DOUBLE_MAX; + MinX = MinY = std::numeric_limits::max(); + MaxX = MaxY = -std::numeric_limits::max(); } inline void BoundBox2d::Add(const Vector2d& v) diff --git a/src/Base/Vector3D.h b/src/Base/Vector3D.h index 62ad1fb5f1..6b8ec5423c 100644 --- a/src/Base/Vector3D.h +++ b/src/Base/Vector3D.h @@ -24,34 +24,9 @@ #ifndef BASE_VECTOR3D_H #define BASE_VECTOR3D_H - +#include #include -#include - -#ifndef F_PI -#define F_PI 3.1415926f -#endif - -#ifndef D_PI -#define D_PI 3.141592653589793 -#endif - -#ifndef FLOAT_MAX -#define FLOAT_MAX 3.402823466E+38F -#endif - -#ifndef FLOAT_MIN -#define FLOAT_MIN 1.175494351E-38F -#endif - -#ifndef DOUBLE_MAX -#define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif - -#ifndef DOUBLE_MIN -#define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif - +#include namespace Base { @@ -60,21 +35,22 @@ struct float_traits { }; +// TODO: Remove these specializations and use the default implementation for all types. template<> struct float_traits { using float_type = float; - [[nodiscard]] static constexpr float_type pi() + [[nodiscard]] static consteval float_type pi() { - return F_PI; + return std::numbers::pi_v; } - [[nodiscard]] static constexpr float_type epsilon() + [[nodiscard]] static consteval float_type epsilon() { - return FLT_EPSILON; + return std::numeric_limits::epsilon(); } - [[nodiscard]] static constexpr float_type maximum() + [[nodiscard]] static consteval float_type maximum() { - return FLT_MAX; + return std::numeric_limits::max(); } }; @@ -82,17 +58,17 @@ template<> struct float_traits { using float_type = double; - [[nodiscard]] static constexpr float_type pi() + [[nodiscard]] static consteval float_type pi() { - return D_PI; + return std::numbers::pi_v; } - [[nodiscard]] static constexpr float_type epsilon() + [[nodiscard]] static consteval float_type epsilon() { - return DBL_EPSILON; + return std::numeric_limits::epsilon(); } - [[nodiscard]] static constexpr float_type maximum() + [[nodiscard]] static consteval float_type maximum() { - return DBL_MAX; + return std::numeric_limits::max(); } }; @@ -275,7 +251,7 @@ template float_type x = v1.x - v2.x; float_type y = v1.y - v2.y; float_type z = v1.z - v2.z; - return static_cast(sqrt((x * x) + (y * y) + (z * z))); + return static_cast(std::sqrt((x * x) + (y * y) + (z * z))); } /// Returns the squared distance between two points diff --git a/src/Gui/CallTips.cpp b/src/Gui/CallTips.cpp index 93221d7366..e3712f9c22 100644 --- a/src/Gui/CallTips.cpp +++ b/src/Gui/CallTips.cpp @@ -748,7 +748,7 @@ QString CallTipsList::stripWhiteSpace(const QString& str) const { QString stripped = str; QStringList lines = str.split(QLatin1String("\n")); - int minspace=INT_MAX; + int minspace=std::numeric_limits::max(); int line=0; for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { if (it->size() > 0 && line > 0) { @@ -766,7 +766,7 @@ QString CallTipsList::stripWhiteSpace(const QString& str) const } // remove all leading tabs from each line - if (minspace > 0 && minspace < INT_MAX) { + if (minspace > 0 && minspace < std::numeric_limits::max()) { int line=0; QStringList strippedlines; for (QStringList::iterator it = lines.begin(); it != lines.end(); ++it, ++line) { diff --git a/src/Gui/Clipping.cpp b/src/Gui/Clipping.cpp index e56eb2997b..d2495c3720 100644 --- a/src/Gui/Clipping.cpp +++ b/src/Gui/Clipping.cpp @@ -109,20 +109,21 @@ Clipping::Clipping(Gui::View3DInventor* view, QWidget* parent) d->ui.setupUi(this); setupConnections(); - d->ui.clipView->setRange(-INT_MAX, INT_MAX); + constexpr int max = std::numeric_limits::max(); + d->ui.clipView->setRange(-max, max); d->ui.clipView->setSingleStep(0.1f); - d->ui.clipX->setRange(-INT_MAX, INT_MAX); + d->ui.clipX->setRange(-max, max); d->ui.clipX->setSingleStep(0.1f); - d->ui.clipY->setRange(-INT_MAX, INT_MAX); + d->ui.clipY->setRange(-max, max); d->ui.clipY->setSingleStep(0.1f); - d->ui.clipZ->setRange(-INT_MAX, INT_MAX); + d->ui.clipZ->setRange(-max, max); d->ui.clipZ->setSingleStep(0.1f); - d->ui.dirX->setRange(-INT_MAX, INT_MAX); + d->ui.dirX->setRange(-max, max); d->ui.dirX->setSingleStep(0.1f); - d->ui.dirY->setRange(-INT_MAX, INT_MAX); + d->ui.dirY->setRange(-max, max); d->ui.dirY->setSingleStep(0.1f); - d->ui.dirZ->setRange(-INT_MAX, INT_MAX); + d->ui.dirZ->setRange(-max, max); d->ui.dirZ->setSingleStep(0.1f); d->ui.dirZ->setValue(1.0f); diff --git a/src/Gui/DemoMode.cpp b/src/Gui/DemoMode.cpp index e253246b3d..d69224d891 100644 --- a/src/Gui/DemoMode.cpp +++ b/src/Gui/DemoMode.cpp @@ -166,7 +166,7 @@ SbVec3f DemoMode::getDirection(Gui::View3DInventor* view) const SbRotation inv = rot.inverse(); SbVec3f vec(this->viewAxis); inv.multVec(vec, vec); - if (vec.length() < FLT_EPSILON) { + if (vec.length() < std::numeric_limits::epsilon()) { vec = this->viewAxis; } vec.normalize(); diff --git a/src/Gui/Dialogs/DlgParameterImp.cpp b/src/Gui/Dialogs/DlgParameterImp.cpp index 2036e65ee4..8139e994ba 100644 --- a/src/Gui/Dialogs/DlgParameterImp.cpp +++ b/src/Gui/Dialogs/DlgParameterImp.cpp @@ -905,7 +905,7 @@ void ParameterValue::onCreateUIntItem() DlgInputDialogImp::UIntBox); dlg.setWindowTitle(QObject::tr("New unsigned item")); UIntSpinBox* edit = dlg.getUIntBox(); - edit->setRange(0, UINT_MAX); + edit->setRange(0, std::numeric_limits::max()); if (dlg.exec() == QDialog::Accepted) { QString value = edit->text(); unsigned long val = value.toULong(&ok); @@ -1249,7 +1249,7 @@ void ParameterUInt::changeValue() DlgInputDialogImp::UIntBox); dlg.setWindowTitle(QObject::tr("Change value")); UIntSpinBox* edit = dlg.getUIntBox(); - edit->setRange(0, UINT_MAX); + edit->setRange(0, std::numeric_limits::max()); edit->setValue(text(2).toULong()); if (dlg.exec() == QDialog::Accepted) { QString value = edit->text(); diff --git a/src/Gui/EditableDatumLabel.cpp b/src/Gui/EditableDatumLabel.cpp index 5fa800935e..0604bc0a2d 100644 --- a/src/Gui/EditableDatumLabel.cpp +++ b/src/Gui/EditableDatumLabel.cpp @@ -152,8 +152,8 @@ void EditableDatumLabel::startEdit(double val, QObject* eventFilteringObj, bool spinBox = new QuantitySpinBox(mdi); spinBox->setUnit(Base::Unit::Length); - spinBox->setMinimum(-INT_MAX); - spinBox->setMaximum(INT_MAX); + spinBox->setMinimum(-std::numeric_limits::max()); + spinBox->setMaximum(std::numeric_limits::max()); spinBox->setButtonSymbols(QAbstractSpinBox::NoButtons); spinBox->setKeyboardTracking(false); spinBox->setFocusPolicy(Qt::ClickFocus); // prevent passing focus with tab. diff --git a/src/Gui/InputField.cpp b/src/Gui/InputField.cpp index 0d432566a9..e53fc5d1c4 100644 --- a/src/Gui/InputField.cpp +++ b/src/Gui/InputField.cpp @@ -71,8 +71,8 @@ InputField::InputField(QWidget * parent) ExpressionWidget(), validInput(true), actUnitValue(0), - Maximum(DOUBLE_MAX), - Minimum(-DOUBLE_MAX), + Maximum(std::numeric_limits::max()), + Minimum(-std::numeric_limits::max()), StepSize(1.0), HistorySize(5), SaveSize(5) diff --git a/src/Gui/Inventor/SoFCBackgroundGradient.cpp b/src/Gui/Inventor/SoFCBackgroundGradient.cpp index 37eb809127..323c18a91e 100644 --- a/src/Gui/Inventor/SoFCBackgroundGradient.cpp +++ b/src/Gui/Inventor/SoFCBackgroundGradient.cpp @@ -25,10 +25,8 @@ #ifndef _PreComp_ #include #include -#ifdef FC_OS_WIN32 - #define _USE_MATH_DEFINES -#endif #include +#include #ifdef FC_OS_MACOSX #include #else @@ -39,17 +37,23 @@ #include "SoFCBackgroundGradient.h" static const std::array big_circle = []{ - static const float pi2 = boost::math::constants::two_pi(); + constexpr float pi = std::numbers::pi_v; + constexpr float sqrt2 = std::numbers::sqrt2_v; std::array result; int c = 0; - for (GLfloat i = 0; i < pi2; i += pi2 / 32, c++) { - result[c][0] = M_SQRT2*cosf(i); result[c][1] = M_SQRT2*sinf(i); + for (GLfloat i = 0; i < 2 * pi; i += 2 * pi / 32, c++) { + result[c][0] = sqrt2 * cosf(i); + result[c][1] = sqrt2 * sinf(i); } return result; }(); static const std::array small_oval = []{ - static const float pi2 = boost::math::constants::two_pi(); + constexpr float pi = std::numbers::pi_v; + constexpr float sqrt2 = std::numbers::sqrt2_v; + static const float sqrt1_2 = std::sqrt(1 / 2.F); + std::array result; int c = 0; - for (GLfloat i = 0; i < pi2; i += pi2 / 32, c++) { - result[c][0] = 0.3*M_SQRT2*cosf(i); result[c][1] = M_SQRT1_2*sinf(i); + for (GLfloat i = 0; i < 2 * pi; i += 2 * pi / 32, c++) { + result[c][0] = 0.3 * sqrt2 * cosf(i); + result[c][1] = sqrt1_2 * sinf(i); } return result; }(); diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index 2780fdc703..5cff61a54d 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -23,7 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include -# include +# include # ifdef FC_OS_WIN32 # include # endif @@ -553,7 +553,7 @@ void NaviCubeImplementation::addButtonFace(PickId pickId, const SbVec3f& directi case PickId::DotBackside: { int steps = 16; for (int i = 0; i < steps; i++) { - float angle = 2.0f * M_PI * ((float)i+0.5) / (float)steps; + float angle = 2.0f * std::numbers::pi_v * ((float)i+0.5) / (float)steps; pointData.emplace_back(10. * cos(angle) + 87.); pointData.emplace_back(10. * sin(angle) - 87.); } @@ -659,8 +659,8 @@ void NaviCubeImplementation::setSize(int size) void NaviCubeImplementation::prepare() { - static const float pi = boost::math::constants::pi(); - static const float pi1_2 = boost::math::constants::half_pi(); + constexpr float pi = std::numbers::pi_v; + constexpr float pi1_2 = pi / 2; createCubeFaceTextures(); @@ -817,7 +817,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode, float opacity) glOrtho(-2.1, 2.1, -2.1, 2.1, NEARVAL, FARVAL); } else { - const float dim = NEARVAL * float(tan(M_PI / 8.0)) * 1.1; + const float dim = NEARVAL * float(tan(std::numbers::pi / 8.0)) * 1.1; glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL); } glMatrixMode(GL_MODELVIEW); @@ -1010,15 +1010,11 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) { angle *= -1; } - static const float pi = boost::math::constants::pi(); - static const float pi2 = boost::math::constants::two_pi(); - static const float pi1_2 = boost::math::constants::half_pi(); - static const float pi1_3 = boost::math::constants::third_pi(); - static const float pi2_3 = boost::math::constants::two_thirds_pi(); + constexpr float pi = std::numbers::pi_v; // Make angle positive if (angle < 0) { - angle += pi2; + angle += 2 * pi; } // f is a small value used to control orientation priority when the camera is almost exactly between two @@ -1030,23 +1026,23 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) { // Find the angle to rotate to the nearest orientation if (m_Faces[pickId].type == ShapeId::Corner) { // 6 possible orientations for the corners - if (angle <= (M_PI / 6 + f)) { + if (angle <= (pi / 6 + f)) { angle = 0; } - else if (angle <= (M_PI_2 + f)) { - angle = pi1_3; + else if (angle <= (pi / 2 + f)) { + angle = pi / 3; } - else if (angle < (5 * M_PI / 6 - f)) { - angle = pi2_3; + else if (angle < (5 * pi / 6 - f)) { + angle = 2 * pi / 3; } - else if (angle <= (M_PI + M_PI / 6 + f)) { + else if (angle <= (pi + pi / 6 + f)) { angle = pi; } - else if (angle < (M_PI + M_PI_2 - f)) { - angle = pi + pi1_3; + else if (angle < (pi + pi / 2 - f)) { + angle = pi + pi / 3; } - else if (angle < (M_PI + 5 * M_PI / 6 - f)) { - angle = pi + pi2_3; + else if (angle < (pi + 5 * pi / 6 - f)) { + angle = pi + 2 * pi / 3; } else { angle = 0; @@ -1054,17 +1050,17 @@ SbRotation NaviCubeImplementation::getNearestOrientation(PickId pickId) { } else { // 4 possible orientations for the main and edge faces - if (angle <= (M_PI_4 + f)) { + if (angle <= (pi / 4 + f)) { angle = 0; } - else if (angle <= (3 * M_PI_4 + f)) { - angle = pi1_2; + else if (angle <= (3 * pi / 4 + f)) { + angle = pi / 2; } - else if (angle < (M_PI + M_PI_4 - f)) { + else if (angle < (pi + pi / 4 - f)) { angle = pi; } - else if (angle < (M_PI + 3 * M_PI_4 - f)) { - angle = pi + pi1_2; + else if (angle < (pi + 3 * pi / 4 - f)) { + angle = pi + pi / 2; } else { angle = 0; @@ -1089,7 +1085,7 @@ bool NaviCubeImplementation::mouseReleased(short x, short y) } else { PickId pickId = pickFace(x, y); long step = Base::clamp(long(m_NaviStepByTurn), 4L, 36L); - float rotStepAngle = (2 * M_PI) / step; + float rotStepAngle = (2 * std::numbers::pi) / step; if (m_Faces[pickId].type == ShapeId::Main || m_Faces[pickId].type == ShapeId::Edge || m_Faces[pickId].type == ShapeId::Corner) { // Handle the cube faces diff --git a/src/Gui/Navigation/NavigationAnimation.cpp b/src/Gui/Navigation/NavigationAnimation.cpp index 943af87706..29b0529006 100644 --- a/src/Gui/Navigation/NavigationAnimation.cpp +++ b/src/Gui/Navigation/NavigationAnimation.cpp @@ -25,6 +25,8 @@ #include "NavigationAnimation.h" #include +#include + using namespace Gui; NavigationAnimation::NavigationAnimation(NavigationStyle* navigation) @@ -69,8 +71,8 @@ void FixedTimeAnimation::initialize() SbVec3f rotationAxisPost; float angle; SbRotation(navigation->getCamera()->orientation.getValue().inverse() * targetOrientation).getValue(rotationAxisPost, angle); - if (angle > M_PI) { - angle -= float(2 * M_PI); + if (angle > std::numbers::pi) { + angle -= float(2 * std::numbers::pi); } // Convert post-multiplication axis to a pre-multiplication axis @@ -130,9 +132,9 @@ SpinningAnimation::SpinningAnimation(NavigationStyle* navigation, const SbVec3f& : NavigationAnimation(navigation) , rotationAxis(axis) { - setDuration((2 * M_PI / velocity) * 1000.0); + setDuration((2 * std::numbers::pi / velocity) * 1000.0); setStartValue(0.0); - setEndValue(2 * M_PI); + setEndValue(2 * std::numbers::pi); setLoopCount(-1); } diff --git a/src/Gui/Navigation/NavigationStyle.cpp b/src/Gui/Navigation/NavigationStyle.cpp index 3f48db267d..9a0e3fca08 100644 --- a/src/Gui/Navigation/NavigationStyle.cpp +++ b/src/Gui/Navigation/NavigationStyle.cpp @@ -39,6 +39,9 @@ # include #endif +#include +#include + #include #include @@ -719,7 +722,8 @@ void NavigationStyle::zoom(SoCamera * cam, float diffvalue) const float distorigo = newpos.length(); // sqrt(FLT_MAX) == ~ 1e+19, which should be both safe for further // calculations and ok for the end-user and app-programmer. - if (distorigo > float(sqrt(FLT_MAX))) { + float maxDistance = std::sqrt(std::numeric_limits::max()); + if (distorigo > maxDistance) { // do nothing here } else { diff --git a/src/Gui/OverlayManager.cpp b/src/Gui/OverlayManager.cpp index f7b437e54b..41cb897bc8 100644 --- a/src/Gui/OverlayManager.cpp +++ b/src/Gui/OverlayManager.cpp @@ -1819,7 +1819,7 @@ bool OverlayManager::eventFilter(QObject *o, QEvent *ev) } if (hit <= 0) { - d->_lastPos.setX(INT_MAX); + d->_lastPos.setX(std::numeric_limits::max()); if (ev->type() == QEvent::Wheel) { d->wheelDelay = QTime::currentTime().addMSecs(OverlayParams::getDockOverlayWheelDelay()); d->wheelPos = pos; diff --git a/src/Gui/PreCompiled.h b/src/Gui/PreCompiled.h index c3a5f43345..c665016cf7 100644 --- a/src/Gui/PreCompiled.h +++ b/src/Gui/PreCompiled.h @@ -50,8 +50,6 @@ #include #include #include -#include -#include #ifdef FC_OS_WIN32 #include @@ -69,6 +67,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp b/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp index 0c395195e6..9e5bd6b5ba 100644 --- a/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp +++ b/src/Gui/PreferencePages/DlgSettingsCacheDirectory.cpp @@ -182,7 +182,7 @@ void ApplicationCache::setPeriod(ApplicationCache::Period period) numDays = 365; break; case Period::Never: - numDays = INT_MAX; + numDays = std::numeric_limits::max(); break; } } diff --git a/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp b/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp index 4297531a3f..cb352c303f 100644 --- a/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp +++ b/src/Gui/PreferencePages/DlgSettingsDocumentImp.cpp @@ -60,7 +60,7 @@ DlgSettingsDocumentImp::DlgSettingsDocumentImp(QWidget* parent) ui->prefSaveBackupDateFormat->setToolTip(tip); ui->FormatTimeDocsLabel->setText(link); - ui->prefCountBackupFiles->setMaximum(INT_MAX); + ui->prefCountBackupFiles->setMaximum(std::numeric_limits::max()); ui->prefCompression->setMinimum(Z_NO_COMPRESSION); ui->prefCompression->setMaximum(Z_BEST_COMPRESSION); connect(ui->prefLicenseType, qOverload(&QComboBox::currentIndexChanged), diff --git a/src/Gui/QuantitySpinBox.cpp b/src/Gui/QuantitySpinBox.cpp index abfbb04e34..cc18e8be11 100644 --- a/src/Gui/QuantitySpinBox.cpp +++ b/src/Gui/QuantitySpinBox.cpp @@ -66,8 +66,8 @@ public: pendingEmit(false), checkRangeInExpression(false), unitValue(0), - maximum(DOUBLE_MAX), - minimum(-DOUBLE_MAX), + maximum(std::numeric_limits::max()), + minimum(-std::numeric_limits::max()), singleStep(1.0), q_ptr(q) { diff --git a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp index ecfbf9a142..e98bd2d77f 100644 --- a/src/Gui/Quarter/SoQTQuarterAdaptor.cpp +++ b/src/Gui/Quarter/SoQTQuarterAdaptor.cpp @@ -20,6 +20,8 @@ #include "PreCompiled.h" +#include + #include #include #include @@ -303,7 +305,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So SbRotation camrot = in->orientation.getValue(); - float focaldist = float(in->height.getValue() / (2.0*tan(M_PI / 8.0))); // NOLINT + float focaldist = float(in->height.getValue() / (2.0*tan(std::numbers::pi / 8.0))); // NOLINT SbVec3f offset(0,0,focaldist-in->focalDistance.getValue()); @@ -313,7 +315,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertOrtho2Perspective(const So out->focalDistance.setValue(focaldist); // 45° is the default value of this field in SoPerspectiveCamera. - out->heightAngle = (float)(M_PI / 4.0); // NOLINT + out->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT } void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::convertPerspective2Ortho(const SoPerspectiveCamera* in, @@ -568,7 +570,7 @@ void SIM::Coin3D::Quarter::SoQTQuarterAdaptor::seeksensorCB(void* data, SoSensor bool end = (par == 1.0F); - par = (float)((1.0 - cos(M_PI * par)) * 0.5); // NOLINT + par = (float)((1.0 - cos(std::numbers::pi * par)) * 0.5); // NOLINT thisp->getSoRenderManager()->getCamera()->position = thisp->m_camerastartposition + (thisp->m_cameraendposition - thisp->m_camerastartposition) * par; diff --git a/src/Gui/Selection/SelectionFilter.h b/src/Gui/Selection/SelectionFilter.h index 90d3430bb7..563acd90af 100644 --- a/src/Gui/Selection/SelectionFilter.h +++ b/src/Gui/Selection/SelectionFilter.h @@ -172,8 +172,9 @@ private: struct Node_Slice { - explicit Node_Slice(int min=1,int max=INT_MAX):Min(min),Max(max){} - int Min,Max; + explicit Node_Slice(int min = 1, int max = std::numeric_limits::max()) + : Min(min), Max(max) {} + int Min, Max; }; diff --git a/src/Gui/Selection/SoFCSelectionContext.h b/src/Gui/Selection/SoFCSelectionContext.h index 3d92e00b1a..d9cb345bbf 100644 --- a/src/Gui/Selection/SoFCSelectionContext.h +++ b/src/Gui/Selection/SoFCSelectionContext.h @@ -23,7 +23,6 @@ #ifndef GUI_SOFCSELECTIONCONTEXT_H #define GUI_SOFCSELECTIONCONTEXT_H -#include #include #include #include @@ -79,11 +78,11 @@ struct GuiExport SoFCSelectionContext : SoFCSelectionContextBase } bool isHighlightAll() const{ - return highlightIndex==INT_MAX && (selectionIndex.empty() || isSelectAll()); + return highlightIndex == std::numeric_limits::max() && (selectionIndex.empty() || isSelectAll()); } void highlightAll() { - highlightIndex = INT_MAX; + highlightIndex = std::numeric_limits::max(); } void removeHighlight() { diff --git a/src/Gui/ShortcutManager.cpp b/src/Gui/ShortcutManager.cpp index c7103f7c7a..2f49e8fd7d 100644 --- a/src/Gui/ShortcutManager.cpp +++ b/src/Gui/ShortcutManager.cpp @@ -409,7 +409,7 @@ void ShortcutManager::onTimer() timer.stop(); QAction *found = nullptr; - int priority = -INT_MAX; + int priority = -std::numeric_limits::max(); int seq_length = 0; for (const auto &info : pendingActions) { if (info.action) { diff --git a/src/Gui/SoDatumLabel.cpp b/src/Gui/SoDatumLabel.cpp index fff3978b6f..978a7721a1 100644 --- a/src/Gui/SoDatumLabel.cpp +++ b/src/Gui/SoDatumLabel.cpp @@ -34,8 +34,8 @@ # endif # include -# include # include +# include # include # include @@ -78,11 +78,12 @@ void glDrawLine(const SbVec3f& p1, const SbVec3f& p2){ glEnd(); } -void glDrawArc(const SbVec3f& center, float radius, float startAngle=0., float endAngle=2.0*M_PI, int countSegments=0){ +void glDrawArc(const SbVec3f& center, float radius, float startAngle=0., + float endAngle=2.0*std::numbers::pi, int countSegments=0){ float range = endAngle - startAngle; if (countSegments == 0){ - countSegments = std::max(6, abs(int(25.0 * range / M_PI))); + countSegments = std::max(6, abs(int(25.0 * range / std::numbers::pi))); } float segment = range / (countSegments-1); @@ -238,11 +239,12 @@ public: private: void getBBox(const std::vector& corners, SbBox3f& box, SbVec3f& center) const { + constexpr float floatMax = std::numeric_limits::max(); if (corners.size() > 1) { - float minX = FLT_MAX; - float minY = FLT_MAX; - float maxX = -FLT_MAX; - float maxY = -FLT_MAX; + float minX = floatMax; + float minY = floatMax; + float maxX = -floatMax; + float maxY = -floatMax; for (SbVec3f it : corners) { minX = (it[0] < minX) ? it[0] : minX; minY = (it[1] < minY) ? it[1] : minY; @@ -288,14 +290,15 @@ private: SbVec3f dir; SbVec3f normal; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (label->datumtype.getValue() == SoDatumLabel::DISTANCE) { dir = (p2-p1); } else if (label->datumtype.getValue() == SoDatumLabel::DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (label->datumtype.getValue() == SoDatumLabel::DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -546,11 +549,11 @@ private: float startangle = atan2f(vc1[1], vc1[0]); float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2. * M_PI; + endangle += 2. * std::numbers::pi; } SbVec3f textCenter; - if (endangle - startangle <= M_PI) { + if (endangle - startangle <= std::numbers::pi) { textCenter = ctr + vm * (length + imgHeight); } else { textCenter = ctr - vm * (length + 2. * imgHeight); @@ -628,14 +631,16 @@ SbVec3f SoDatumLabel::getLabelTextCenterDistance(const SbVec3f& p1, const SbVec3 SbVec3f dir; SbVec3f normal; + + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (datumtype.getValue() == SoDatumLabel::DISTANCE) { dir = (p2 - p1); } else if (datumtype.getValue() == SoDatumLabel::DISTANCEX) { - dir = SbVec3f((p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f((p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (datumtype.getValue() == SoDatumLabel::DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -689,7 +694,7 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2. * M_PI; + endangle += 2. * std::numbers::pi; } // Text location @@ -697,7 +702,7 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe vm.normalize(); SbVec3f textCenter; - if (endangle - startangle <= M_PI) { + if (endangle - startangle <= std::numbers::pi) { textCenter = ctr + vm * (length + this->imgHeight); } else { textCenter = ctr - vm * (length + 2. * this->imgHeight); @@ -709,12 +714,13 @@ SbVec3f SoDatumLabel::getLabelTextCenterArcLength(const SbVec3f& ctr, const SbVe void SoDatumLabel::generateDistancePrimitives(SoAction * action, const SbVec3f& p1, const SbVec3f& p2) { SbVec3f dir; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (this->datumtype.getValue() == DISTANCE) { dir = (p2-p1); } else if (this->datumtype.getValue() == DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (this->datumtype.getValue() == DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -957,7 +963,8 @@ void SoDatumLabel::generateArcLengthPrimitives(SoAction * action, const SbVec3f& void SoDatumLabel::generatePrimitives(SoAction * action) { // Initialisation check (needs something more sensible) prevents an infinite loop bug - if (this->imgHeight <= FLT_EPSILON || this->imgWidth <= FLT_EPSILON) { + constexpr float floatEpsilon = std::numeric_limits::epsilon(); + if (this->imgHeight <= floatEpsilon | this->imgWidth <= floatEpsilon) { return; } @@ -1161,6 +1168,8 @@ void SoDatumLabel::getDimension(float scale, int& srcw, int& srch) void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, float& angle, SbVec3f& textOffset) { + using std::numbers::pi; + float length = this->param1.getValue(); float length2 = this->param2.getValue(); @@ -1168,12 +1177,13 @@ void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, fl SbVec3f p2 = points[1]; SbVec3f dir; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); if (this->datumtype.getValue() == DISTANCE) { dir = (p2-p1); } else if (this->datumtype.getValue() == DISTANCEX) { - dir = SbVec3f( (p2[0] - p1[0] >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = SbVec3f( (p2[0] - p1[0] >= floatEpsilon) ? 1 : -1, 0, 0); } else if (this->datumtype.getValue() == DISTANCEY) { - dir = SbVec3f(0, (p2[1] - p1[1] >= FLT_EPSILON) ? 1 : -1, 0); + dir = SbVec3f(0, (p2[1] - p1[1] >= floatEpsilon) ? 1 : -1, 0); } dir.normalize(); @@ -1192,10 +1202,10 @@ void SoDatumLabel::drawDistance(const SbVec3f* points, float scale, int srch, fl // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > pi/2 + pi/12) { + angle -= (float)pi; + } else if (angle <= -pi/2 + pi/12) { + angle += (float)pi; } textOffset = midpos + normal * length + dir * length2; @@ -1291,7 +1301,7 @@ void SoDatumLabel::drawDistance(const SbVec3f* points) float startangle1 = this->param3.getValue(); float radius1 = this->param5.getValue(); SbVec3f center = points[2]; - int countSegments = std::max(6, abs(int(50.0 * range1 / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range1 / (2 * std::numbers::pi)))); double segment = range1 / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1307,7 +1317,7 @@ void SoDatumLabel::drawDistance(const SbVec3f* points) float startangle2 = this->param6.getValue(); float radius2 = this->param8.getValue(); SbVec3f center = points[3]; - int countSegments = std::max(6, abs(int(50.0 * range2 / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range2 / (2 * std::numbers::pi)))); double segment = range2 / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1342,10 +1352,10 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > std::numbers::pi/2 + std::numbers::pi/12) { + angle -= (float)std::numbers::pi; + } else if (angle <= -std::numbers::pi/2 + std::numbers::pi/12) { + angle += (float)std::numbers::pi; } textOffset = pos; @@ -1401,7 +1411,7 @@ void SoDatumLabel::drawRadiusOrDiameter(const SbVec3f* points, float& angle, SbV float startangle = this->param3.getValue(); float range = this->param4.getValue(); if (range != 0.0) { - int countSegments = std::max(6, abs(int(50.0 * range / (2 * M_PI)))); + int countSegments = std::max(6, abs(int(50.0 * range / (2 * std::numbers::pi)))); double segment = range / (countSegments - 1); glBegin(GL_LINE_STRIP); @@ -1521,6 +1531,8 @@ void SoDatumLabel::drawSymmetric(const SbVec3f* points) void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& textOffset) { + using std::numbers::pi; + SbVec3f ctr = points[0]; SbVec3f p1 = points[1]; SbVec3f p2 = points[2]; @@ -1535,7 +1547,7 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t float startangle = atan2f(vc1[1], vc1[0]); float endangle = atan2f(vc2[1], vc2[0]); if (endangle < startangle) { - endangle += 2.0F * (float)M_PI; + endangle += 2.0F * (float)pi; } float range = endangle - startangle; @@ -1547,10 +1559,10 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t dir.normalize(); // Get magnitude of angle between horizontal angle = atan2f(dir[1],dir[0]); - if (angle > M_PI_2+M_PI/12) { - angle -= (float)M_PI; - } else if (angle <= -M_PI_2+M_PI/12) { - angle += (float)M_PI; + if (angle > pi/2 + pi/12) { + angle -= (float)pi; + } else if (angle <= -pi/2 + pi/12) { + angle += (float)pi; } // Text location textOffset = getLabelTextCenterArcLength(ctr, p1, p2); @@ -1566,7 +1578,7 @@ void SoDatumLabel::drawArcLength(const SbVec3f* points, float& angle, SbVec3f& t SbVec3f pnt4 = p2 + (length-radius) * vm; // Draw arc - if (range <= M_PI) { + if (range <= pi) { glDrawArc(ctr + (length-radius)*vm, radius, startangle, endangle); } else { @@ -1606,7 +1618,7 @@ void SoDatumLabel::drawText(SoState *state, int srcw, int srch, float angle, con const SbViewVolume & vv = SoViewVolumeElement::get(state); SbVec3f z = vv.zVector(); - bool flip = norm.getValue().dot(z) > FLT_EPSILON; + bool flip = norm.getValue().dot(z) > std::numeric_limits::epsilon(); static bool init = false; static bool npot = false; @@ -1678,7 +1690,7 @@ void SoDatumLabel::drawText(SoState *state, int srcw, int srch, float angle, con // Apply a rotation and translation matrix glTranslatef(textOffset[0], textOffset[1], textOffset[2]); - glRotatef((GLfloat) angle * 180 / M_PI, 0,0,1); + glRotatef((GLfloat) angle * 180 / std::numbers::pi, 0,0,1); glBegin(GL_QUADS); glColor3f(1.F, 1.F, 1.F); diff --git a/src/Gui/SoFCCSysDragger.cpp b/src/Gui/SoFCCSysDragger.cpp index 39130d3b9e..21142b5def 100644 --- a/src/Gui/SoFCCSysDragger.cpp +++ b/src/Gui/SoFCCSysDragger.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include +#include #include #include @@ -743,7 +744,7 @@ RDragger::RDragger() } SO_KIT_ADD_FIELD(rotation, (SbVec3f(0.0, 0.0, 1.0), 0.0)); - SO_KIT_ADD_FIELD(rotationIncrement, (M_PI / 8.0)); + SO_KIT_ADD_FIELD(rotationIncrement, (std::numbers::pi / 8.0)); SO_KIT_ADD_FIELD(rotationIncrementCount, (0)); SO_KIT_INIT_INSTANCE(); @@ -808,7 +809,7 @@ SoGroup* RDragger::buildGeometry() unsigned int segments = 15; - float angleIncrement = static_cast(M_PI / 2.0) / static_cast(segments); + float angleIncrement = (std::numbers::pi_v / 2.f) / static_cast(segments); SbRotation rotation(SbVec3f(0.0, 0.0, 1.0), angleIncrement); SbVec3f point(arcRadius, 0.0, 0.0); for (unsigned int index = 0; index <= segments; ++index) { @@ -965,9 +966,10 @@ void RDragger::drag() appendRotation(getStartMotionMatrix(), localRotation, SbVec3f(0.0, 0.0, 0.0))); } - Base::Quantity quantity(static_cast(rotationIncrementCount.getValue()) * (180.0 / M_PI) - * rotationIncrement.getValue(), - Base::Unit::Angle); + Base::Quantity quantity( + static_cast(rotationIncrementCount.getValue()) + * (180.0 / std::numbers::pi)* rotationIncrement.getValue(), + Base::Unit::Angle); QString message = QStringLiteral("%1 %2").arg(QObject::tr("Rotation:"), QString::fromStdString(quantity.getUserString())); @@ -1179,7 +1181,7 @@ SoFCCSysDragger::SoFCCSysDragger() SO_KIT_ADD_FIELD(translationIncrementCountZ, (0)); SO_KIT_ADD_FIELD(rotation, (SbVec3f(0.0, 0.0, 1.0), 0.0)); - SO_KIT_ADD_FIELD(rotationIncrement, (M_PI / 8.0)); + SO_KIT_ADD_FIELD(rotationIncrement, (std::numbers::pi / 8.0)); SO_KIT_ADD_FIELD(rotationIncrementCountX, (0)); SO_KIT_ADD_FIELD(rotationIncrementCountY, (0)); SO_KIT_ADD_FIELD(rotationIncrementCountZ, (0)); @@ -1272,7 +1274,7 @@ SoFCCSysDragger::SoFCCSysDragger() SoRotation* localRotation; SbRotation tempRotation; - auto angle = static_cast(M_PI / 2.0); + auto angle = static_cast(std::numbers::pi / 2.0); // Translator localRotation = SO_GET_ANY_PART(this, "xTranslatorRotation", SoRotation); localRotation->rotation.setValue(SbVec3f(0.0, 0.0, -1.0), angle); diff --git a/src/Gui/SoTextLabel.cpp b/src/Gui/SoTextLabel.cpp index 695ba378e3..037f75b6f4 100644 --- a/src/Gui/SoTextLabel.cpp +++ b/src/Gui/SoTextLabel.cpp @@ -31,7 +31,6 @@ # else # include # endif -# include # include # include # include diff --git a/src/Gui/SoTouchEvents.cpp b/src/Gui/SoTouchEvents.cpp index 628fb089c3..8b99c606e8 100644 --- a/src/Gui/SoTouchEvents.cpp +++ b/src/Gui/SoTouchEvents.cpp @@ -22,6 +22,8 @@ #include "PreCompiled.h" +#include + #include #include #include @@ -86,8 +88,8 @@ SoGesturePinchEvent::SoGesturePinchEvent(QPinchGesture* qpinch, QWidget *widget) deltaZoom = qpinch->scaleFactor(); totalZoom = qpinch->totalScaleFactor(); - deltaAngle = -unbranchAngle((qpinch->rotationAngle()-qpinch->lastRotationAngle()) / 180.0 * M_PI); - totalAngle = -qpinch->totalRotationAngle() / 180 * M_PI; + deltaAngle = -unbranchAngle((qpinch->rotationAngle()-qpinch->lastRotationAngle()) / 180.0 * std::numbers::pi); + totalAngle = -qpinch->totalRotationAngle() / 180 * std::numbers::pi; state = SbGestureState(qpinch->state()); @@ -111,7 +113,9 @@ SbBool SoGesturePinchEvent::isSoGesturePinchEvent(const SoEvent *ev) const */ double SoGesturePinchEvent::unbranchAngle(double ang) { - return ang - 2.0 * M_PI * floor((ang + M_PI) / (2.0 * M_PI)); + using std::numbers::pi; + + return ang - 2.0 * pi * floor((ang + pi) / (2.0 * pi)); } diff --git a/src/Gui/SpinBox.cpp b/src/Gui/SpinBox.cpp index 207ec81335..a4fdb99add 100644 --- a/src/Gui/SpinBox.cpp +++ b/src/Gui/SpinBox.cpp @@ -238,7 +238,7 @@ UnsignedValidator::UnsignedValidator( QObject * parent ) : QValidator( parent ) { b = 0; - t = UINT_MAX; + t = std::numeric_limits::max(); } UnsignedValidator::UnsignedValidator( uint minimum, uint maximum, QObject * parent ) @@ -295,27 +295,31 @@ public: uint mapToUInt( int v ) const { uint ui; - if ( v == INT_MIN ) { + if ( v == std::numeric_limits::min() ) { ui = 0; - } else if ( v == INT_MAX ) { - ui = UINT_MAX; + } else if ( v == std::numeric_limits::max() ) { + ui = std::numeric_limits::max(); } else if ( v < 0 ) { - v -= INT_MIN; ui = (uint)v; + v -= std::numeric_limits::min(); + ui = static_cast(v); } else { - ui = (uint)v; ui -= INT_MIN; + ui = static_cast(v); + ui -= std::numeric_limits::min(); } return ui; } int mapToInt( uint v ) const { int in; - if ( v == UINT_MAX ) { - in = INT_MAX; + if ( v == std::numeric_limits::max() ) { + in = std::numeric_limits::max(); } else if ( v == 0 ) { - in = INT_MIN; - } else if ( v > INT_MAX ) { - v += INT_MIN; in = (int)v; + in = std::numeric_limits::min(); + } else if ( v > std::numeric_limits::max() ) { + v += std::numeric_limits::min(); + in = static_cast(v); } else { - in = v; in += INT_MIN; + in = v; + in += std::numeric_limits::min(); } return in; } }; diff --git a/src/Gui/Transform.cpp b/src/Gui/Transform.cpp index e1d22d1105..b6b0e68b81 100644 --- a/src/Gui/Transform.cpp +++ b/src/Gui/Transform.cpp @@ -378,6 +378,7 @@ Base::Vector3d Transform::getDirection() const Base::Placement Transform::getPlacementData() const { + using std::numbers::pi; int index = ui->rotationInput->currentIndex(); Base::Rotation rot; Base::Vector3d pos; @@ -388,7 +389,7 @@ Base::Placement Transform::getPlacementData() const if (index == 0) { Base::Vector3d dir = getDirection(); - rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value().getValue()*D_PI/180.0); + rot.setValue(Base::Vector3d(dir.x,dir.y,dir.z),ui->angle->value().getValue()*pi/180.0); } else if (index == 1) { rot.setYawPitchRoll( diff --git a/src/Gui/VectorListEditor.cpp b/src/Gui/VectorListEditor.cpp index 9450145b7f..0e432920d1 100644 --- a/src/Gui/VectorListEditor.cpp +++ b/src/Gui/VectorListEditor.cpp @@ -255,8 +255,8 @@ QWidget *VectorTableDelegate::createEditor(QWidget *parent, const QStyleOptionVi { auto editor = new QDoubleSpinBox(parent); editor->setDecimals(decimals); - editor->setMinimum(INT_MIN); - editor->setMaximum(INT_MAX); + editor->setMinimum(std::numeric_limits::min()); + editor->setMaximum(std::numeric_limits::max()); editor->setSingleStep(0.1); return editor; @@ -299,11 +299,14 @@ VectorListEditor::VectorListEditor(int decimals, QWidget* parent) ui->tableWidget->setModel(model); ui->widget->hide(); - ui->coordX->setRange(INT_MIN, INT_MAX); + ui->coordX->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordX->setDecimals(decimals); - ui->coordY->setRange(INT_MIN, INT_MAX); + ui->coordY->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordY->setDecimals(decimals); - ui->coordZ->setRange(INT_MIN, INT_MAX); + ui->coordZ->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); ui->coordZ->setDecimals(decimals); ui->toolButtonMouse->setDisabled(true); diff --git a/src/Gui/View3DInventorRiftViewer.cpp b/src/Gui/View3DInventorRiftViewer.cpp index 7dc8c49a62..3dd1a92647 100644 --- a/src/Gui/View3DInventorRiftViewer.cpp +++ b/src/Gui/View3DInventorRiftViewer.cpp @@ -43,7 +43,7 @@ View3DInventorRiftViewer::View3DInventorRiftViewer() : CoinRiftWidget() rotation1 = new SoRotationXYZ ; rotation1->axis.setValue(SoRotationXYZ::X); - rotation1->angle.setValue(-M_PI/2); + rotation1->angle.setValue(-std::numbers::pi/2); workplace->addChild(rotation1); rotation2 = new SoRotationXYZ ; @@ -104,7 +104,7 @@ void View3DInventorRiftViewer::setSceneGraph(SoNode *sceneGraph) void View3DInventorRiftViewer::keyPressEvent(QKeyEvent *event) { static const float increment = 0.02; // move two centimeter per key - static const float rotIncrement = M_PI/4; // move two 90° per key + static const float rotIncrement = std::numbers::pi / 4; // move two 90° per key if (event->key() == Qt::Key_Plus) { diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index f8c3e5df70..078abfa336 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # ifdef FC_OS_WIN32 # include # endif @@ -3262,7 +3261,7 @@ void View3DInventorViewer::setCameraType(SoType type) // heightAngle. Setting it to 45 deg also causes an issue with a too // close camera but we don't have this other ugly effect. - static_cast(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT + static_cast(cam)->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT } lightRotation->rotation.connectFrom(&cam->orientation); @@ -3421,7 +3420,7 @@ void View3DInventorViewer::viewAll() SoCamera* cam = this->getSoRenderManager()->getCamera(); if (cam && cam->getTypeId().isDerivedFrom(SoPerspectiveCamera::getClassTypeId())) { - static_cast(cam)->heightAngle = (float)(M_PI / 4.0); // NOLINT + static_cast(cam)->heightAngle = (float)(std::numbers::pi / 4.0); // NOLINT } if (isAnimationEnabled()) { @@ -3605,26 +3604,28 @@ void View3DInventorViewer::alignToSelection() angle *= -1; } + using std::numbers::pi; + // Make angle positive if (angle < 0) { - angle += 2 * M_PI; + angle += 2 * pi; } // Find the angle to rotate to the nearest horizontal or vertical alignment with directionX. // f is a small value used to get more deterministic behavior when the camera is at directionX +- 45 degrees. const float f = 0.00001F; - if (angle <= M_PI_4 + f) { + if (angle <= pi/4 + f) { angle = 0; } - else if (angle <= 3 * M_PI_4 + f) { - angle = M_PI_2; + else if (angle <= 3 * pi/4 + f) { + angle = pi/2; } - else if (angle < M_PI + M_PI_4 - f) { - angle = M_PI; + else if (angle < pi + pi/4 - f) { + angle = pi; } - else if (angle < M_PI + 3 * M_PI_4 - f) { - angle = M_PI + M_PI_2; + else if (angle < pi + 3 * pi/4 - f) { + angle = pi + pi/2; } else { angle = 0; @@ -3933,7 +3934,7 @@ void View3DInventorViewer::drawAxisCross() const float NEARVAL = 0.1F; const float FARVAL = 10.0F; - const float dim = NEARVAL * float(tan(M_PI / 8.0)); // FOV is 45 deg (45/360 = 1/8) + const float dim = NEARVAL * float(tan(std::numbers::pi / 8.0)); // FOV is 45 deg (45/360 = 1/8) glFrustum(-dim, dim, -dim, dim, NEARVAL, FARVAL); diff --git a/src/Gui/View3DPy.cpp b/src/Gui/View3DPy.cpp index b99918ddba..dab66a874b 100644 --- a/src/Gui/View3DPy.cpp +++ b/src/Gui/View3DPy.cpp @@ -658,7 +658,7 @@ Py::Object View3DInventorPy::viewRotateLeft() SbRotation rot = cam->orientation.getValue(); SbVec3f vdir(0, 0, -1); rot.multVec(vdir, vdir); - SbRotation nrot(vdir, (float)M_PI/2); + SbRotation nrot(vdir, (float)std::numbers::pi/2); cam->orientation.setValue(rot*nrot); } catch (const Base::Exception& e) { @@ -681,7 +681,7 @@ Py::Object View3DInventorPy::viewRotateRight() SbRotation rot = cam->orientation.getValue(); SbVec3f vdir(0, 0, -1); rot.multVec(vdir, vdir); - SbRotation nrot(vdir, (float)-M_PI/2); + SbRotation nrot(vdir, (float)-std::numbers::pi/2); cam->orientation.setValue(rot*nrot); } catch (const Base::Exception& e) { diff --git a/src/Gui/ViewProviderAnnotation.cpp b/src/Gui/ViewProviderAnnotation.cpp index 785a96f368..5e110f90c6 100644 --- a/src/Gui/ViewProviderAnnotation.cpp +++ b/src/Gui/ViewProviderAnnotation.cpp @@ -155,7 +155,7 @@ void ViewProviderAnnotation::onChanged(const App::Property* prop) } } else if (prop == &Rotation) { - pRotationXYZ->angle = (Rotation.getValue()/360)*(2*M_PI); + pRotationXYZ->angle = (Rotation.getValue()/360)*(2*std::numbers::pi); } else { ViewProviderDocumentObject::onChanged(prop); diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index e07d3fdf20..94bbd659f7 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -968,7 +968,8 @@ QWidget* PropertyIntegerItem::createEditor(QWidget* parent, void PropertyIntegerItem::setEditorData(QWidget* editor, const QVariant& data) const { auto sb = qobject_cast(editor); - sb->setRange(INT_MIN, INT_MAX); + sb->setRange(std::numeric_limits::min(), + std::numeric_limits::max()); sb->setValue(data.toInt()); } @@ -1128,7 +1129,8 @@ QWidget* PropertyFloatItem::createEditor(QWidget* parent, const std::function(editor); - sb->setRange((double)INT_MIN, (double)INT_MAX); + sb->setRange(static_cast(std::numeric_limits::min()), + static_cast(std::numeric_limits::max())); sb->setValue(data.toDouble()); } diff --git a/src/Gui/propertyeditor/PropertyItem.h b/src/Gui/propertyeditor/PropertyItem.h index c27300cadb..b8182c4fd8 100644 --- a/src/Gui/propertyeditor/PropertyItem.h +++ b/src/Gui/propertyeditor/PropertyItem.h @@ -360,8 +360,8 @@ protected: PropertyIntegerConstraintItem(); private: - int min = INT_MIN; - int max = INT_MAX; + int min = std::numeric_limits::min(); + int max = std::numeric_limits::max(); int steps = 1; }; @@ -434,8 +434,8 @@ protected: PropertyUnitConstraintItem(); private: - double min = double(INT_MIN); - double max = double(INT_MAX); + double min = static_cast(std::numeric_limits::min()); + double max = static_cast(std::numeric_limits::max()); double steps = 0.1; }; @@ -472,8 +472,8 @@ protected: PropertyFloatConstraintItem(); private: - double min = double(INT_MIN); - double max = double(INT_MAX); + double min = static_cast(std::numeric_limits::min()); + double max = static_cast(std::numeric_limits::max()); double steps = 0.1; }; diff --git a/src/Gui/propertyeditor/PropertyModel.cpp b/src/Gui/propertyeditor/PropertyModel.cpp index bb5e565f8d..aa93d2563a 100644 --- a/src/Gui/propertyeditor/PropertyModel.cpp +++ b/src/Gui/propertyeditor/PropertyModel.cpp @@ -96,7 +96,7 @@ bool PropertyModel::setData(const QModelIndex& index, const QVariant& value, int // now? double d = data.toDouble(); double v = value.toDouble(); - if (fabs(d - v) > DBL_EPSILON) { + if (fabs(d - v) > std::numeric_limits::epsilon()) { return item->setData(value); } } diff --git a/src/Mod/Assembly/App/AssemblyObject.cpp b/src/Mod/Assembly/App/AssemblyObject.cpp index 910101a8bf..495536f6c8 100644 --- a/src/Mod/Assembly/App/AssemblyObject.cpp +++ b/src/Mod/Assembly/App/AssemblyObject.cpp @@ -1120,7 +1120,7 @@ std::shared_ptr AssemblyObject::makeMbdJointOfType(App::DocumentObjec } else if (type == JointType::Angle) { double angle = fabs(Base::toRadians(getJointDistance(joint))); - if (fmod(angle, 2 * M_PI) < Precision::Confusion()) { + if (fmod(angle, 2 * std::numbers::pi) < Precision::Confusion()) { return CREATE::With(); } else { diff --git a/src/Mod/CAM/App/Area.cpp b/src/Mod/CAM/App/Area.cpp index df87a8f527..82892eef4d 100644 --- a/src/Mod/CAM/App/Area.cpp +++ b/src/Mod/CAM/App/Area.cpp @@ -26,7 +26,6 @@ #define BOOST_GEOMETRY_DISABLE_DEPRECATED_03_WARNING #ifndef _PreComp_ -#include #include #include @@ -452,7 +451,7 @@ void Area::addWire(CArea& area, if (reversed) { type = -type; } - if (fabs(first - last) > M_PI) { + if (fabs(first - last) > std::numbers::pi) { // Split arc(circle) larger than half circle. Because gcode // can't handle full circle? gp_Pnt mid = curve.Value((last - first) * 0.5 + first); @@ -1221,7 +1220,8 @@ struct WireJoiner info.iEnd[i] = info.iStart[i] = (int)adjacentList.size(); // populate adjacent list - for (auto vit = vmap.qbegin(bgi::nearest(pt[i], INT_MAX)); vit != vmap.qend(); + constexpr int intMax = std::numeric_limits::max(); + for (auto vit = vmap.qbegin(bgi::nearest(pt[i], intMax)); vit != vmap.qend(); ++vit) { ++rcount; if (vit->pt().SquareDistance(pt[i]) > tol) { @@ -2631,7 +2631,7 @@ TopoDS_Shape Area::makePocket(int index, PARAM_ARGS(PARAM_FARG, AREA_PARAMS_POCK for (int j = 0; j < steps; ++j, offset += stepover) { Point p1(-r, offset), p2(r, offset); if (a > Precision::Confusion()) { - double r = a * M_PI / 180.0; + double r = a * std::numbers::pi / 180.0; p1.Rotate(r); p2.Rotate(r); } @@ -3703,7 +3703,7 @@ std::list Area::sortWires(const std::list& shapes, double max_dist = sort_mode == SortModeGreedy ? threshold * threshold : 0; while (!shape_list.empty()) { AREA_TRACE("sorting " << shape_list.size() << ' ' << AREA_XYZ(pstart)); - double best_d = DBL_MAX; + double best_d = std::numeric_limits::max(); auto best_it = shape_list.begin(); for (auto it = best_it; it != shape_list.end(); ++it) { double d; @@ -4155,7 +4155,7 @@ void Area::toPath(Toolpath& path, } } - if (fabs(first - last) > M_PI) { + if (fabs(first - last) > std::numbers::pi) { // Split arc(circle) larger than half circle. gp_Pnt mid = curve.Value((last - first) * 0.5 + first); addGArc(verbose, diff --git a/src/Mod/CAM/App/PathSegmentWalker.cpp b/src/Mod/CAM/App/PathSegmentWalker.cpp index 2cd883ef09..5b9a54b6cb 100644 --- a/src/Mod/CAM/App/PathSegmentWalker.cpp +++ b/src/Mod/CAM/App/PathSegmentWalker.cpp @@ -31,14 +31,6 @@ #define ARC_MIN_SEGMENTS 20.0 // minimum # segments to interpolate an arc -#ifndef M_PI -#define M_PI 3.14159265358979323846 /* pi */ -#endif - -#ifndef M_PI_2 -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#endif - namespace Path { @@ -195,7 +187,7 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start if (nrot != lrot) { double amax = std::max(fmod(fabs(a - A), 360), std::max(fmod(fabs(b - B), 360), fmod(fabs(c - C), 360))); - double angle = amax / 180 * M_PI; + double angle = amax / 180 * std::numbers::pi; int segments = std::max(ARC_MIN_SEGMENTS, 3.0 / (deviation / angle)); double da = (a - A) / segments; @@ -257,16 +249,16 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start Base::Vector3d anorm = (last0 - center0) % (next0 - center0); if (anorm.*pz < 0) { if (name == "G3" || name == "G03") { - angle = M_PI * 2 - angle; + angle = std::numbers::pi * 2 - angle; } } else if (anorm.*pz > 0) { if (name == "G2" || name == "G02") { - angle = M_PI * 2 - angle; + angle = std::numbers::pi * 2 - angle; } } else if (angle == 0) { - angle = M_PI * 2; + angle = std::numbers::pi * 2; } double amax = std::max(fmod(fabs(a - A), 360), @@ -337,7 +329,7 @@ void PathSegmentWalker::walk(PathSegmentVisitor& cb, const Base::Vector3d& start if (nrot != lrot) { double amax = std::max(fmod(fabs(a - A), 360), std::max(fmod(fabs(b - B), 360), fmod(fabs(c - C), 360))); - double angle = amax / 180 * M_PI; + double angle = amax / 180 * std::numbers::pi; int segments = std::max(ARC_MIN_SEGMENTS, 3.0 / (deviation / angle)); double da = (a - A) / segments; diff --git a/src/Mod/CAM/App/Voronoi.cpp b/src/Mod/CAM/App/Voronoi.cpp index 55aeb601c3..0ccad2e191 100644 --- a/src/Mod/CAM/App/Voronoi.cpp +++ b/src/Mod/CAM/App/Voronoi.cpp @@ -22,8 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#define _USE_MATH_DEFINES -#include #endif #include @@ -260,10 +258,10 @@ double Voronoi::diagram_type::angleOfSegment(int i, Voronoi::diagram_type::angle double ang = 0; if (p0.x() == p1.x()) { if (p0.y() < p1.y()) { - ang = M_PI_2; + ang = std::numbers::pi / 2; } else { - ang = -M_PI_2; + ang = -std::numbers::pi / 2; } } else { @@ -292,7 +290,8 @@ bool Voronoi::diagram_type::segmentsAreConnected(int i, int j) const void Voronoi::colorColinear(Voronoi::color_type color, double degree) { - double rad = degree * M_PI / 180; + using std::numbers::pi; + double rad = degree * pi / 180; Voronoi::diagram_type::angle_map_t angle; int psize = vd->points.size(); @@ -306,11 +305,11 @@ void Voronoi::colorColinear(Voronoi::color_type color, double degree) double a0 = vd->angleOfSegment(i0, &angle); double a1 = vd->angleOfSegment(i1, &angle); double a = a0 - a1; - if (a > M_PI_2) { - a -= M_PI; + if (a > pi / 2) { + a -= pi; } - else if (a < -M_PI_2) { - a += M_PI; + else if (a < -pi / 2) { + a += pi; } if (fabs(a) < rad) { it->color(color); diff --git a/src/Mod/CAM/App/Voronoi.h b/src/Mod/CAM/App/Voronoi.h index d7a4ac5c8c..ff77698bfb 100644 --- a/src/Mod/CAM/App/Voronoi.h +++ b/src/Mod/CAM/App/Voronoi.h @@ -22,7 +22,6 @@ #ifndef PATH_VORONOI_H #define PATH_VORONOI_H -#include #include #include #include @@ -33,11 +32,6 @@ #include #include -#if (SIZE_MAX == UINT_MAX) -#define PATH_VORONOI_COLOR_MASK 0x07FFFFFFul -#else -#define PATH_VORONOI_COLOR_MASK 0x07FFFFFFFFFFFFFFul -#endif namespace Path { @@ -51,8 +45,8 @@ public: ~Voronoi() override; using color_type = std::size_t; - static const int InvalidIndex = INT_MAX; - static const color_type ColorMask = PATH_VORONOI_COLOR_MASK; + static const int InvalidIndex = std::numeric_limits::max(); + static const color_type ColorMask = std::numeric_limits::max() >> 5; // types using coordinate_type = double; diff --git a/src/Mod/CAM/App/VoronoiEdgePyImp.cpp b/src/Mod/CAM/App/VoronoiEdgePyImp.cpp index 9015e49d52..bf47258083 100644 --- a/src/Mod/CAM/App/VoronoiEdgePyImp.cpp +++ b/src/Mod/CAM/App/VoronoiEdgePyImp.cpp @@ -466,12 +466,12 @@ PyObject* VoronoiEdgePy::isBorderline(PyObject* args) PyObject* VoronoiEdgePy::toShape(PyObject* args) { double z0 = 0.0; - double z1 = DBL_MAX; + double z1 = std::numeric_limits::max(); int dbg = 0; if (!PyArg_ParseTuple(args, "|ddp", &z0, &z1, &dbg)) { throw Py::RuntimeError("no, one or two arguments of type double accepted"); } - if (z1 == DBL_MAX) { + if (z1 == std::numeric_limits::max()) { z1 = z0; } VoronoiEdge* e = getVoronoiEdgePtr(); @@ -688,6 +688,8 @@ PyObject* VoronoiEdgePy::getDistances(PyObject* args) PyObject* VoronoiEdgePy::getSegmentAngle(PyObject* args) { + using std::numbers::pi; + VoronoiEdge* e = getVoronoiEdgeFromPy(this, args); if (e->ptr->cell()->contains_segment() && e->ptr->twin()->cell()->contains_segment()) { @@ -697,11 +699,11 @@ PyObject* VoronoiEdgePy::getSegmentAngle(PyObject* args) double a0 = e->dia->angleOfSegment(i0); double a1 = e->dia->angleOfSegment(i1); double a = a0 - a1; - if (a > M_PI_2) { - a -= M_PI; + if (a > pi / 2) { + a -= pi; } - else if (a < -M_PI_2) { - a += M_PI; + else if (a < -pi / 2) { + a += pi; } return Py::new_reference_to(Py::Float(a)); } diff --git a/src/Mod/CAM/Gui/ViewProviderPath.cpp b/src/Mod/CAM/Gui/ViewProviderPath.cpp index 25276bdacb..44698df05a 100644 --- a/src/Mod/CAM/Gui/ViewProviderPath.cpp +++ b/src/Mod/CAM/Gui/ViewProviderPath.cpp @@ -183,11 +183,11 @@ ViewProviderPath::ViewProviderPath() ShowCountConstraints.LowerBound = 0; - ShowCountConstraints.UpperBound = INT_MAX; + ShowCountConstraints.UpperBound = std::numeric_limits::max(); ShowCountConstraints.StepSize = 1; ShowCount.setConstraints(&ShowCountConstraints); StartIndexConstraints.LowerBound = 0; - StartIndexConstraints.UpperBound = INT_MAX; + StartIndexConstraints.UpperBound = std::numeric_limits::max(); StartIndexConstraints.StepSize = 1; StartIndex.setConstraints(&StartIndexConstraints); ADD_PROPERTY_TYPE(StartPosition, diff --git a/src/Mod/CAM/PathSimulator/AppGL/linmath.h b/src/Mod/CAM/PathSimulator/AppGL/linmath.h index 7ebdc2cfba..c0feb2caa0 100644 --- a/src/Mod/CAM/PathSimulator/AppGL/linmath.h +++ b/src/Mod/CAM/PathSimulator/AppGL/linmath.h @@ -5,7 +5,7 @@ #define LINMATH_H #include -#include +#include #ifdef LINMATH_NO_INLINE #define LINMATH_H_FUNC static diff --git a/src/Mod/CAM/libarea/Adaptive.cpp b/src/Mod/CAM/libarea/Adaptive.cpp index 3b45c3254a..535d25efe4 100644 --- a/src/Mod/CAM/libarea/Adaptive.cpp +++ b/src/Mod/CAM/libarea/Adaptive.cpp @@ -26,6 +26,7 @@ #include #include #include +#include namespace ClipperLib { @@ -116,7 +117,7 @@ inline double Angle3Points(const DoublePoint& p1, const DoublePoint& p2, const D double t1 = atan2(p2.Y - p1.Y, p2.X - p1.X); double t2 = atan2(p3.Y - p2.Y, p3.X - p2.X); double a = fabs(t2 - t1); - return min(a, 2 * M_PI - a); + return min(a, 2 * std::numbers::pi - a); } inline DoublePoint DirectionV(const IntPoint& pt1, const IntPoint& pt2) @@ -1096,8 +1097,8 @@ private: class Interpolation { public: - const double MIN_ANGLE = -M_PI / 4; - const double MAX_ANGLE = M_PI / 4; + const double MIN_ANGLE = -std::numbers::pi / 4; + const double MAX_ANGLE = std::numbers::pi / 4; void clear() { @@ -1542,7 +1543,7 @@ double Adaptive2d::CalcCutArea(Clipper& clip, double minFi = fi1; double maxFi = fi2; if (maxFi < minFi) { - maxFi += 2 * M_PI; + maxFi += 2 * std::numbers::pi; } if (preventConventional && interPathLen >= RESOLUTION_FACTOR) { @@ -2359,7 +2360,7 @@ bool Adaptive2d::MakeLeadPath(bool leadIn, IntPoint(currentPoint.X + nextDir.X * stepSize, currentPoint.Y + nextDir.Y * stepSize); Path checkPath; double adaptFactor = 0.4; - double alfa = M_PI / 64; + double alfa = std::numbers::pi / 64; double pathLen = 0; checkPath.push_back(nextPoint); for (int i = 0; i < 10000; i++) { @@ -2802,7 +2803,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths) IntPoint clp; // to store closest point vector gyro; // used to average tool direction vector angleHistory; // use to predict deflection angle - double angle = M_PI; + double angle = std::numbers::pi; engagePoint = toolPos; Interpolation interp; // interpolation instance @@ -2846,7 +2847,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths) } } - angle = M_PI / 4; // initial pass angle + angle = std::numbers::pi / 4; // initial pass angle bool recalcArea = false; double cumulativeCutArea = 0; // init gyro @@ -2991,7 +2992,7 @@ void Adaptive2d::ProcessPolyNode(Paths boundPaths, Paths toolBoundPaths) rotateStep++; // if new tool pos. outside boundary rotate until back in recalcArea = true; - newToolDir = rotate(newToolDir, M_PI / 90); + newToolDir = rotate(newToolDir, std::numbers::pi / 90); newToolPos = IntPoint(long(toolPos.X + newToolDir.X * stepScaled), long(toolPos.Y + newToolDir.Y * stepScaled)); } diff --git a/src/Mod/CAM/libarea/Adaptive.hpp b/src/Mod/CAM/libarea/Adaptive.hpp index 497aa2792a..9f57b5407f 100644 --- a/src/Mod/CAM/libarea/Adaptive.hpp +++ b/src/Mod/CAM/libarea/Adaptive.hpp @@ -36,10 +36,6 @@ #define __LONG_MAX__ 2147483647 #endif -#ifndef M_PI -#define M_PI 3.141592653589793238 -#endif - // #define DEV_MODE #define NTOL 1.0e-7 // numeric tolerance diff --git a/src/Mod/CAM/libarea/Box2D.h b/src/Mod/CAM/libarea/Box2D.h index 23ee202ac7..b0c02d9e3f 100644 --- a/src/Mod/CAM/libarea/Box2D.h +++ b/src/Mod/CAM/libarea/Box2D.h @@ -29,7 +29,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #pragma once #include // for memcpy() prototype -#include // for sqrt() prototype +#include // for sqrt() prototype class CBox2D { diff --git a/src/Mod/CAM/libarea/Curve.h b/src/Mod/CAM/libarea/Curve.h index f6f62eee14..35ea485a52 100644 --- a/src/Mod/CAM/libarea/Curve.h +++ b/src/Mod/CAM/libarea/Curve.h @@ -31,7 +31,7 @@ THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include "Point.h" #include "Box2D.h" diff --git a/src/Mod/CAM/libarea/kurve/geometry.h b/src/Mod/CAM/libarea/kurve/geometry.h index 88cbbf5b1a..8c8dc5a6ca 100644 --- a/src/Mod/CAM/libarea/kurve/geometry.h +++ b/src/Mod/CAM/libarea/kurve/geometry.h @@ -17,7 +17,7 @@ #endif #endif -#include +#include #include #include #include diff --git a/src/Mod/Drawing/App/DrawingExport.cpp b/src/Mod/Drawing/App/DrawingExport.cpp index 1f654caf60..516458e917 100644 --- a/src/Mod/Drawing/App/DrawingExport.cpp +++ b/src/Mod/Drawing/App/DrawingExport.cpp @@ -207,9 +207,10 @@ void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) } // arc of circle else { + using std::numbers::pi; // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths - char xar = '0'; // x-axis-rotation - char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag + char xar = '0'; // x-axis-rotation + char las = (l - f > pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << ""; @@ -255,7 +256,8 @@ void SVGOutput::printEllipse(const BRepAdaptor_Curve& c, int id, std::ostream& o } // arc of ellipse else { - char las = (l - f > D_PI) ? '1' : '0'; // large-arc-flag + using std::numbers::pi; + char las = (l - f > pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "" << std::endl; @@ -460,6 +462,8 @@ void DXFOutput::printHeader(std::ostream& out) void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) { + using std::numbers::pi; + gp_Circ circ = c.Circle(); const gp_Pnt& p = circ.Location(); double r = circ.Radius(); @@ -502,8 +506,8 @@ void DXFOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) double bx = e.X() - p.X(); double by = e.Y() - p.Y(); - double start_angle = atan2(ay, ax) * 180 / D_PI; - double end_angle = atan2(by, bx) * 180 / D_PI; + double start_angle = atan2(ay, ax) * 180 / pi; + double end_angle = atan2(by, bx) * 180 / pi; if (a > 0) { double temp = start_angle; diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index 98d8a2897f..319dbcb186 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -256,7 +256,7 @@ void orthoview::set_projection(const gp_Ax2& cs) // angle between desired projection and actual projection float rotation = X_dir.Angle(actual_X); - if (rotation != 0 && abs(M_PI - rotation) > 0.05) { + if (rotation != 0 && abs(std::numbers::pi - rotation) > 0.05) { if (!Z_dir.IsEqual(actual_X.Crossed(X_dir), 0.05)) { rotation = -rotation; } @@ -266,7 +266,7 @@ void orthoview::set_projection(const gp_Ax2& cs) // this_view->Direction.setValue(Z_dir.X(), Z_dir.Y(), Z_dir.Z()); this_view->Direction.setValue(x, y, z); - this_view->Rotation.setValue(180 * rotation / M_PI); + this_view->Rotation.setValue(180 * rotation / std::numbers::pi); } /////////////////////////////////////////////////////////////////////////////////////////////// @@ -613,8 +613,8 @@ void OrthoViews::set_orientation(int index) // set orientation of single view dir = primary.XDirection(); n = -views[index]->rel_y; } - - rotation = n * rotate_coeff * M_PI / 2; // rotate_coeff is -1 or 1 for 1st or 3rd angle + // rotate_coeff is -1 or 1 for 1st or 3rd angle + rotation = n * rotate_coeff * std::numbers::pi / 2; cs = primary.Rotated(gp_Ax1(gp_Pnt(0, 0, 0), dir), rotation); views[index]->set_projection(cs); } @@ -780,7 +780,7 @@ void OrthoViews::set_Axo(int rel_x, rotations[1] = -0.6156624905260762; } else { - rotations[0] = 1.3088876392502007 - M_PI / 2; + rotations[0] = 1.3088876392502007 - std::numbers::pi / 2; rotations[1] = -0.6156624905260762; } diff --git a/src/Mod/Fem/App/FemConstraint.cpp b/src/Mod/Fem/App/FemConstraint.cpp index 6e48bdc599..322e824335 100644 --- a/src/Mod/Fem/App/FemConstraint.cpp +++ b/src/Mod/Fem/App/FemConstraint.cpp @@ -75,7 +75,10 @@ using Adaptor3d_HSurface = Adaptor3d_Surface; using BRepAdaptor_HSurface = BRepAdaptor_Surface; #endif -static const App::PropertyFloatConstraint::Constraints scaleConstraint = {0.0, DBL_MAX, 0.1}; +static const App::PropertyFloatConstraint::Constraints scaleConstraint = { + 0.0, + std::numeric_limits::max(), + 0.1}; PROPERTY_SOURCE(Fem::Constraint, App::DocumentObject) diff --git a/src/Mod/Fem/App/FemConstraintTransform.cpp b/src/Mod/Fem/App/FemConstraintTransform.cpp index b1947866ab..aaa7299009 100644 --- a/src/Mod/Fem/App/FemConstraintTransform.cpp +++ b/src/Mod/Fem/App/FemConstraintTransform.cpp @@ -116,12 +116,14 @@ namespace Base::Rotation anglesToRotation(double xAngle, double yAngle, double zAngle) { + using std::numbers::pi; + static Base::Vector3d a(1, 0, 0); static Base::Vector3d b(0, 1, 0); static int count = 0; - double xRad = xAngle * D_PI / 180.0; - double yRad = yAngle * D_PI / 180.0; - double zRad = zAngle * D_PI / 180.0; + double xRad = xAngle * pi / 180.0; + double yRad = yAngle * pi / 180.0; + double zRad = zAngle * pi / 180.0; if (xAngle != 0) { a[1] = 0; a[2] = 0; diff --git a/src/Mod/Fem/Gui/DlgSettingsFemCcxImp.cpp b/src/Mod/Fem/Gui/DlgSettingsFemCcxImp.cpp index e70b285702..cbded442f1 100644 --- a/src/Mod/Fem/Gui/DlgSettingsFemCcxImp.cpp +++ b/src/Mod/Fem/Gui/DlgSettingsFemCcxImp.cpp @@ -43,8 +43,8 @@ DlgSettingsFemCcxImp::DlgSettingsFemCcxImp(QWidget* parent) { ui->setupUi(this); // set ranges - ui->dsb_ccx_analysis_time->setMaximum(FLOAT_MAX); - ui->dsb_ccx_initial_time_step->setMaximum(FLOAT_MAX); + ui->dsb_ccx_analysis_time->setMaximum(std::numeric_limits::max()); + ui->dsb_ccx_initial_time_step->setMaximum(std::numeric_limits::max()); connect(ui->fc_ccx_binary_path, &Gui::PrefFileChooser::fileNameChanged, diff --git a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp index 72d355449c..d054494ca6 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintBearing.cpp @@ -66,18 +66,19 @@ TaskFemConstraintBearing::TaskFemConstraintBearing(ViewProviderFemConstraint* Co this->groupLayout()->addWidget(proxy); // setup ranges - ui->spinDiameter->setMinimum(-FLOAT_MAX); - ui->spinDiameter->setMaximum(FLOAT_MAX); - ui->spinOtherDiameter->setMinimum(-FLOAT_MAX); - ui->spinOtherDiameter->setMaximum(FLOAT_MAX); - ui->spinCenterDistance->setMinimum(-FLOAT_MAX); - ui->spinCenterDistance->setMaximum(FLOAT_MAX); - ui->spinForce->setMinimum(-FLOAT_MAX); - ui->spinForce->setMaximum(FLOAT_MAX); - ui->spinTensionForce->setMinimum(-FLOAT_MAX); - ui->spinTensionForce->setMaximum(FLOAT_MAX); - ui->spinDistance->setMinimum(-FLOAT_MAX); - ui->spinDistance->setMaximum(FLOAT_MAX); + constexpr float max = std::numeric_limits::max(); + ui->spinDiameter->setMinimum(-max); + ui->spinDiameter->setMaximum(max); + ui->spinOtherDiameter->setMinimum(-max); + ui->spinOtherDiameter->setMaximum(max); + ui->spinCenterDistance->setMinimum(-max); + ui->spinCenterDistance->setMaximum(max); + ui->spinForce->setMinimum(-max); + ui->spinForce->setMaximum(max); + ui->spinTensionForce->setMinimum(-max); + ui->spinTensionForce->setMaximum(max); + ui->spinDistance->setMinimum(-max); + ui->spinDistance->setMaximum(max); // Get the feature data Fem::ConstraintBearing* pcConstraint = ConstraintView->getObject(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp index 2b49edb781..65c1744127 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintContact.cpp @@ -96,27 +96,27 @@ TaskFemConstraintContact::TaskFemConstraintContact(ViewProviderFemConstraintCont // Fill data into dialog elements ui->spbSlope->setUnit(pcConstraint->Slope.getUnit()); ui->spbSlope->setMinimum(0); - ui->spbSlope->setMaximum(FLOAT_MAX); + ui->spbSlope->setMaximum(std::numeric_limits::max()); ui->spbSlope->setValue(pcConstraint->Slope.getQuantityValue()); ui->spbSlope->bind(pcConstraint->Slope); ui->spbAdjust->setUnit(pcConstraint->Adjust.getUnit()); ui->spbAdjust->setMinimum(0); - ui->spbAdjust->setMaximum(FLOAT_MAX); + ui->spbAdjust->setMaximum(std::numeric_limits::max()); ui->spbAdjust->setValue(pcConstraint->Adjust.getQuantityValue()); ui->spbAdjust->bind(pcConstraint->Adjust); ui->ckbFriction->setChecked(friction); ui->spbFrictionCoeff->setMinimum(0); - ui->spbFrictionCoeff->setMaximum(FLOAT_MAX); + ui->spbFrictionCoeff->setMaximum(std::numeric_limits::max()); ui->spbFrictionCoeff->setValue(pcConstraint->FrictionCoefficient.getValue()); ui->spbFrictionCoeff->setEnabled(friction); ui->spbFrictionCoeff->bind(pcConstraint->FrictionCoefficient); ui->spbStickSlope->setUnit(pcConstraint->StickSlope.getUnit()); ui->spbStickSlope->setMinimum(0); - ui->spbStickSlope->setMaximum(FLOAT_MAX); + ui->spbStickSlope->setMaximum(std::numeric_limits::max()); ui->spbStickSlope->setValue(pcConstraint->StickSlope.getQuantityValue()); ui->spbStickSlope->setEnabled(friction); ui->spbStickSlope->bind(pcConstraint->StickSlope); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index e4c490860b..b760434e77 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -74,18 +74,19 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement( this->groupLayout()->addWidget(proxy); // setup ranges - ui->spinxDisplacement->setMinimum(-FLOAT_MAX); - ui->spinxDisplacement->setMaximum(FLOAT_MAX); - ui->spinyDisplacement->setMinimum(-FLOAT_MAX); - ui->spinyDisplacement->setMaximum(FLOAT_MAX); - ui->spinzDisplacement->setMinimum(-FLOAT_MAX); - ui->spinzDisplacement->setMaximum(FLOAT_MAX); - ui->spinxRotation->setMinimum(-FLOAT_MAX); - ui->spinxRotation->setMaximum(FLOAT_MAX); - ui->spinyRotation->setMinimum(-FLOAT_MAX); - ui->spinyRotation->setMaximum(FLOAT_MAX); - ui->spinzRotation->setMinimum(-FLOAT_MAX); - ui->spinzRotation->setMaximum(FLOAT_MAX); + constexpr float max = std::numeric_limits::max(); + ui->spinxDisplacement->setMinimum(-max); + ui->spinxDisplacement->setMaximum(max); + ui->spinyDisplacement->setMinimum(-max); + ui->spinyDisplacement->setMaximum(max); + ui->spinzDisplacement->setMinimum(-max); + ui->spinzDisplacement->setMaximum(max); + ui->spinxRotation->setMinimum(-max); + ui->spinxRotation->setMaximum(max); + ui->spinyRotation->setMinimum(-max); + ui->spinyRotation->setMaximum(max); + ui->spinzRotation->setMinimum(-max); + ui->spinzRotation->setMaximum(max); // Get the feature data Fem::ConstraintDisplacement* pcConstraint = diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index ff11970ea9..fb9a3fe912 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -145,18 +145,19 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary( &TaskFemConstraintFluidBoundary::onReferenceDeleted); // setup ranges - ui->spinBoundaryValue->setMinimum(-FLOAT_MAX); - ui->spinBoundaryValue->setMaximum(FLOAT_MAX); + constexpr float max = std::numeric_limits::max(); + ui->spinBoundaryValue->setMinimum(-max); + ui->spinBoundaryValue->setMaximum(max); ui->spinTurbulentIntensityValue->setMinimum(0.0); - ui->spinTurbulentIntensityValue->setMaximum(FLOAT_MAX); + ui->spinTurbulentIntensityValue->setMaximum(max); ui->spinTurbulentLengthValue->setMinimum(0.0); - ui->spinTurbulentLengthValue->setMaximum(FLOAT_MAX); + ui->spinTurbulentLengthValue->setMaximum(max); ui->spinTemperatureValue->setMinimum(-273.15); - ui->spinTemperatureValue->setMaximum(FLOAT_MAX); + ui->spinTemperatureValue->setMaximum(max); ui->spinHeatFluxValue->setMinimum(0.0); - ui->spinHeatFluxValue->setMaximum(FLOAT_MAX); + ui->spinHeatFluxValue->setMaximum(max); ui->spinHTCoeffValue->setMinimum(0.0); - ui->spinHTCoeffValue->setMaximum(FLOAT_MAX); + ui->spinHTCoeffValue->setMaximum(max); connect(ui->comboBoundaryType, qOverload(&QComboBox::currentIndexChanged), @@ -352,8 +353,8 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary( // Fill data into dialog elements double f = pcConstraint->BoundaryValue.getValue(); - ui->spinBoundaryValue->setMinimum(FLOAT_MIN); // previous set the min to ZERO is not flexible - ui->spinBoundaryValue->setMaximum(FLOAT_MAX); + ui->spinBoundaryValue->setMinimum(std::numeric_limits::min()); // ZERO is not flexible + ui->spinBoundaryValue->setMaximum(std::numeric_limits::max()); ui->spinBoundaryValue->setValue(f); ui->listReferences->clear(); for (std::size_t i = 0; i < Objects.size(); i++) { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 236fdef904..fb8f7f9855 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -75,7 +75,7 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* C // Fill data into dialog elements ui->spinForce->setUnit(pcConstraint->Force.getUnit()); ui->spinForce->setMinimum(0); - ui->spinForce->setMaximum(FLOAT_MAX); + ui->spinForce->setMaximum(std::numeric_limits::max()); ui->spinForce->setValue(force); ui->listReferences->clear(); for (std::size_t i = 0; i < Objects.size(); i++) { diff --git a/src/Mod/Fem/Gui/TaskFemConstraintGear.cpp b/src/Mod/Fem/Gui/TaskFemConstraintGear.cpp index 3a116dff1c..9e139f899c 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintGear.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintGear.cpp @@ -87,10 +87,10 @@ TaskFemConstraintGear::TaskFemConstraintGear(ViewProviderFemConstraint* Constrai // Fill data into dialog elements ui->spinDiameter->setMinimum(0); - ui->spinDiameter->setMaximum(FLOAT_MAX); + ui->spinDiameter->setMaximum(std::numeric_limits::max()); ui->spinDiameter->setValue(dia); ui->spinForce->setMinimum(0); - ui->spinForce->setMaximum(FLOAT_MAX); + ui->spinForce->setMaximum(std::numeric_limits::max()); ui->spinForce->setValue(force); ui->spinForceAngle->setMinimum(-360); ui->spinForceAngle->setMaximum(360); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index 41651983ef..0241563cbb 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -119,16 +119,16 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux( ui->sw_heatflux->setCurrentIndex(constrType->getValue()); ui->qsb_ambienttemp_conv->setMinimum(0); - ui->qsb_ambienttemp_conv->setMaximum(FLOAT_MAX); + ui->qsb_ambienttemp_conv->setMaximum(std::numeric_limits::max()); ui->qsb_film_coef->setMinimum(0); - ui->qsb_film_coef->setMaximum(FLOAT_MAX); + ui->qsb_film_coef->setMaximum(std::numeric_limits::max()); ui->dsb_emissivity->setMinimum(0); - ui->dsb_emissivity->setMaximum(FLOAT_MAX); + ui->dsb_emissivity->setMaximum(std::numeric_limits::max()); ui->qsb_ambienttemp_rad->setMinimum(0); - ui->qsb_ambienttemp_rad->setMaximum(FLOAT_MAX); + ui->qsb_ambienttemp_rad->setMaximum(std::numeric_limits::max()); ui->qsb_ambienttemp_conv->setValue(pcConstraint->AmbientTemp.getQuantityValue()); ui->qsb_film_coef->setValue(pcConstraint->FilmCoef.getQuantityValue()); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index 030cfc9c1c..41406cc1a2 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -64,7 +64,7 @@ TaskFemConstraintPressure::TaskFemConstraintPressure( // Fill data into dialog elements ui->if_pressure->setUnit(pcConstraint->Pressure.getUnit()); ui->if_pressure->setMinimum(0); - ui->if_pressure->setMaximum(FLOAT_MAX); + ui->if_pressure->setMaximum(std::numeric_limits::max()); ui->if_pressure->setValue(pcConstraint->Pressure.getQuantityValue()); ui->if_pressure->bind(pcConstraint->Pressure); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPulley.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPulley.cpp index 710b041a61..ebc8ac670e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPulley.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPulley.cpp @@ -76,15 +76,15 @@ TaskFemConstraintPulley::TaskFemConstraintPulley(ViewProviderFemConstraintPulley // Fill data into dialog elements ui->spinOtherDiameter->setMinimum(0); - ui->spinOtherDiameter->setMaximum(FLOAT_MAX); + ui->spinOtherDiameter->setMaximum(std::numeric_limits::max()); ui->spinOtherDiameter->setValue(otherdia); ui->spinCenterDistance->setMinimum(0); - ui->spinCenterDistance->setMaximum(FLOAT_MAX); + ui->spinCenterDistance->setMaximum(std::numeric_limits::max()); ui->spinCenterDistance->setValue(centerdist); ui->checkIsDriven->setChecked(isdriven); - ui->spinForce->setMinimum(-FLOAT_MAX); + ui->spinForce->setMinimum(-std::numeric_limits::max()); ui->spinTensionForce->setMinimum(0); - ui->spinTensionForce->setMaximum(FLOAT_MAX); + ui->spinTensionForce->setMaximum(std::numeric_limits::max()); ui->spinTensionForce->setValue(tensionforce); // Adjust ui diff --git a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp index 70da10d875..c1f5e17ee9 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintRigidBody.cpp @@ -48,6 +48,7 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( QWidget* parent) : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintRigidBody") { // Note change "RigidBody" in line above to new constraint name + constexpr float floatMax = std::numeric_limits::max(); proxy = new QWidget(this); ui = new Ui_TaskFemConstraintRigidBody(); ui->setupUi(proxy); @@ -137,12 +138,12 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( App::ObjectIdentifier::parse(pcConstraint, std::string("ReferenceNode.y"))); ui->qsb_ref_node_z->bind( App::ObjectIdentifier::parse(pcConstraint, std::string("ReferenceNode.z"))); - ui->qsb_ref_node_x->setMinimum(-FLOAT_MAX); - ui->qsb_ref_node_x->setMaximum(FLOAT_MAX); - ui->qsb_ref_node_y->setMinimum(-FLOAT_MAX); - ui->qsb_ref_node_y->setMaximum(FLOAT_MAX); - ui->qsb_ref_node_z->setMinimum(-FLOAT_MAX); - ui->qsb_ref_node_z->setMaximum(FLOAT_MAX); + ui->qsb_ref_node_x->setMinimum(-floatMax); + ui->qsb_ref_node_x->setMaximum(floatMax); + ui->qsb_ref_node_y->setMinimum(-floatMax); + ui->qsb_ref_node_y->setMaximum(floatMax); + ui->qsb_ref_node_z->setMinimum(-floatMax); + ui->qsb_ref_node_z->setMaximum(floatMax); ui->qsb_disp_x->setValue(disp.x); ui->qsb_disp_y->setValue(disp.y); @@ -150,12 +151,12 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( ui->qsb_disp_x->bind(App::ObjectIdentifier::parse(pcConstraint, std::string("Displacement.x"))); ui->qsb_disp_y->bind(App::ObjectIdentifier::parse(pcConstraint, std::string("Displacement.y"))); ui->qsb_disp_z->bind(App::ObjectIdentifier::parse(pcConstraint, std::string("Displacement.z"))); - ui->qsb_disp_x->setMinimum(-FLOAT_MAX); - ui->qsb_disp_x->setMaximum(FLOAT_MAX); - ui->qsb_disp_y->setMinimum(-FLOAT_MAX); - ui->qsb_disp_y->setMaximum(FLOAT_MAX); - ui->qsb_disp_z->setMinimum(-FLOAT_MAX); - ui->qsb_disp_z->setMaximum(FLOAT_MAX); + ui->qsb_disp_x->setMinimum(-floatMax); + ui->qsb_disp_x->setMaximum(floatMax); + ui->qsb_disp_y->setMinimum(-floatMax); + ui->qsb_disp_y->setMaximum(floatMax); + ui->qsb_disp_z->setMinimum(-floatMax); + ui->qsb_disp_z->setMaximum(floatMax); ui->spb_rot_axis_x->setValue(rotDir.x); ui->spb_rot_axis_y->setValue(rotDir.y); @@ -169,14 +170,14 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( App::ObjectIdentifier::parse(pcConstraint, std::string("Rotation.Axis.z"))); ui->qsb_rot_angle->bind( App::ObjectIdentifier::parse(pcConstraint, std::string("Rotation.Angle"))); - ui->spb_rot_axis_x->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_x->setMaximum(FLOAT_MAX); - ui->spb_rot_axis_y->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_y->setMaximum(FLOAT_MAX); - ui->spb_rot_axis_z->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_z->setMaximum(FLOAT_MAX); - ui->qsb_rot_angle->setMinimum(-FLOAT_MAX); - ui->qsb_rot_angle->setMaximum(FLOAT_MAX); + ui->spb_rot_axis_x->setMinimum(-floatMax); + ui->spb_rot_axis_x->setMaximum(floatMax); + ui->spb_rot_axis_y->setMinimum(-floatMax); + ui->spb_rot_axis_y->setMaximum(floatMax); + ui->spb_rot_axis_z->setMinimum(-floatMax); + ui->spb_rot_axis_z->setMaximum(floatMax); + ui->qsb_rot_angle->setMinimum(-floatMax); + ui->qsb_rot_angle->setMaximum(floatMax); ui->qsb_force_x->setValue(forceX); ui->qsb_force_y->setValue(forceY); @@ -184,12 +185,12 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( ui->qsb_force_x->bind(pcConstraint->ForceX); ui->qsb_force_y->bind(pcConstraint->ForceY); ui->qsb_force_z->bind(pcConstraint->ForceZ); - ui->qsb_force_x->setMinimum(-FLOAT_MAX); - ui->qsb_force_x->setMaximum(FLOAT_MAX); - ui->qsb_force_y->setMinimum(-FLOAT_MAX); - ui->qsb_force_y->setMaximum(FLOAT_MAX); - ui->qsb_force_z->setMinimum(-FLOAT_MAX); - ui->qsb_force_z->setMaximum(FLOAT_MAX); + ui->qsb_force_x->setMinimum(-floatMax); + ui->qsb_force_x->setMaximum(floatMax); + ui->qsb_force_y->setMinimum(-floatMax); + ui->qsb_force_y->setMaximum(floatMax); + ui->qsb_force_z->setMinimum(-floatMax); + ui->qsb_force_z->setMaximum(floatMax); ui->qsb_moment_x->setValue(momentX); ui->qsb_moment_y->setValue(momentY); @@ -197,12 +198,12 @@ TaskFemConstraintRigidBody::TaskFemConstraintRigidBody( ui->qsb_moment_x->bind(pcConstraint->MomentX); ui->qsb_moment_y->bind(pcConstraint->MomentY); ui->qsb_moment_z->bind(pcConstraint->MomentZ); - ui->qsb_moment_x->setMinimum(-FLOAT_MAX); - ui->qsb_moment_x->setMaximum(FLOAT_MAX); - ui->qsb_moment_y->setMinimum(-FLOAT_MAX); - ui->qsb_moment_y->setMaximum(FLOAT_MAX); - ui->qsb_moment_z->setMinimum(-FLOAT_MAX); - ui->qsb_moment_z->setMaximum(FLOAT_MAX); + ui->qsb_moment_x->setMinimum(-floatMax); + ui->qsb_moment_x->setMaximum(floatMax); + ui->qsb_moment_y->setMinimum(-floatMax); + ui->qsb_moment_y->setMaximum(floatMax); + ui->qsb_moment_z->setMinimum(-floatMax); + ui->qsb_moment_z->setMaximum(floatMax); QStringList modeList; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index 4f09a745b8..e21fb5b299 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -76,11 +76,11 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring // Fill data into dialog elements ui->qsb_norm->setUnit(pcConstraint->NormalStiffness.getUnit()); - ui->qsb_norm->setMaximum(FLOAT_MAX); + ui->qsb_norm->setMaximum(std::numeric_limits::max()); ui->qsb_norm->setValue(pcConstraint->NormalStiffness.getQuantityValue()); ui->qsb_tan->setUnit(pcConstraint->TangentialStiffness.getUnit()); - ui->qsb_tan->setMaximum(FLOAT_MAX); + ui->qsb_tan->setMaximum(std::numeric_limits::max()); ui->qsb_tan->setValue(pcConstraint->TangentialStiffness.getQuantityValue()); ui->cb_elmer_stiffness->clear(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index c989436740..ff648c41e7 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -68,9 +68,9 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature( // Fill data into dialog elements ui->qsb_temperature->setMinimum(0); - ui->qsb_temperature->setMaximum(FLOAT_MAX); - ui->qsb_cflux->setMinimum(-FLOAT_MAX); - ui->qsb_cflux->setMaximum(FLOAT_MAX); + ui->qsb_temperature->setMaximum(std::numeric_limits::max()); + ui->qsb_cflux->setMinimum(-std::numeric_limits::max()); + ui->qsb_cflux->setMaximum(std::numeric_limits::max()); App::PropertyEnumeration* constrType = &pcConstraint->ConstraintType; QStringList qTypeList; diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp index d53e476f37..894b27b62e 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTransform.cpp @@ -130,14 +130,15 @@ TaskFemConstraintTransform::TaskFemConstraintTransform( ui->qsb_rot_angle->bind( App::ObjectIdentifier::parse(pcConstraint, std::string("Rotation.Angle"))); - ui->spb_rot_axis_x->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_x->setMaximum(FLOAT_MAX); - ui->spb_rot_axis_y->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_y->setMaximum(FLOAT_MAX); - ui->spb_rot_axis_z->setMinimum(-FLOAT_MAX); - ui->spb_rot_axis_z->setMaximum(FLOAT_MAX); - ui->qsb_rot_angle->setMinimum(-FLOAT_MAX); - ui->qsb_rot_angle->setMaximum(FLOAT_MAX); + float max = std::numeric_limits::max(); + ui->spb_rot_axis_x->setMinimum(-max); + ui->spb_rot_axis_x->setMaximum(max); + ui->spb_rot_axis_y->setMinimum(-max); + ui->spb_rot_axis_y->setMaximum(max); + ui->spb_rot_axis_z->setMinimum(-max); + ui->spb_rot_axis_z->setMaximum(max); + ui->qsb_rot_angle->setMinimum(-max); + ui->qsb_rot_angle->setMaximum(max); std::string transform_type = pcConstraint->TransformType.getValueAsString(); if (transform_type == "Rectangular") { diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintFluidBoundary.cpp index 9ac1828bd9..9813172d33 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintFluidBoundary.cpp @@ -145,8 +145,8 @@ void ViewProviderFemConstraintFluidBoundary::updateData(const App::Property* pro for (const auto& point : points) { SbVec3f base(point.x, point.y, point.z); - if (forceDirection.GetAngle(normal) - < M_PI_2) { // Move arrow so it doesn't disappear inside the solid + if (forceDirection.GetAngle(normal) < std::numbers::pi + / 2) { // Move arrow so it doesn't disappear inside the solid base = base + dir * scaledlength; // OvG: Scaling } #ifdef USE_MULTIPLE_COPY @@ -191,7 +191,7 @@ void ViewProviderFemConstraintFluidBoundary::updateData(const App::Property* pro for (const auto& point : points) { SbVec3f base(point.x, point.y, point.z); - if (forceDirection.GetAngle(normal) < M_PI_2) { + if (forceDirection.GetAngle(normal) < std::numbers::pi / 2) { base = base + dir * scaledlength; // OvG: Scaling } #ifdef USE_MULTIPLE_COPY diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintForce.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintForce.cpp index 2c100a3a93..20d7832d3e 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintForce.cpp @@ -88,7 +88,7 @@ void ViewProviderFemConstraintForce::transformSymbol(const Base::Vector3d& point // Place each symbol outside the boundary Base::Vector3d dir = (rev ? -1.0 : 1.0) * obj->DirectionVector.getValue(); float symTraY = dir.Dot(normal) < 0 ? -1 * symLen : 0.0f; - float rotAngle = rev ? F_PI : 0.0f; + float rotAngle = rev ? std::numbers::pi_v : 0.0f; SbMatrix mat0, mat1; mat0.setTransform(SbVec3f(0, symTraY, 0), SbRotation(SbVec3f(0, 0, 1), rotAngle), diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintGear.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintGear.cpp index 33cd6ecd8a..95609843a4 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintGear.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintGear.cpp @@ -88,7 +88,7 @@ void ViewProviderFemConstraintGear::updateData(const App::Property* prop) if (dia < 2 * radius) { dia = 2 * radius; } - double angle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double angle = pcConstraint->ForceAngle.getValue() / 180 * std::numbers::pi; SbVec3f b(base.x, base.y, base.z); SbVec3f ax(axis.x, axis.y, axis.z); @@ -118,7 +118,7 @@ void ViewProviderFemConstraintGear::updateData(const App::Property* prop) if (dia < 2 * radius) { dia = 2 * radius; } - double angle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double angle = pcConstraint->ForceAngle.getValue() / 180 * std::numbers::pi; SbVec3f ax(axis.x, axis.y, axis.z); SbVec3f dir(direction.x, direction.y, direction.z); @@ -143,7 +143,7 @@ void ViewProviderFemConstraintGear::updateData(const App::Property* prop) direction = Base::Vector3d(0, 1, 0); } double dia = pcConstraint->Diameter.getValue(); - double angle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double angle = pcConstraint->ForceAngle.getValue() / 180 * std::numbers::pi; SbVec3f ax(axis.x, axis.y, axis.z); SbVec3f dir(direction.x, direction.y, direction.z); diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp index b58c9f5596..737b34994b 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPressure.cpp @@ -82,7 +82,7 @@ void ViewProviderFemConstraintPressure::transformSymbol(const Base::Vector3d& po SbMatrix& mat) const { auto obj = this->getObject(); - float rotAngle = obj->Reversed.getValue() ? F_PI : 0.0f; + float rotAngle = obj->Reversed.getValue() ? std::numbers::pi_v : 0.0f; float s = obj->getScaleFactor(); // Symbol length from .iv file float symLen = 4.0f; diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintPulley.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintPulley.cpp index 2a43326fe1..4cd2bc084f 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintPulley.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintPulley.cpp @@ -66,6 +66,8 @@ bool ViewProviderFemConstraintPulley::setEdit(int ModNum) void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) { + using std::numbers::pi; + // Gets called whenever a property of the attached object changes Fem::ConstraintPulley* pcConstraint = this->getObject(); @@ -82,7 +84,7 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) if (dia < 2 * radius) { dia = 2 * radius; } - double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * pi; double beltAngle = pcConstraint->BeltAngle.getValue(); double rat1 = 0.8, rat2 = 0.2; double f1 = pcConstraint->BeltForce1.getValue(); @@ -106,9 +108,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, dia / 2 * cos(forceAngle + beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(sin(forceAngle + beltAngle + M_PI_2), + SbVec3f(sin(forceAngle + beltAngle + pi / 2), 0, - cos(forceAngle + beltAngle + M_PI_2)))); + cos(forceAngle + beltAngle + pi / 2)))); GuiTools::createPlacement(sep, SbVec3f(0, dia / 8 + dia / 2 * rat1, 0), SbRotation()); sep->addChild(GuiTools::createArrow(dia / 8 + dia / 2 * rat1, dia / 8)); pShapeSep->addChild(sep); // child 3 @@ -118,9 +120,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, -dia / 2 * cos(forceAngle - beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(-sin(forceAngle - beltAngle - M_PI_2), + SbVec3f(-sin(forceAngle - beltAngle - pi / 2), 0, - -cos(forceAngle - beltAngle - M_PI_2)))); + -cos(forceAngle - beltAngle - pi / 2)))); GuiTools::createPlacement(sep, SbVec3f(0, dia / 8 + dia / 2 * rat2, 0), SbRotation()); sep->addChild(GuiTools::createArrow(dia / 8 + dia / 2 * rat2, dia / 8)); pShapeSep->addChild(sep); // child 4 @@ -134,7 +136,7 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) if (dia < 2 * radius) { dia = 2 * radius; } - double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * pi; double beltAngle = pcConstraint->BeltAngle.getValue(); double rat1 = 0.8, rat2 = 0.2; double f1 = pcConstraint->BeltForce1.getValue(); @@ -153,9 +155,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, dia / 2 * cos(forceAngle + beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(sin(forceAngle + beltAngle + M_PI_2), + SbVec3f(sin(forceAngle + beltAngle + pi / 2), 0, - cos(forceAngle + beltAngle + M_PI_2)))); + cos(forceAngle + beltAngle + pi / 2)))); GuiTools::updatePlacement(sep, 2, SbVec3f(0, dia / 8 + dia / 2 * rat1, 0), @@ -169,9 +171,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, -dia / 2 * cos(forceAngle - beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(-sin(forceAngle - beltAngle - M_PI_2), + SbVec3f(-sin(forceAngle - beltAngle - pi / 2), 0, - -cos(forceAngle - beltAngle - M_PI_2)))); + -cos(forceAngle - beltAngle - pi / 2)))); GuiTools::updatePlacement(sep, 2, SbVec3f(0, dia / 8 + dia / 2 * rat2, 0), @@ -187,7 +189,7 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) if (dia < 2 * radius) { dia = 2 * radius; } - double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * M_PI; + double forceAngle = pcConstraint->ForceAngle.getValue() / 180 * pi; double beltAngle = pcConstraint->BeltAngle.getValue(); const SoSeparator* sep = static_cast(pShapeSep->getChild(3)); @@ -197,9 +199,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, dia / 2 * cos(forceAngle + beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(sin(forceAngle + beltAngle + M_PI_2), + SbVec3f(sin(forceAngle + beltAngle + pi / 2), 0, - cos(forceAngle + beltAngle + M_PI_2)))); + cos(forceAngle + beltAngle + pi / 2)))); sep = static_cast(pShapeSep->getChild(4)); GuiTools::updatePlacement(sep, 0, @@ -207,9 +209,9 @@ void ViewProviderFemConstraintPulley::updateData(const App::Property* prop) 0, -dia / 2 * cos(forceAngle - beltAngle)), SbRotation(SbVec3f(0, 1, 0), - SbVec3f(-sin(forceAngle - beltAngle - M_PI_2), + SbVec3f(-sin(forceAngle - beltAngle - pi / 2), 0, - -cos(forceAngle - beltAngle - M_PI_2)))); + -cos(forceAngle - beltAngle - pi / 2)))); } } else if ((prop == &pcConstraint->BeltForce1) || (prop == &pcConstraint->BeltForce2)) { diff --git a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp index be2daae11e..200622da31 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemPostFunction.cpp @@ -756,7 +756,10 @@ void CylinderWidget::radiusChanged(double) PROPERTY_SOURCE(FemGui::ViewProviderFemPostPlaneFunction, FemGui::ViewProviderFemPostFunction) // NOTE: The technical lower limit is at 1e-4 that the Coin3D manipulator can handle -static const App::PropertyFloatConstraint::Constraints scaleConstraint = {1e-4, DBL_MAX, 1.0}; +static const App::PropertyFloatConstraint::Constraints scaleConstraint = { + 1e-4, + std::numeric_limits::max(), + 1.0}; ViewProviderFemPostPlaneFunction::ViewProviderFemPostPlaneFunction() : m_detectscale(false) @@ -1178,6 +1181,8 @@ SoGroup* postBox() SoGroup* postCylinder() { + using std::numbers::pi; + SoCoordinate3* points = new SoCoordinate3(); int nCirc = 20; const int nSide = 8; @@ -1189,8 +1194,8 @@ SoGroup* postCylinder() for (int i = 0; i < 2; ++i) { for (int j = 0; j < nCirc + 1; ++j) { points->point.set1Value(idx, - SbVec3f(std::cos(2 * M_PI / nCirc * j), - std::sin(2 * M_PI / nCirc * j), + SbVec3f(std::cos(2 * pi / nCirc * j), + std::sin(2 * pi / nCirc * j), -h / 2. + h * i)); ++idx; } @@ -1199,8 +1204,8 @@ SoGroup* postCylinder() for (int i = 0; i < nSide; ++i) { for (int j = 0; j < 2; ++j) { points->point.set1Value(idx, - SbVec3f(std::cos(2 * M_PI / nSide * i), - std::sin(2 * M_PI / nSide * i), + SbVec3f(std::cos(2 * pi / nSide * i), + std::sin(2 * pi / nSide * i), -h / 2. + h * j)); ++idx; } @@ -1243,24 +1248,26 @@ SoGroup* postPlane() SoGroup* postSphere() { + using std::numbers::pi; + SoCoordinate3* points = new SoCoordinate3(); points->point.setNum(2 * 84); int idx = 0; for (int i = 0; i < 4; i++) { for (int j = 0; j < 21; j++) { points->point.set1Value(idx, - SbVec3f(std::sin(2 * M_PI / 20 * j) * std::cos(M_PI / 4 * i), - std::sin(2 * M_PI / 20 * j) * std::sin(M_PI / 4 * i), - std::cos(2 * M_PI / 20 * j))); + SbVec3f(std::sin(2 * pi / 20 * j) * std::cos(pi / 4 * i), + std::sin(2 * pi / 20 * j) * std::sin(pi / 4 * i), + std::cos(2 * pi / 20 * j))); ++idx; } } for (int i = 0; i < 4; i++) { for (int j = 0; j < 21; j++) { points->point.set1Value(idx, - SbVec3f(std::sin(M_PI / 4 * i) * std::cos(2 * M_PI / 20 * j), - std::sin(M_PI / 4 * i) * std::sin(2 * M_PI / 20 * j), - std::cos(M_PI / 4 * i))); + SbVec3f(std::sin(pi / 4 * i) * std::cos(2 * pi / 20 * j), + std::sin(pi / 4 * i) * std::sin(2 * pi / 20 * j), + std::cos(pi / 4 * i))); ++idx; } } diff --git a/src/Mod/Import/App/AppImportPy.cpp b/src/Mod/Import/App/AppImportPy.cpp index 31fd806866..7aa936f1c2 100644 --- a/src/Mod/Import/App/AppImportPy.cpp +++ b/src/Mod/Import/App/AppImportPy.cpp @@ -27,7 +27,6 @@ #ifndef _PreComp_ #include #include -#include #if defined(__clang__) #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wextra-semi" diff --git a/src/Mod/Import/App/ExportOCAF.cpp b/src/Mod/Import/App/ExportOCAF.cpp index b4b7ad3a14..814140ce64 100644 --- a/src/Mod/Import/App/ExportOCAF.cpp +++ b/src/Mod/Import/App/ExportOCAF.cpp @@ -36,7 +36,6 @@ #include #include #include -#include #include #include #include // for Precision::Confusion() diff --git a/src/Mod/Import/App/ExportOCAF.h b/src/Mod/Import/App/ExportOCAF.h index 847b437cda..d74ab481d9 100644 --- a/src/Mod/Import/App/ExportOCAF.h +++ b/src/Mod/Import/App/ExportOCAF.h @@ -23,7 +23,6 @@ #ifndef IMPORT_EXPORTOCAF_H #define IMPORT_EXPORTOCAF_H -#include #include #include #include diff --git a/src/Mod/Import/App/ImportOCAF.cpp b/src/Mod/Import/App/ImportOCAF.cpp index 0d155d5201..89d40ec7d7 100644 --- a/src/Mod/Import/App/ImportOCAF.cpp +++ b/src/Mod/Import/App/ImportOCAF.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include // for Precision::Confusion() #include #endif diff --git a/src/Mod/Import/App/ImportOCAF.h b/src/Mod/Import/App/ImportOCAF.h index 18ae55312a..239cdc9787 100644 --- a/src/Mod/Import/App/ImportOCAF.h +++ b/src/Mod/Import/App/ImportOCAF.h @@ -23,7 +23,6 @@ #ifndef IMPORT_IMPORTOCAF_H #define IMPORT_IMPORTOCAF_H -#include #include #include #include diff --git a/src/Mod/Import/App/ImportOCAF2.h b/src/Mod/Import/App/ImportOCAF2.h index a850e3d583..fd264eb6d5 100644 --- a/src/Mod/Import/App/ImportOCAF2.h +++ b/src/Mod/Import/App/ImportOCAF2.h @@ -23,7 +23,6 @@ #ifndef IMPORT_IMPORTOCAF2_H #define IMPORT_IMPORTOCAF2_H -#include #include #include #include diff --git a/src/Mod/Import/App/ImportOCAFAssembly.cpp b/src/Mod/Import/App/ImportOCAFAssembly.cpp index 4d60e779aa..3a904ce589 100644 --- a/src/Mod/Import/App/ImportOCAFAssembly.cpp +++ b/src/Mod/Import/App/ImportOCAFAssembly.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #endif diff --git a/src/Mod/Import/App/ImportOCAFAssembly.h b/src/Mod/Import/App/ImportOCAFAssembly.h index ee18ab30a2..dad46e8cba 100644 --- a/src/Mod/Import/App/ImportOCAFAssembly.h +++ b/src/Mod/Import/App/ImportOCAFAssembly.h @@ -23,7 +23,6 @@ #ifndef IMPORT_ImportOCAFAssembly_H #define IMPORT_ImportOCAFAssembly_H -#include #include #include #include diff --git a/src/Mod/Import/App/Tools.h b/src/Mod/Import/App/Tools.h index 9d99cf5dae..56b704e010 100644 --- a/src/Mod/Import/App/Tools.h +++ b/src/Mod/Import/App/Tools.h @@ -41,7 +41,7 @@ struct ShapeHasher #if OCC_VERSION_HEX >= 0x070800 return std::hash {}(shape); #else - return shape.HashCode(INT_MAX); + return shape.HashCode(std::numeric_limits::max()); #endif } }; @@ -53,7 +53,7 @@ struct LabelHasher #if OCC_VERSION_HEX >= 0x070800 return std::hash {}(label); #else - return TDF_LabelMapHasher::HashCode(label, INT_MAX); + return TDF_LabelMapHasher::HashCode(label, std::numeric_limits::max()); #endif } }; diff --git a/src/Mod/Import/App/dxf/ImpExpDxf.cpp b/src/Mod/Import/App/dxf/ImpExpDxf.cpp index 13f16b3ece..913d53aae6 100644 --- a/src/Mod/Import/App/dxf/ImpExpDxf.cpp +++ b/src/Mod/Import/App/dxf/ImpExpDxf.cpp @@ -977,8 +977,8 @@ void ImpExpDxfWrite::exportEllipse(BRepAdaptor_Curve& c) // rotation appears to be the clockwise(?) angle between major & +Y?? double rotation = xaxis.AngleWithRef(gp_Dir(0, 1, 0), gp_Dir(0, 0, 1)); - // 2*M_PI = 6.28319 is invalid(doesn't display in LibreCAD), but 2PI = 6.28318 is valid! - // writeEllipse(center, major, minor, rotation, 0.0, 2 * M_PI, true ); + // 2*pi = 6.28319 is invalid(doesn't display in LibreCAD), but 2PI = 6.28318 is valid! + // writeEllipse(center, major, minor, rotation, 0.0, 2 * std::numbers::pi, true ); writeEllipse(center, major, minor, rotation, 0.0, 6.28318, true); } @@ -1036,8 +1036,8 @@ void ImpExpDxfWrite::exportEllipseArc(BRepAdaptor_Curve& c) // a > 0 ==> v2 is CCW from v1 (righthanded)? // a < 0 ==> v2 is CW from v1 (lefthanded)? - double startAngle = fmod(f, 2.0 * M_PI); // revolutions - double endAngle = fmod(l, 2.0 * M_PI); + double startAngle = fmod(f, 2.0 * std::numbers::pi); // revolutions + double endAngle = fmod(l, 2.0 * std::numbers::pi); bool endIsCW = (a < 0) ? true : false; // if !endIsCW swap(start,end) // not sure if this is a hack or not. seems to make valid arcs. if (!endIsCW) { diff --git a/src/Mod/Import/App/dxf/dxf.cpp b/src/Mod/Import/App/dxf/dxf.cpp index 54b40ad234..0799e021ba 100644 --- a/src/Mod/Import/App/dxf/dxf.cpp +++ b/src/Mod/Import/App/dxf/dxf.cpp @@ -5,8 +5,6 @@ #include "PreCompiled.h" -// required by windows for M_PI definition -#define _USE_MATH_DEFINES #include #include #include @@ -1584,10 +1582,10 @@ void CDxfWrite::writeAngularDimBlock(const double* textMidPoint, double span = fabs(endAngle - startAngle); double offset = span * 0.10; if (startAngle < 0) { - startAngle += 2 * M_PI; + startAngle += 2 * std::numbers::pi; } if (endAngle < 0) { - endAngle += 2 * M_PI; + endAngle += 2 * std::numbers::pi; } Base::Vector3d startOff(cos(startAngle + offset), sin(startAngle + offset), 0.0); Base::Vector3d endOff(cos(endAngle - offset), sin(endAngle - offset), 0.0); @@ -2130,7 +2128,7 @@ bool CDxfRead::ReadEllipse() Base::Vector3d majorAxisEnd; // relative to centre double eccentricity = 0; double startAngleRadians = 0; - double endAngleRadians = 2 * M_PI; + double endAngleRadians = 2 * std::numbers::pi; Setup3DVectorAttribute(ePrimaryPoint, centre); Setup3DVectorAttribute(ePoint2, majorAxisEnd); diff --git a/src/Mod/Import/Gui/AppImportGuiPy.cpp b/src/Mod/Import/Gui/AppImportGuiPy.cpp index 246a1dafb2..2a6143c21e 100644 --- a/src/Mod/Import/Gui/AppImportGuiPy.cpp +++ b/src/Mod/Import/Gui/AppImportGuiPy.cpp @@ -25,7 +25,6 @@ #define WNT // avoid conflict with GUID #endif #ifndef _PreComp_ -#include #include #include diff --git a/src/Mod/Inspection/App/InspectionFeature.cpp b/src/Mod/Inspection/App/InspectionFeature.cpp index bb0cdee9eb..ce6868327f 100644 --- a/src/Mod/Inspection/App/InspectionFeature.cpp +++ b/src/Mod/Inspection/App/InspectionFeature.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ #include #include +#include #include #include @@ -316,7 +317,7 @@ InspectNominalMesh::~InspectNominalMesh() float InspectNominalMesh::getDistance(const Base::Vector3f& point) const { if (!_box.IsInBox(point)) { - return FLT_MAX; // must be inside bbox + return std::numeric_limits::max(); // must be inside bbox } std::vector indices; @@ -327,7 +328,7 @@ float InspectNominalMesh::getDistance(const Base::Vector3f& point) const indices.insert(indices.begin(), inds.begin(), inds.end()); } - float fMinDist = FLT_MAX; + float fMinDist = std::numeric_limits::max(); bool positive = true; for (unsigned long it : indices) { MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(it); @@ -393,7 +394,7 @@ InspectNominalFastMesh::~InspectNominalFastMesh() float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const { if (!_box.IsInBox(point)) { - return FLT_MAX; // must be inside bbox + return std::numeric_limits::max(); // must be inside bbox } std::set indices; @@ -413,7 +414,7 @@ float InspectNominalFastMesh::getDistance(const Base::Vector3f& point) const } #endif - float fMinDist = FLT_MAX; + float fMinDist = std::numeric_limits::max(); bool positive = true; for (unsigned long it : indices) { MeshCore::MeshGeomFacet geomFace = _mesh.GetFacet(it); @@ -457,7 +458,7 @@ float InspectNominalPoints::getDistance(const Base::Vector3f& point) const _pGrid->Position(pointd, x, y, z); _pGrid->GetElements(x, y, z, indices); - double fMinDist = DBL_MAX; + double fMinDist = std::numeric_limits::max(); for (unsigned long it : indices) { Base::Vector3d pt = _rKernel.getPoint(it); double fDist = Base::Distance(pointd, pt); @@ -501,7 +502,7 @@ float InspectNominalShape::getDistance(const Base::Vector3f& point) const BRepBuilderAPI_MakeVertex mkVert(pnt3d); distss->LoadS2(mkVert.Vertex()); - float fMinDist = FLT_MAX; + float fMinDist = std::numeric_limits::max(); if (distss->Perform() && distss->NbSolution() > 0) { fMinDist = (float)distss->Value(); // the shape is a solid, check if the vertex is inside @@ -713,7 +714,7 @@ struct DistanceInspection { Base::Vector3f pnt = actual->getPoint(index); - float fMinDist = FLT_MAX; + float fMinDist = std::numeric_limits::max(); for (auto it : nominal) { float fDist = it->getDistance(pnt); if (fabs(fDist) < fabs(fMinDist)) { @@ -722,10 +723,10 @@ struct DistanceInspection } if (fMinDist > this->radius) { - fMinDist = FLT_MAX; + fMinDist = std::numeric_limits::max(); } else if (-fMinDist > this->radius) { - fMinDist = -FLT_MAX; + fMinDist = -std::numeric_limits::max(); } return fMinDist; @@ -884,7 +885,7 @@ App::DocumentObjectExecReturn* Feature::execute() float fRMS = 0; int countRMS = 0; for (std::vector::iterator it = vals.begin(); it != vals.end(); ++it) { - if (fabs(*it) < FLT_MAX) { + if (fabs(*it) < std::numeric_limits::max()) { fRMS += (*it) * (*it); countRMS++; } @@ -904,7 +905,7 @@ App::DocumentObjectExecReturn* Feature::execute() DistanceInspectionRMS res; Base::Vector3f pnt = actual->getPoint(index); - float fMinDist = FLT_MAX; + float fMinDist = std::numeric_limits::max(); for (auto it : inspectNominal) { float fDist = it->getDistance(pnt); if (fabs(fDist) < fabs(fMinDist)) { @@ -913,10 +914,10 @@ App::DocumentObjectExecReturn* Feature::execute() } if (fMinDist > this->SearchRadius.getValue()) { - fMinDist = FLT_MAX; + fMinDist = std::numeric_limits::max(); } else if (-fMinDist > this->SearchRadius.getValue()) { - fMinDist = -FLT_MAX; + fMinDist = -std::numeric_limits::max(); } else { res.m_sumsq += fMinDist * fMinDist; diff --git a/src/Mod/Inspection/Gui/PreCompiled.h b/src/Mod/Inspection/Gui/PreCompiled.h index d6afd093c4..d304568b6a 100644 --- a/src/Mod/Inspection/Gui/PreCompiled.h +++ b/src/Mod/Inspection/Gui/PreCompiled.h @@ -35,7 +35,6 @@ #ifdef _PreComp_ // STL -#include // Inventor #include diff --git a/src/Mod/Inspection/Gui/ViewProviderInspection.h b/src/Mod/Inspection/Gui/ViewProviderInspection.h index f311da9b45..ca3a575502 100644 --- a/src/Mod/Inspection/Gui/ViewProviderInspection.h +++ b/src/Mod/Inspection/Gui/ViewProviderInspection.h @@ -107,7 +107,7 @@ private: SoCoordinate3* pcCoords; private: - float search_radius {FLT_MAX}; + float search_radius {std::numeric_limits::max()}; static bool addflag; static App::PropertyFloatConstraint::Constraints floatRange; }; diff --git a/src/Mod/Inspection/Gui/VisualInspection.cpp b/src/Mod/Inspection/Gui/VisualInspection.cpp index afaaad9845..4170624344 100644 --- a/src/Mod/Inspection/Gui/VisualInspection.cpp +++ b/src/Mod/Inspection/Gui/VisualInspection.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #endif #include @@ -100,9 +99,9 @@ VisualInspection::VisualInspection(QWidget* parent, Qt::WindowFlags fl) ui->textLabel2->hide(); ui->thickness->hide(); ui->searchRadius->setUnit(Base::Unit::Length); - ui->searchRadius->setRange(0, DBL_MAX); + ui->searchRadius->setRange(0, std::numeric_limits::max()); ui->thickness->setUnit(Base::Unit::Length); - ui->thickness->setRange(0, DBL_MAX); + ui->thickness->setRange(0, std::numeric_limits::max()); App::Document* doc = App::GetApplication().getActiveDocument(); // disable Ok button and enable of at least one item in each view is on diff --git a/src/Mod/Material/App/PreCompiled.h b/src/Mod/Material/App/PreCompiled.h index 085b2d5ca4..255a52e0de 100644 --- a/src/Mod/Material/App/PreCompiled.h +++ b/src/Mod/Material/App/PreCompiled.h @@ -42,7 +42,6 @@ #ifdef _PreComp_ // standard -#include #include // STL diff --git a/src/Mod/Material/Gui/ArrayDelegate.cpp b/src/Mod/Material/Gui/ArrayDelegate.cpp index 38f6f14246..91ff581927 100644 --- a/src/Mod/Material/Gui/ArrayDelegate.cpp +++ b/src/Mod/Material/Gui/ArrayDelegate.cpp @@ -125,7 +125,7 @@ QWidget* ArrayDelegate::createWidget(QWidget* parent, const QVariant& item) cons else if (_type == Materials::MaterialValue::Integer) { Gui::UIntSpinBox* spinner = new Gui::UIntSpinBox(parent); spinner->setMinimum(0); - spinner->setMaximum(UINT_MAX); + spinner->setMaximum(std::numeric_limits::max()); spinner->setValue(item.toUInt()); widget = spinner; } diff --git a/src/Mod/Material/Gui/BaseDelegate.cpp b/src/Mod/Material/Gui/BaseDelegate.cpp index 27123a2a0e..12291aaf93 100644 --- a/src/Mod/Material/Gui/BaseDelegate.cpp +++ b/src/Mod/Material/Gui/BaseDelegate.cpp @@ -414,7 +414,7 @@ BaseDelegate::createWidget(QWidget* parent, const QVariant& item, const QModelIn if (type == Materials::MaterialValue::Integer) { auto spinner = new Gui::UIntSpinBox(parent); spinner->setMinimum(0); - spinner->setMaximum(UINT_MAX); + spinner->setMaximum(std::numeric_limits::max()); spinner->setValue(item.toUInt()); widget = spinner; } diff --git a/src/Mod/Material/Gui/MaterialDelegate.cpp b/src/Mod/Material/Gui/MaterialDelegate.cpp index 7e58258bc0..ad36b74462 100644 --- a/src/Mod/Material/Gui/MaterialDelegate.cpp +++ b/src/Mod/Material/Gui/MaterialDelegate.cpp @@ -424,7 +424,7 @@ QWidget* MaterialDelegate::createWidget(QWidget* parent, if (type == Materials::MaterialValue::Integer) { auto spinner = new Gui::IntSpinBox(parent); spinner->setMinimum(0); - spinner->setMaximum(INT_MAX); + spinner->setMaximum(std::numeric_limits::max()); spinner->setValue(item.toInt()); widget = spinner; } diff --git a/src/Mod/Material/Gui/PreCompiled.h b/src/Mod/Material/Gui/PreCompiled.h index 85b68f8801..aef9192070 100644 --- a/src/Mod/Material/Gui/PreCompiled.h +++ b/src/Mod/Material/Gui/PreCompiled.h @@ -42,7 +42,6 @@ #ifdef _PreComp_ // standard -#include #include #include diff --git a/src/Mod/Measure/App/MeasureAngle.cpp b/src/Mod/Measure/App/MeasureAngle.cpp index 73021f0b4e..5e72fbe5b4 100644 --- a/src/Mod/Measure/App/MeasureAngle.cpp +++ b/src/Mod/Measure/App/MeasureAngle.cpp @@ -108,7 +108,7 @@ bool MeasureAngle::isPrioritizedSelection(const App::MeasureSelection& selection getVec(*ob2, sub2, vec2); - double angle = std::fmod(vec1.GetAngle(vec2), D_PI); + double angle = std::fmod(vec1.GetAngle(vec2), std::numbers::pi); return angle > Base::Precision::Angular(); } diff --git a/src/Mod/Measure/App/PreCompiled.h b/src/Mod/Measure/App/PreCompiled.h index c3f684ddc1..ee6e3a5092 100644 --- a/src/Mod/Measure/App/PreCompiled.h +++ b/src/Mod/Measure/App/PreCompiled.h @@ -30,7 +30,6 @@ #ifdef _PreComp_ // standard -#include #include // STL diff --git a/src/Mod/Measure/Gui/PreCompiled.h b/src/Mod/Measure/Gui/PreCompiled.h index a2a4065edf..c897421afa 100644 --- a/src/Mod/Measure/Gui/PreCompiled.h +++ b/src/Mod/Measure/Gui/PreCompiled.h @@ -44,7 +44,6 @@ #ifdef _PreComp_ // standard -#include #include // STL diff --git a/src/Mod/Measure/Gui/ViewProviderMeasureAngle.cpp b/src/Mod/Measure/Gui/ViewProviderMeasureAngle.cpp index 5c1efba5f3..33cfbd62b2 100644 --- a/src/Mod/Measure/Gui/ViewProviderMeasureAngle.cpp +++ b/src/Mod/Measure/Gui/ViewProviderMeasureAngle.cpp @@ -325,7 +325,7 @@ void ViewProviderMeasureAngle::redrawAnnotation() { auto obj = dynamic_cast(getMeasureObject()); double angleDeg = obj->Angle.getValue(); - constexpr double radiansPerDegree = M_PI / 180.0; + constexpr double radiansPerDegree = std::numbers::pi / 180.0; this->fieldAngle = angleDeg * radiansPerDegree; // Set matrix diff --git a/src/Mod/Mesh/App/Core/Algorithm.cpp b/src/Mod/Mesh/App/Core/Algorithm.cpp index 9b9ebc1b64..3f513925f8 100644 --- a/src/Mod/Mesh/App/Core/Algorithm.cpp +++ b/src/Mod/Mesh/App/Core/Algorithm.cpp @@ -295,7 +295,7 @@ float MeshAlgorithm::GetAverageEdgeLength() const float MeshAlgorithm::GetMinimumEdgeLength() const { - float fLen = FLOAT_MAX; + float fLen = std::numeric_limits::max(); MeshFacetIterator cF(_rclMesh); for (cF.Init(); cF.More(); cF.Next()) { for (int i = 0; i < 3; i++) { @@ -785,19 +785,20 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, } } + constexpr auto max = std::numeric_limits::max(); // Get the new neighbour to our reference facet MeshFacet facet; unsigned short ref_side = rFace.Side(refPoint0, refPoint1); - unsigned short tri_side = USHRT_MAX; + unsigned short tri_side = max; if (cTria.NeedsReindexing()) { // the referenced indices of the polyline refPoint0 = 0; refPoint1 = 1; } - if (ref_side < USHRT_MAX) { + if (ref_side < max) { for (const auto& face : faces) { tri_side = face.Side(refPoint0, refPoint1); - if (tri_side < USHRT_MAX) { + if (tri_side < max) { facet = face; break; } @@ -805,7 +806,7 @@ bool MeshAlgorithm::FillupHole(const std::vector& boundary, } // in case the reference facet has not an open edge print a log message - if (ref_side == USHRT_MAX || tri_side == USHRT_MAX) { + if (ref_side == max || tri_side == max) { Base::Console().Log( "MeshAlgorithm::FillupHole: Expected open edge for facet <%d, %d, %d>\n", rFace._aulPoints[0], @@ -1461,7 +1462,7 @@ bool MeshAlgorithm::NearestPointFromPoint(const Base::Vector3f& rclPt, } // calc each facet - float fMinDist = FLOAT_MAX; + float fMinDist = std::numeric_limits::max(); FacetIndex ulInd = FACET_INDEX_MAX; MeshFacetIterator pF(_rclMesh); for (pF.Init(); pF.More(); pF.Next()) { diff --git a/src/Mod/Mesh/App/Core/Approximation.cpp b/src/Mod/Mesh/App/Core/Approximation.cpp index 8b728ece41..cf7123a9ed 100644 --- a/src/Mod/Mesh/App/Core/Approximation.cpp +++ b/src/Mod/Mesh/App/Core/Approximation.cpp @@ -143,7 +143,7 @@ float PlaneFit::Fit() { _bIsFitted = true; if (CountPoints() < 3) { - return FLOAT_MAX; + return std::numeric_limits::max(); } double sxx {0.0}; @@ -207,7 +207,7 @@ float PlaneFit::Fit() akMat.EigenDecomposition(rkRot, rkDiag); } catch (const std::exception&) { - return FLOAT_MAX; + return std::numeric_limits::max(); } // We know the Eigenvalues are ordered @@ -215,7 +215,7 @@ float PlaneFit::Fit() // // points describe a line or even are identical if (rkDiag(1, 1) <= 0) { - return FLOAT_MAX; + return std::numeric_limits::max(); } Wm4::Vector3 U = rkRot.GetColumn(1); @@ -225,7 +225,7 @@ float PlaneFit::Fit() // It may happen that the result have nan values for (int i = 0; i < 3; i++) { if (boost::math::isnan(W[i])) { - return FLOAT_MAX; + return std::numeric_limits::max(); } } @@ -253,7 +253,7 @@ float PlaneFit::Fit() // In case sigma is nan if (boost::math::isnan(sigma)) { - return FLOAT_MAX; + return std::numeric_limits::max(); } // This must be caused by some round-off errors. Theoretically it's impossible @@ -318,7 +318,7 @@ Base::Vector3f PlaneFit::GetNormal() const float PlaneFit::GetDistanceToPlane(const Base::Vector3f& rcPoint) const { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (_bIsFitted) { fResult = (rcPoint - _vBase) * _vDirW; } @@ -332,7 +332,7 @@ float PlaneFit::GetStdDeviation() const // Standard deviation: SD=SQRT(VAR) // Standard error of the mean: SE=SD/SQRT(N) if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } float fSumXi = 0.0F, fSumXi2 = 0.0F, fMean = 0.0F, fDist = 0.0F; @@ -356,11 +356,11 @@ float PlaneFit::GetSignedStdDeviation() const // of normal direction the value will be // positive otherwise negative if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } float fSumXi = 0.0F, fSumXi2 = 0.0F, fMean = 0.0F, fDist = 0.0F; - float fMinDist = FLOAT_MAX; + float fMinDist = std::numeric_limits::max(); float fFactor = 0.0F; float ulPtCt = float(CountPoints()); @@ -426,7 +426,7 @@ void PlaneFit::Dimension(float& length, float& width) const std::vector PlaneFit::GetLocalPoints() const { std::vector localPoints; - if (_bIsFitted && _fLastResult < FLOAT_MAX) { + if (_bIsFitted && _fLastResult < std::numeric_limits::max()) { Base::Vector3d bs = Base::convertTo(this->_vBase); Base::Vector3d ex = Base::convertTo(this->_vDirU); Base::Vector3d ey = Base::convertTo(this->_vDirV); @@ -507,12 +507,12 @@ double QuadraticFit::GetCoeff(std::size_t ulIndex) const return _fCoeff[ulIndex]; } - return double(FLOAT_MAX); + return double(std::numeric_limits::max()); } float QuadraticFit::Fit() { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (CountPoints() > 0) { std::vector> cPts; @@ -595,14 +595,14 @@ void QuadraticFit::CalcZValues(double x, double y, double& dZ1, double& dZ2) con - 4 * _fCoeff[6] * _fCoeff[4] * x * x - 4 * _fCoeff[6] * _fCoeff[5] * y * y; if (fabs(_fCoeff[6]) < 0.000005) { - dZ1 = double(FLOAT_MAX); - dZ2 = double(FLOAT_MAX); + dZ1 = double(std::numeric_limits::max()); + dZ2 = double(std::numeric_limits::max()); return; } if (dDisk < 0.0) { - dZ1 = double(FLOAT_MAX); - dZ2 = double(FLOAT_MAX); + dZ1 = double(std::numeric_limits::max()); + dZ2 = double(std::numeric_limits::max()); return; } @@ -620,7 +620,7 @@ SurfaceFit::SurfaceFit() float SurfaceFit::Fit() { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (CountPoints() > 0) { fResult = float(PolynomFit()); @@ -671,8 +671,8 @@ bool SurfaceFit::GetCurvatureInfo(double x, double y, double z, double& rfCurv0, double SurfaceFit::PolynomFit() { - if (PlaneFit::Fit() >= FLOAT_MAX) { - return double(FLOAT_MAX); + if (PlaneFit::Fit() >= std::numeric_limits::max()) { + return double(std::numeric_limits::max()); } Base::Vector3d bs = Base::convertTo(this->_vBase); @@ -1165,7 +1165,7 @@ void CylinderFit::SetInitialValues(const Base::Vector3f& b, const Base::Vector3f float CylinderFit::Fit() { if (CountPoints() < 7) { - return FLOAT_MAX; + return std::numeric_limits::max(); } _bIsFitted = true; @@ -1180,7 +1180,7 @@ float CylinderFit::Fit() } float result = cylFit.Fit(); - if (result < FLOAT_MAX) { + if (result < std::numeric_limits::max()) { Base::Vector3d base = cylFit.GetBase(); Base::Vector3d dir = cylFit.GetAxis(); @@ -1284,7 +1284,7 @@ Base::Vector3f CylinderFit::GetAxis() const float CylinderFit::GetDistanceToCylinder(const Base::Vector3f& rcPoint) const { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (_bIsFitted) { fResult = rcPoint.DistanceToLine(_vBase, _vAxis) - _fRadius; } @@ -1298,7 +1298,7 @@ float CylinderFit::GetStdDeviation() const // Standard deviation: SD=SQRT(VAR) // Standard error of the mean: SE=SD/SQRT(N) if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } float fSumXi = 0.0F, fSumXi2 = 0.0F, fMean = 0.0F, fDist = 0.0F; @@ -1318,8 +1318,8 @@ float CylinderFit::GetStdDeviation() const void CylinderFit::GetBounding(Base::Vector3f& bottom, Base::Vector3f& top) const { - float distMin = FLT_MAX; - float distMax = FLT_MIN; + float distMin = std::numeric_limits::max(); + float distMax = std::numeric_limits::min(); std::list::const_iterator cIt; for (cIt = _vPoints.begin(); cIt != _vPoints.end(); ++cIt) { @@ -1384,7 +1384,7 @@ float SphereFit::GetRadius() const return _fRadius; } - return FLOAT_MAX; + return std::numeric_limits::max(); } Base::Vector3f SphereFit::GetCenter() const @@ -1400,7 +1400,7 @@ float SphereFit::Fit() { _bIsFitted = true; if (CountPoints() < 4) { - return FLOAT_MAX; + return std::numeric_limits::max(); } std::vector input; @@ -1433,7 +1433,7 @@ float SphereFit::Fit() sphereFit.AddPoints(_vPoints); sphereFit.ComputeApproximations(); float result = sphereFit.Fit(); - if (result < FLOAT_MAX) { + if (result < std::numeric_limits::max()) { Base::Vector3d center = sphereFit.GetCenter(); #if defined(_DEBUG) Base::Console().Message("MeshCoreFit::Sphere Fit: Center: (%0.4f, %0.4f, %0.4f), Radius: " @@ -1455,7 +1455,7 @@ float SphereFit::Fit() float SphereFit::GetDistanceToSphere(const Base::Vector3f& rcPoint) const { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (_bIsFitted) { fResult = Base::Vector3f(rcPoint - _vCenter).Length() - _fRadius; } @@ -1469,7 +1469,7 @@ float SphereFit::GetStdDeviation() const // Standard deviation: SD=SQRT(VAR) // Standard error of the mean: SE=SD/SQRT(N) if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } float fSumXi = 0.0F, fSumXi2 = 0.0F, fMean = 0.0F, fDist = 0.0F; @@ -1533,7 +1533,7 @@ float PolynomialFit::Fit() } } catch (const std::exception&) { - return FLOAT_MAX; + return std::numeric_limits::max(); } return 0.0F; diff --git a/src/Mod/Mesh/App/Core/Approximation.h b/src/Mod/Mesh/App/Core/Approximation.h index 1bbe71ebd5..32e7211390 100644 --- a/src/Mod/Mesh/App/Core/Approximation.h +++ b/src/Mod/Mesh/App/Core/Approximation.h @@ -201,7 +201,8 @@ protected: // NOLINTBEGIN std::list _vPoints; /**< Holds the points for the fit algorithm. */ bool _bIsFitted {false}; /**< Flag, whether the fit has been called. */ - float _fLastResult {FLOAT_MAX}; /**< Stores the last result of the fit */ + float _fLastResult { + std::numeric_limits::max()}; /**< Stores the last result of the fit */ // NOLINTEND }; diff --git a/src/Mod/Mesh/App/Core/Curvature.cpp b/src/Mod/Mesh/App/Core/Curvature.cpp index 07334f7785..15b2c8733b 100644 --- a/src/Mod/Mesh/App/Core/Curvature.cpp +++ b/src/Mod/Mesh/App/Core/Curvature.cpp @@ -423,14 +423,14 @@ CurvatureInfo FacetCurvature::Compute(FacetIndex index) const fMax = (float)dMax; } else { - fMin = FLT_MAX; - fMax = FLT_MAX; + fMin = std::numeric_limits::max(); + fMax = std::numeric_limits::max(); } } else { // too few points => cannot calc any properties - fMin = FLT_MAX; - fMax = FLT_MAX; + fMin = std::numeric_limits::max(); + fMax = std::numeric_limits::max(); } CurvatureInfo info; diff --git a/src/Mod/Mesh/App/Core/CylinderFit.cpp b/src/Mod/Mesh/App/Core/CylinderFit.cpp index face997e6b..cc44aa2d74 100644 --- a/src/Mod/Mesh/App/Core/CylinderFit.cpp +++ b/src/Mod/Mesh/App/Core/CylinderFit.cpp @@ -81,7 +81,7 @@ void CylinderFit::SetApproximations(double radius, const Base::Vector3d& axis) { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; _dRadius = radius; _vBase = base; @@ -94,7 +94,7 @@ void CylinderFit::SetApproximations(double radius, void CylinderFit::SetApproximations(const Base::Vector3d& base, const Base::Vector3d& axis) { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; _vBase = base; _vAxis = axis; @@ -168,7 +168,7 @@ int CylinderFit::GetNumIterations() const float CylinderFit::GetDistanceToCylinder(const Base::Vector3f& rcPoint) const { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (_bIsFitted) { Base::Vector3d pt(rcPoint.x, rcPoint.y, rcPoint.z); fResult = static_cast(pt.DistanceToLine(_vBase, _vAxis) - _dRadius); @@ -182,7 +182,7 @@ float CylinderFit::GetStdDeviation() const // Variance: VAR=(N/N-1)*[(1/N)*SUM(Xi^2)-M^2] // Standard deviation: SD=SQRT(VAR) if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } double sumXi = 0.0; @@ -239,7 +239,7 @@ void CylinderFit::ProjectToCylinder() void CylinderFit::ComputeApproximationsLine() { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; _vBase.Set(0.0, 0.0, 0.0); _vAxis.Set(0.0, 0.0, 0.0); @@ -266,13 +266,13 @@ void CylinderFit::ComputeApproximationsLine() float CylinderFit::Fit() { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; // A minimum of 5 surface points is needed to define a cylinder const int minPts = 5; if (CountPoints() < minPts) { - return FLOAT_MAX; + return std::numeric_limits::max(); } // If approximations have not been set/computed then compute some now using the line fit method @@ -308,7 +308,7 @@ float CylinderFit::Fit() // Solve the equations for the unknown corrections Eigen::LLT llt(atpa); if (llt.info() != Eigen::Success) { - return FLOAT_MAX; + return std::numeric_limits::max(); } Eigen::VectorXd x = llt.solve(atpl); @@ -327,7 +327,7 @@ float CylinderFit::Fit() // convergence bool vConverged {}; if (!computeResiduals(solDir, x, residuals, sigma0, _vConvLimit, vConverged)) { - return FLOAT_MAX; + return std::numeric_limits::max(); } if (!vConverged) { cont = true; @@ -335,13 +335,13 @@ float CylinderFit::Fit() // Update the parameters if (!updateParameters(solDir, x)) { - return FLOAT_MAX; + return std::numeric_limits::max(); } } // Check for convergence if (cont) { - return FLOAT_MAX; + return std::numeric_limits::max(); } _bIsFitted = true; diff --git a/src/Mod/Mesh/App/Core/Decimation.cpp b/src/Mod/Mesh/App/Core/Decimation.cpp index 096b438add..da40713799 100644 --- a/src/Mod/Mesh/App/Core/Decimation.cpp +++ b/src/Mod/Mesh/App/Core/Decimation.cpp @@ -123,7 +123,7 @@ void MeshSimplify::simplify(int targetSize) } // Simplification starts - alg.simplify_mesh(targetSize, FLT_MAX); + alg.simplify_mesh(targetSize, std::numeric_limits::max()); // Simplification done MeshPointArray new_points; diff --git a/src/Mod/Mesh/App/Core/Definitions.h b/src/Mod/Mesh/App/Core/Definitions.h index e8b2569d20..7802c3c512 100644 --- a/src/Mod/Mesh/App/Core/Definitions.h +++ b/src/Mod/Mesh/App/Core/Definitions.h @@ -27,7 +27,7 @@ #include #endif -#include +#include // default values #define MESH_MIN_PT_DIST 1.0e-6F @@ -36,33 +36,16 @@ #define MESH_REMOVE_MIN_LEN true #define MESH_REMOVE_G3_EDGES true -/* - * general constant definitions - */ -#define FLOAT_EPS 1.0e-4F - -#ifndef FLOAT_MAX -#define FLOAT_MAX 1e30F -#endif - -#ifndef DOUBLE_MAX -#define DOUBLE_MAX 1.7976931348623157E+308 /* max decimal value of a "double"*/ -#endif - -#ifndef DOUBLE_MIN -#define DOUBLE_MIN 2.2250738585072014E-308 /* min decimal value of a "double"*/ -#endif - namespace MeshCore { // type definitions using ElementIndex = unsigned long; -const ElementIndex ELEMENT_INDEX_MAX = ULONG_MAX; +const ElementIndex ELEMENT_INDEX_MAX = std::numeric_limits::max(); using FacetIndex = ElementIndex; -const FacetIndex FACET_INDEX_MAX = ULONG_MAX; +const FacetIndex FACET_INDEX_MAX = std::numeric_limits::max(); using PointIndex = ElementIndex; -const PointIndex POINT_INDEX_MAX = ULONG_MAX; +const PointIndex POINT_INDEX_MAX = std::numeric_limits::max(); template class Math diff --git a/src/Mod/Mesh/App/Core/Elements.cpp b/src/Mod/Mesh/App/Core/Elements.cpp index 5d365251db..428358f9ca 100644 --- a/src/Mod/Mesh/App/Core/Elements.cpp +++ b/src/Mod/Mesh/App/Core/Elements.cpp @@ -1309,9 +1309,9 @@ unsigned short MeshGeomFacet::NearestEdgeToPoint(const Base::Vector3f& rclPt) co const Base::Vector3f& rcP2 = _aclPoints[1]; const Base::Vector3f& rcP3 = _aclPoints[2]; - float fD1 = FLOAT_MAX; - float fD2 = FLOAT_MAX; - float fD3 = FLOAT_MAX; + float fD1 = std::numeric_limits::max(); + float fD2 = std::numeric_limits::max(); + float fD3 = std::numeric_limits::max(); // 1st edge Base::Vector3f clDir = rcP2 - rcP1; @@ -1383,9 +1383,9 @@ void MeshGeomFacet::NearestEdgeToPoint(const Base::Vector3f& rclPt, const Base::Vector3f& rcP2 = _aclPoints[1]; const Base::Vector3f& rcP3 = _aclPoints[2]; - float fD1 = FLOAT_MAX; - float fD2 = FLOAT_MAX; - float fD3 = FLOAT_MAX; + float fD1 = std::numeric_limits::max(); + float fD2 = std::numeric_limits::max(); + float fD3 = std::numeric_limits::max(); // 1st edge Base::Vector3f clDir = rcP2 - rcP1; diff --git a/src/Mod/Mesh/App/Core/Elements.h b/src/Mod/Mesh/App/Core/Elements.h index 2181301bca..1c2521576f 100644 --- a/src/Mod/Mesh/App/Core/Elements.h +++ b/src/Mod/Mesh/App/Core/Elements.h @@ -23,7 +23,6 @@ #ifndef MESH_ELEMENTS_H #define MESH_ELEMENTS_H -#include #include #include #include @@ -1147,7 +1146,7 @@ inline unsigned short MeshFacet::Side(FacetIndex ulNIndex) const return 2; } - return USHRT_MAX; + return std::numeric_limits::max(); } inline unsigned short MeshFacet::Side(PointIndex ulP0, PointIndex ulP1) const @@ -1177,7 +1176,7 @@ inline unsigned short MeshFacet::Side(PointIndex ulP0, PointIndex ulP1) const } } - return USHRT_MAX; + return std::numeric_limits::max(); } inline unsigned short MeshFacet::Side(const MeshFacet& rFace) const @@ -1185,12 +1184,12 @@ inline unsigned short MeshFacet::Side(const MeshFacet& rFace) const unsigned short side {}; for (int i = 0; i < 3; i++) { side = Side(rFace._aulPoints[i], rFace._aulPoints[(i + 1) % 3]); - if (side != USHRT_MAX) { + if (side != std::numeric_limits::max()) { return side; } } - return USHRT_MAX; + return std::numeric_limits::max(); } inline bool MeshFacet::IsEqual(const MeshFacet& rcFace) const diff --git a/src/Mod/Mesh/App/Core/Grid.cpp b/src/Mod/Mesh/App/Core/Grid.cpp index 603650ed7b..083d834f10 100644 --- a/src/Mod/Mesh/App/Core/Grid.cpp +++ b/src/Mod/Mesh/App/Core/Grid.cpp @@ -639,7 +639,7 @@ unsigned long MeshGrid::GetIndexToPosition(unsigned long ulX, unsigned long ulY, unsigned long ulZ) const { if (!CheckPos(ulX, ulY, ulZ)) { - return ULONG_MAX; + return std::numeric_limits::max(); } return (ulZ * _ulCtGridsY + ulY) * _ulCtGridsX + ulX; } @@ -654,9 +654,9 @@ bool MeshGrid::GetPositionToIndex(unsigned long id, ulZ = id / (_ulCtGridsX * _ulCtGridsY); if (!CheckPos(ulX, ulY, ulZ)) { - ulX = ULONG_MAX; - ulY = ULONG_MAX; - ulZ = ULONG_MAX; + ulX = std::numeric_limits::max(); + ulY = std::numeric_limits::max(); + ulZ = std::numeric_limits::max(); return false; } @@ -760,7 +760,7 @@ void MeshFacetGrid::RebuildGrid() unsigned long MeshFacetGrid::SearchNearestFromPoint(const Base::Vector3f& rclPt) const { ElementIndex ulFacetInd = ELEMENT_INDEX_MAX; - float fMinDist = FLOAT_MAX; + float fMinDist = std::numeric_limits::max(); Base::BoundBox3f clBB = GetBoundBox(); if (clBB.IsInBox(rclPt)) { // Point lies within @@ -1154,7 +1154,7 @@ bool MeshGridIterator::InitOnRay(const Base::Vector3f& rclPt, // needed in NextOnRay() to avoid an infinite loop _cSearchPositions.clear(); - _fMaxSearchArea = FLOAT_MAX; + _fMaxSearchArea = std::numeric_limits::max(); raulElements.clear(); diff --git a/src/Mod/Mesh/App/Core/Grid.h b/src/Mod/Mesh/App/Core/Grid.h index 3cd9990ce9..e5f9c46360 100644 --- a/src/Mod/Mesh/App/Core/Grid.h +++ b/src/Mod/Mesh/App/Core/Grid.h @@ -447,7 +447,7 @@ private: Base::Vector3f _clPt; /**< Base point of search ray. */ Base::Vector3f _clDir; /**< Direction of search ray. */ bool _bValidRay {false}; /**< Search ray ok? */ - float _fMaxSearchArea {FLOAT_MAX}; + float _fMaxSearchArea {std::numeric_limits::max()}; /** Checks if a grid position is already visited by NextOnRay(). */ struct GridElement { diff --git a/src/Mod/Mesh/App/Core/Iterator.h b/src/Mod/Mesh/App/Core/Iterator.h index 4b8c5dddd3..3b7d741d02 100644 --- a/src/Mod/Mesh/App/Core/Iterator.h +++ b/src/Mod/Mesh/App/Core/Iterator.h @@ -23,7 +23,6 @@ #ifndef MESH_ITERATOR_H #define MESH_ITERATOR_H -#include #include diff --git a/src/Mod/Mesh/App/Core/MeshKernel.cpp b/src/Mod/Mesh/App/Core/MeshKernel.cpp index be46d392c4..b2def70220 100644 --- a/src/Mod/Mesh/App/Core/MeshKernel.cpp +++ b/src/Mod/Mesh/App/Core/MeshKernel.cpp @@ -310,7 +310,7 @@ unsigned long MeshKernel::AddFacets(const std::vector& rclFAry, bool if (ulF0 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF0].Side(ulP0, ulP1); - assert(usSide != USHRT_MAX); + assert(usSide != std::numeric_limits::max()); _aclFacetArray[ulF0]._aulNeighbours[usSide] = FACET_INDEX_MAX; } } @@ -342,13 +342,13 @@ unsigned long MeshKernel::AddFacets(const std::vector& rclFAry, bool if (ulF0 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF0].Side(ulP0, ulP1); - assert(usSide != USHRT_MAX); + assert(usSide != std::numeric_limits::max()); _aclFacetArray[ulF0]._aulNeighbours[usSide] = ulF1; } if (ulF1 != FACET_INDEX_MAX) { unsigned short usSide = _aclFacetArray[ulF1].Side(ulP0, ulP1); - assert(usSide != USHRT_MAX); + assert(usSide != std::numeric_limits::max()); _aclFacetArray[ulF1]._aulNeighbours[usSide] = ulF0; } } diff --git a/src/Mod/Mesh/App/Core/Projection.cpp b/src/Mod/Mesh/App/Core/Projection.cpp index b3bd4d584e..06c676b234 100644 --- a/src/Mod/Mesh/App/Core/Projection.cpp +++ b/src/Mod/Mesh/App/Core/Projection.cpp @@ -78,7 +78,7 @@ bool MeshProjection::connectLines(std::list& polyline) const { - const float fMaxDist = float(std::sqrt(FLOAT_MAX)); // max. length of a gap + const float fMaxDist = std::sqrt(std::numeric_limits::max()); // max. length of a gap const float fMinEps = 1.0e-4F; polyline.clear(); diff --git a/src/Mod/Mesh/App/Core/Segmentation.cpp b/src/Mod/Mesh/App/Core/Segmentation.cpp index f21245dbe8..5fd0dd410f 100644 --- a/src/Mod/Mesh/App/Core/Segmentation.cpp +++ b/src/Mod/Mesh/App/Core/Segmentation.cpp @@ -201,7 +201,7 @@ std::vector PlaneSurfaceFit::Parameters() const // -------------------------------------------------------- CylinderSurfaceFit::CylinderSurfaceFit() - : radius(FLOAT_MAX) + : radius(std::numeric_limits::max()) , fitter(new CylinderFit) { axis.Set(0, 0, 0); @@ -266,7 +266,7 @@ float CylinderSurfaceFit::Fit() } float fit = fitter->Fit(); - if (fit < FLOAT_MAX) { + if (fit < std::numeric_limits::max()) { basepoint = fitter->GetBase(); axis = fitter->GetAxis(); radius = fitter->GetRadius(); @@ -309,7 +309,7 @@ std::vector CylinderSurfaceFit::Parameters() const // -------------------------------------------------------- SphereSurfaceFit::SphereSurfaceFit() - : radius(FLOAT_MAX) + : radius(std::numeric_limits::max()) , fitter(new SphereFit) { center.Set(0, 0, 0); @@ -367,7 +367,7 @@ float SphereSurfaceFit::Fit() } float fit = fitter->Fit(); - if (fit < FLOAT_MAX) { + if (fit < std::numeric_limits::max()) { center = fitter->GetCenter(); radius = fitter->GetRadius(); } diff --git a/src/Mod/Mesh/App/Core/Simplify.h b/src/Mod/Mesh/App/Core/Simplify.h index e2c0cd6672..d45a3ae7c2 100644 --- a/src/Mod/Mesh/App/Core/Simplify.h +++ b/src/Mod/Mesh/App/Core/Simplify.h @@ -13,11 +13,6 @@ #include - -#ifndef _USE_MATH_DEFINES -#define _USE_MATH_DEFINES -#endif - using vec3f = Base::Vector3f; class SymmetricMatrix { diff --git a/src/Mod/Mesh/App/Core/Smoothing.h b/src/Mod/Mesh/App/Core/Smoothing.h index 6f15ffad2a..4579f01959 100644 --- a/src/Mod/Mesh/App/Core/Smoothing.h +++ b/src/Mod/Mesh/App/Core/Smoothing.h @@ -23,7 +23,6 @@ #ifndef MESH_SMOOTHING_H #define MESH_SMOOTHING_H -#include #include #include "Definitions.h" @@ -88,7 +87,7 @@ public: void SmoothPoints(unsigned int, const std::vector&) override; private: - float maximum {FLT_MAX}; + float maximum {std::numeric_limits::max()}; }; class MeshExport LaplaceSmoothing: public AbstractSmoothing diff --git a/src/Mod/Mesh/App/Core/SphereFit.cpp b/src/Mod/Mesh/App/Core/SphereFit.cpp index 7c7c1ebaad..c53812a1b1 100644 --- a/src/Mod/Mesh/App/Core/SphereFit.cpp +++ b/src/Mod/Mesh/App/Core/SphereFit.cpp @@ -41,7 +41,7 @@ SphereFit::SphereFit() void SphereFit::SetApproximations(double radius, const Base::Vector3d& center) { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; _dRadius = radius; _vCenter = center; @@ -92,7 +92,7 @@ int SphereFit::GetNumIterations() const float SphereFit::GetDistanceToSphere(const Base::Vector3f& rcPoint) const { - float fResult = FLOAT_MAX; + float fResult = std::numeric_limits::max(); if (_bIsFitted) { fResult = Base::Vector3d((double)rcPoint.x - _vCenter.x, (double)rcPoint.y - _vCenter.y, @@ -109,7 +109,7 @@ float SphereFit::GetStdDeviation() const // Variance: VAR=(N/N-1)*[(1/N)*SUM(Xi^2)-M^2] // Standard deviation: SD=SQRT(VAR) if (!_bIsFitted) { - return FLOAT_MAX; + return std::numeric_limits::max(); } double sumXi = 0.0, sumXi2 = 0.0, dist = 0.0; @@ -156,7 +156,7 @@ void SphereFit::ProjectToSphere() void SphereFit::ComputeApproximations() { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; _vCenter.Set(0.0, 0.0, 0.0); _dRadius = 0.0; @@ -182,12 +182,12 @@ void SphereFit::ComputeApproximations() float SphereFit::Fit() { _bIsFitted = false; - _fLastResult = FLOAT_MAX; + _fLastResult = std::numeric_limits::max(); _numIter = 0; // A minimum of 4 surface points is needed to define a sphere if (CountPoints() < 4) { - return FLOAT_MAX; + return std::numeric_limits::max(); } // If approximations have not been set/computed then compute some now @@ -212,7 +212,7 @@ float SphereFit::Fit() // Solve the equations for the unknown corrections Eigen::LLT llt(atpa); if (llt.info() != Eigen::Success) { - return FLOAT_MAX; + return std::numeric_limits::max(); } Eigen::VectorXd x = llt.solve(atpl); @@ -227,7 +227,7 @@ float SphereFit::Fit() // convergence bool vConverged {}; if (!computeResiduals(x, residuals, sigma0, _vConvLimit, vConverged)) { - return FLOAT_MAX; + return std::numeric_limits::max(); } if (!vConverged) { cont = true; @@ -242,7 +242,7 @@ float SphereFit::Fit() // Check for convergence if (cont) { - return FLOAT_MAX; + return std::numeric_limits::max(); } _bIsFitted = true; diff --git a/src/Mod/Mesh/App/Core/Tools.h b/src/Mod/Mesh/App/Core/Tools.h index ab1a49bb96..4c61987538 100644 --- a/src/Mod/Mesh/App/Core/Tools.h +++ b/src/Mod/Mesh/App/Core/Tools.h @@ -209,7 +209,7 @@ public: // NOLINTBEGIN Index nearest_index; - float nearest_dist {FLOAT_MAX}; + float nearest_dist {std::numeric_limits::max()}; // NOLINTEND private: diff --git a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp index dfd38113f2..48d92741de 100644 --- a/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp +++ b/src/Mod/Mesh/App/Core/TopoAlgorithm.cpp @@ -121,7 +121,7 @@ bool MeshTopoAlgorithm::SnapVertex(FacetIndex ulFacetPos, const Base::Vector3f& float fTV = (rP - rPt1) * (rPt2 - rPt1); // Point is on the edge - if (cNo3.Length() < FLOAT_EPS) { + if (cNo3.Length() < std::numeric_limits::epsilon()) { return SplitOpenEdge(ulFacetPos, i, rP); } if ((rP - rPt1) * cNo2 > 0.0F && fD2 >= fTV && fTV >= 0.0F) { @@ -290,7 +290,7 @@ float MeshTopoAlgorithm::SwapEdgeBenefit(FacetIndex f, int e) const PointIndex v2 = faces[f]._aulPoints[(e + 1) % 3]; PointIndex v3 = faces[f]._aulPoints[(e + 2) % 3]; unsigned short s = faces[n].Side(faces[f]); - if (s == USHRT_MAX) { + if (s == std::numeric_limits::max()) { std::cerr << "MeshTopoAlgorithm::SwapEdgeBenefit: error in neighbourhood " << "of faces " << f << " and " << n << std::endl; return 0.0F; // topological error @@ -600,7 +600,8 @@ bool MeshTopoAlgorithm::IsSwapEdgeLegal(FacetIndex ulFacetPos, FacetIndex ulNeig unsigned short uFSide = rclF.Side(rclN); unsigned short uNSide = rclN.Side(rclF); - if (uFSide == USHRT_MAX || uNSide == USHRT_MAX) { + constexpr auto max = std::numeric_limits::max(); + if (uFSide == max || uNSide == max) { return false; // not neighbours } @@ -686,7 +687,8 @@ void MeshTopoAlgorithm::SwapEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbour) unsigned short uFSide = rclF.Side(rclN); unsigned short uNSide = rclN.Side(rclF); - if (uFSide == USHRT_MAX || uNSide == USHRT_MAX) { + constexpr auto max = std::numeric_limits::max(); + if (uFSide == max || uNSide == max) { return; // not neighbours } @@ -720,7 +722,8 @@ bool MeshTopoAlgorithm::SplitEdge(FacetIndex ulFacetPos, unsigned short uFSide = rclF.Side(rclN); unsigned short uNSide = rclN.Side(rclF); - if (uFSide == USHRT_MAX || uNSide == USHRT_MAX) { + constexpr auto max = std::numeric_limits::max(); + if (uFSide == max || uNSide == max) { return false; // not neighbours } @@ -816,13 +819,13 @@ bool MeshTopoAlgorithm::SplitOpenEdge(FacetIndex ulFacetPos, bool MeshTopoAlgorithm::Vertex_Less::operator()(const Base::Vector3f& u, const Base::Vector3f& v) const { - if (std::fabs(u.x - v.x) > FLOAT_EPS) { + if (std::fabs(u.x - v.x) > std::numeric_limits::epsilon()) { return u.x < v.x; } - if (std::fabs(u.y - v.y) > FLOAT_EPS) { + if (std::fabs(u.y - v.y) > std::numeric_limits::epsilon()) { return u.y < v.y; } - if (std::fabs(u.z - v.z) > FLOAT_EPS) { + if (std::fabs(u.z - v.z) > std::numeric_limits::epsilon()) { return u.z < v.z; } return false; @@ -980,7 +983,8 @@ bool MeshTopoAlgorithm::CollapseEdge(FacetIndex ulFacetPos, FacetIndex ulNeighbo unsigned short uFSide = rclF.Side(rclN); unsigned short uNSide = rclN.Side(rclF); - if (uFSide == USHRT_MAX || uNSide == USHRT_MAX) { + constexpr auto max = std::numeric_limits::max(); + if (uFSide == max || uNSide == max) { return false; // not neighbours } @@ -1214,7 +1218,7 @@ void MeshTopoAlgorithm::SplitFacet(FacetIndex ulFacetPos, MeshPoint& rVertex2 = _rclMesh._aclPointArray[rFace._aulPoints[2]]; auto pointIndex = [=](const Base::Vector3f& rP) { - unsigned short equalP = USHRT_MAX; + unsigned short equalP = std::numeric_limits::max(); if (Base::Distance(rVertex0, rP) < fEps) { equalP = 0; } @@ -1230,16 +1234,17 @@ void MeshTopoAlgorithm::SplitFacet(FacetIndex ulFacetPos, unsigned short equalP1 = pointIndex(rP1); unsigned short equalP2 = pointIndex(rP2); + constexpr auto max = std::numeric_limits::max(); // both points are coincident with the corner points - if (equalP1 != USHRT_MAX && equalP2 != USHRT_MAX) { + if (equalP1 != max && equalP2 != max) { return; // must not split the facet } - if (equalP1 != USHRT_MAX) { + if (equalP1 != max) { // get the edge to the second given point and perform a split edge operation SplitFacetOnOneEdge(ulFacetPos, rP2); } - else if (equalP2 != USHRT_MAX) { + else if (equalP2 != max) { // get the edge to the first given point and perform a split edge operation SplitFacetOnOneEdge(ulFacetPos, rP1); } @@ -1250,8 +1255,8 @@ void MeshTopoAlgorithm::SplitFacet(FacetIndex ulFacetPos, void MeshTopoAlgorithm::SplitFacetOnOneEdge(FacetIndex ulFacetPos, const Base::Vector3f& rP) { - float fMinDist = FLOAT_MAX; - unsigned short iEdgeNo = USHRT_MAX; + float fMinDist = std::numeric_limits::max(); + unsigned short iEdgeNo = std::numeric_limits::max(); MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos]; for (unsigned short i = 0; i < 3; i++) { @@ -1281,8 +1286,10 @@ void MeshTopoAlgorithm::SplitFacetOnTwoEdges(FacetIndex ulFacetPos, const Base::Vector3f& rP2) { // search for the matching edges - unsigned short iEdgeNo1 = USHRT_MAX, iEdgeNo2 = USHRT_MAX; - float fMinDist1 = FLOAT_MAX, fMinDist2 = FLOAT_MAX; + unsigned short iEdgeNo1 = std::numeric_limits::max(); + unsigned short iEdgeNo2 = std::numeric_limits::max(); + float fMinDist1 = std::numeric_limits::max(); + float fMinDist2 = std::numeric_limits::max(); MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos]; for (unsigned short i = 0; i < 3; i++) { @@ -1392,7 +1399,7 @@ void MeshTopoAlgorithm::SplitFacet(FacetIndex ulFacetPos, { MeshFacet& rFace = _rclMesh._aclFacetArray[ulFacetPos]; unsigned short side = rFace.Side(P1, P2); - if (side != USHRT_MAX) { + if (side != std::numeric_limits::max()) { PointIndex V1 = rFace._aulPoints[(side + 1) % 3]; PointIndex V2 = rFace._aulPoints[(side + 2) % 3]; FacetIndex size = _rclMesh._aclFacetArray.size(); @@ -1455,12 +1462,12 @@ void MeshTopoAlgorithm::HarmonizeNeighbours(FacetIndex facet1, FacetIndex facet2 MeshFacet& rFace2 = _rclMesh._aclFacetArray[facet2]; unsigned short side = rFace1.Side(rFace2); - if (side != USHRT_MAX) { + if (side != std::numeric_limits::max()) { rFace1._aulNeighbours[side] = facet2; } side = rFace2.Side(rFace1); - if (side != USHRT_MAX) { + if (side != std::numeric_limits::max()) { rFace2._aulNeighbours[side] = facet1; } } diff --git a/src/Mod/Mesh/App/Core/Triangulation.cpp b/src/Mod/Mesh/App/Core/Triangulation.cpp index f78a00ec42..7d6855b573 100644 --- a/src/Mod/Mesh/App/Core/Triangulation.cpp +++ b/src/Mod/Mesh/App/Core/Triangulation.cpp @@ -144,7 +144,7 @@ Base::Matrix4D AbstractPolygonTriangulator::GetTransformToFitPlane() const planeFit.AddPoint(point); } - if (planeFit.Fit() >= FLOAT_MAX) { + if (planeFit.Fit() >= std::numeric_limits::max()) { throw Base::RuntimeError("Plane fit failed"); } @@ -215,7 +215,7 @@ void AbstractPolygonTriangulator::PostProcessing(const std::vector= uMinPts && polyFit.Fit() < FLOAT_MAX) { + if (polyFit.CountPoints() >= uMinPts && polyFit.Fit() < std::numeric_limits::max()) { for (auto& newpoint : _newpoints) { newpoint.z = static_cast(polyFit.Value(newpoint.x, newpoint.y)); } @@ -377,7 +377,9 @@ bool EarClippingTriangulator::Triangulate::InsideTriangle(float Ax, cCROSSap = cx * apy - cy * apx; bCROSScp = bx * cpy - by * cpx; - return ((aCROSSbp >= FLOAT_EPS) && (bCROSScp >= FLOAT_EPS) && (cCROSSap >= FLOAT_EPS)); + return ((aCROSSbp >= std::numeric_limits::epsilon()) + && (bCROSScp >= std::numeric_limits::epsilon()) + && (cCROSSap >= std::numeric_limits::epsilon())); } bool EarClippingTriangulator::Triangulate::Snip(const std::vector& contour, @@ -399,7 +401,8 @@ bool EarClippingTriangulator::Triangulate::Snip(const std::vector (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) { + constexpr float eps = std::numeric_limits::epsilon(); + if (eps > (((Bx - Ax) * (Cy - Ay)) - ((By - Ay) * (Cx - Ax)))) { return false; } diff --git a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp index f402424c98..7cdb9060fe 100644 --- a/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp +++ b/src/Mod/Mesh/App/FeatureMeshSegmentByMesh.cpp @@ -119,7 +119,7 @@ App::DocumentObjectExecReturn* SegmentByMesh::execute() // now we have too many facets since we have (invisible) facets near to the back clipping // plane, so we need the nearest facet to the front clipping plane // - float fDist = FLOAT_MAX; + float fDist = std::numeric_limits::max(); MeshCore::FacetIndex uIdx = MeshCore::FACET_INDEX_MAX; MeshFacetIterator cFIt(rMeshKernel); diff --git a/src/Mod/Mesh/App/FeatureMeshSolid.cpp b/src/Mod/Mesh/App/FeatureMeshSolid.cpp index 490428e5d2..e2d1a53e76 100644 --- a/src/Mod/Mesh/App/FeatureMeshSolid.cpp +++ b/src/Mod/Mesh/App/FeatureMeshSolid.cpp @@ -29,8 +29,10 @@ namespace Mesh { -const App::PropertyIntegerConstraint::Constraints intSampling = {0, INT_MAX, 1}; -const App::PropertyLength::Constraints floatRange = {0.0, FLT_MAX, 1.0}; +const App::PropertyIntegerConstraint::Constraints intSampling = {0, + std::numeric_limits::max(), + 1}; +const App::PropertyLength::Constraints floatRange = {0.0, std::numeric_limits::max(), 1.0}; } // namespace Mesh using namespace Mesh; diff --git a/src/Mod/Mesh/App/MeshFeaturePyImp.cpp b/src/Mod/Mesh/App/MeshFeaturePyImp.cpp index aaaf58aff0..f3770dac7b 100644 --- a/src/Mod/Mesh/App/MeshFeaturePyImp.cpp +++ b/src/Mod/Mesh/App/MeshFeaturePyImp.cpp @@ -73,7 +73,7 @@ PyObject* MeshFeaturePy::harmonizeNormals(PyObject* args) PyObject* MeshFeaturePy::smooth(PyObject* args) { int iter = 1; - float d_max = FLOAT_MAX; + float d_max = std::numeric_limits::max(); if (!PyArg_ParseTuple(args, "|if", &iter, &d_max)) { return nullptr; } diff --git a/src/Mod/Mesh/App/MeshPoint.h b/src/Mod/Mesh/App/MeshPoint.h index 1b5043b7f2..a29270108e 100644 --- a/src/Mod/Mesh/App/MeshPoint.h +++ b/src/Mod/Mesh/App/MeshPoint.h @@ -23,7 +23,6 @@ #ifndef MESH_MESHPOINT_H #define MESH_MESHPOINT_H -#include #include #include @@ -51,7 +50,7 @@ public: /// simple constructor explicit MeshPoint(const Vector3d& vec = Vector3d(), const MeshObject* obj = nullptr, - unsigned int index = UINT_MAX) + unsigned int index = std::numeric_limits::max()) : Vector3d(vec) , Index(index) , Mesh(obj) @@ -59,7 +58,7 @@ public: bool isBound() const { - return Index != UINT_MAX; + return Index != std::numeric_limits::max(); } unsigned int Index; diff --git a/src/Mod/Mesh/App/MeshPointPyImp.cpp b/src/Mod/Mesh/App/MeshPointPyImp.cpp index 00f0509655..a4b62e1569 100644 --- a/src/Mod/Mesh/App/MeshPointPyImp.cpp +++ b/src/Mod/Mesh/App/MeshPointPyImp.cpp @@ -86,7 +86,7 @@ PyObject* MeshPointPy::unbound(PyObject* args) if (!PyArg_ParseTuple(args, "")) { return nullptr; } - getMeshPointPtr()->Index = UINT_MAX; + getMeshPointPtr()->Index = std::numeric_limits::max(); getMeshPointPtr()->Mesh = nullptr; Py_Return; } @@ -98,7 +98,7 @@ Py::Long MeshPointPy::getIndex() const Py::Boolean MeshPointPy::getBound() const { - return {getMeshPointPtr()->Index != UINT_MAX}; + return {getMeshPointPtr()->Index != std::numeric_limits::max()}; } Py::Object MeshPointPy::getNormal() const diff --git a/src/Mod/Mesh/App/PreCompiled.h b/src/Mod/Mesh/App/PreCompiled.h index 4d4317c9d0..7484b92f22 100644 --- a/src/Mod/Mesh/App/PreCompiled.h +++ b/src/Mod/Mesh/App/PreCompiled.h @@ -39,7 +39,6 @@ // standard #include -#include #include #include #include diff --git a/src/Mod/Mesh/App/WildMagic4/Wm4Math.cpp b/src/Mod/Mesh/App/WildMagic4/Wm4Math.cpp index efa1a2f762..f497f0851e 100644 --- a/src/Mod/Mesh/App/WildMagic4/Wm4Math.cpp +++ b/src/Mod/Mesh/App/WildMagic4/Wm4Math.cpp @@ -19,9 +19,9 @@ namespace Wm4 { -template<> WM4_FOUNDATION_ITEM const float Math::EPSILON = FLT_EPSILON; +template<> WM4_FOUNDATION_ITEM const float Math::EPSILON = std::numeric_limits::epsilon(); template<> WM4_FOUNDATION_ITEM const float Math::ZERO_TOLERANCE = 1e-06f; -template<> WM4_FOUNDATION_ITEM const float Math::MAX_REAL = FLT_MAX; +template<> WM4_FOUNDATION_ITEM const float Math::MAX_REAL = std::numeric_limits::max(); template<> WM4_FOUNDATION_ITEM const float Math::PI = (float)(4.0*atan(1.0)); template<> WM4_FOUNDATION_ITEM const float Math::TWO_PI = 2.0f*Math::PI; template<> WM4_FOUNDATION_ITEM const float Math::HALF_PI = 0.5f*Math::PI; @@ -34,9 +34,9 @@ template<> WM4_FOUNDATION_ITEM const float Math::LN_10 = Math::Log template<> WM4_FOUNDATION_ITEM const float Math::INV_LN_2 = 1.0f/Math::LN_2; template<> WM4_FOUNDATION_ITEM const float Math::INV_LN_10 = 1.0f/Math::LN_10; -template<> WM4_FOUNDATION_ITEM const double Math::EPSILON = DBL_EPSILON; +template<> WM4_FOUNDATION_ITEM const double Math::EPSILON = std::numeric_limits::epsilon(); template<> WM4_FOUNDATION_ITEM const double Math::ZERO_TOLERANCE = 1e-08; -template<> WM4_FOUNDATION_ITEM const double Math::MAX_REAL = DBL_MAX; +template<> WM4_FOUNDATION_ITEM const double Math::MAX_REAL = std::numeric_limits::max(); template<> WM4_FOUNDATION_ITEM const double Math::PI = 4.0*atan(1.0); template<> WM4_FOUNDATION_ITEM const double Math::TWO_PI = 2.0*Math::PI; template<> WM4_FOUNDATION_ITEM const double Math::HALF_PI = 0.5*Math::PI; diff --git a/src/Mod/Mesh/App/WildMagic4/Wm4System.h b/src/Mod/Mesh/App/WildMagic4/Wm4System.h index 13d1c815a0..3bd3051a1d 100644 --- a/src/Mod/Mesh/App/WildMagic4/Wm4System.h +++ b/src/Mod/Mesh/App/WildMagic4/Wm4System.h @@ -23,7 +23,6 @@ // common standard library headers #include #include -#include #include #include #include diff --git a/src/Mod/Mesh/Gui/Command.cpp b/src/Mod/Mesh/Gui/Command.cpp index 6411e6ac8d..6bfe41ea90 100644 --- a/src/Mod/Mesh/Gui/Command.cpp +++ b/src/Mod/Mesh/Gui/Command.cpp @@ -1798,7 +1798,7 @@ void CmdMeshScale::activated(int) QObject::tr("Enter scaling factor:"), 1, 0, - DBL_MAX, + std::numeric_limits::max(), 5, &ok, Qt::MSWindowsFixedSizeDialogHint); diff --git a/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp b/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp index 10e996b5fa..1c541831fa 100644 --- a/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp +++ b/src/Mod/Mesh/Gui/DlgRegularSolidImp.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #endif @@ -55,45 +54,46 @@ DlgRegularSolidImp::DlgRegularSolidImp(QWidget* parent, Qt::WindowFlags fl) Gui::Command::doCommand(Gui::Command::Doc, "import Mesh,BuildRegularGeoms"); // set limits + constexpr double doubleMax = std::numeric_limits::max(); // Box - ui->boxLength->setMaximum(DBL_MAX); + ui->boxLength->setMaximum(doubleMax); ui->boxLength->setMinimum(0); - ui->boxWidth->setMaximum(DBL_MAX); + ui->boxWidth->setMaximum(doubleMax); ui->boxWidth->setMinimum(0); - ui->boxHeight->setMaximum(DBL_MAX); + ui->boxHeight->setMaximum(doubleMax); ui->boxHeight->setMinimum(0); // Cylinder - ui->cylinderRadius->setMaximum(DBL_MAX); + ui->cylinderRadius->setMaximum(doubleMax); ui->cylinderRadius->setMinimum(0); - ui->cylinderLength->setMaximum(DBL_MAX); + ui->cylinderLength->setMaximum(doubleMax); ui->cylinderLength->setMinimum(0); - ui->cylinderEdgeLength->setMaximum(DBL_MAX); + ui->cylinderEdgeLength->setMaximum(doubleMax); ui->cylinderEdgeLength->setMinimum(0); ui->cylinderCount->setMaximum(1000); // Cone - ui->coneRadius1->setMaximum(DBL_MAX); + ui->coneRadius1->setMaximum(doubleMax); ui->coneRadius1->setMinimum(0); - ui->coneRadius2->setMaximum(DBL_MAX); + ui->coneRadius2->setMaximum(doubleMax); ui->coneRadius2->setMinimum(0); - ui->coneLength->setMaximum(DBL_MAX); + ui->coneLength->setMaximum(doubleMax); ui->coneLength->setMinimum(0); - ui->coneEdgeLength->setMaximum(DBL_MAX); + ui->coneEdgeLength->setMaximum(doubleMax); ui->coneEdgeLength->setMinimum(0); ui->coneCount->setMaximum(1000); // Sphere - ui->sphereRadius->setMaximum(DBL_MAX); + ui->sphereRadius->setMaximum(doubleMax); ui->sphereRadius->setMinimum(0); ui->sphereCount->setMaximum(1000); // Ellipsoid - ui->ellipsoidRadius1->setMaximum(DBL_MAX); + ui->ellipsoidRadius1->setMaximum(doubleMax); ui->ellipsoidRadius1->setMinimum(0); - ui->ellipsoidRadius2->setMaximum(DBL_MAX); + ui->ellipsoidRadius2->setMaximum(doubleMax); ui->ellipsoidRadius2->setMinimum(0); ui->ellipsoidCount->setMaximum(1000); // Torus - ui->toroidRadius1->setMaximum(DBL_MAX); + ui->toroidRadius1->setMaximum(doubleMax); ui->toroidRadius1->setMinimum(0); - ui->toroidRadius2->setMaximum(DBL_MAX); + ui->toroidRadius2->setMaximum(doubleMax); ui->toroidRadius2->setMinimum(0); ui->toroidCount->setMaximum(1000); } diff --git a/src/Mod/Mesh/Gui/MeshEditor.cpp b/src/Mod/Mesh/Gui/MeshEditor.cpp index 9c15efd34f..9ffa3ce5a3 100644 --- a/src/Mod/Mesh/Gui/MeshEditor.cpp +++ b/src/Mod/Mesh/Gui/MeshEditor.cpp @@ -318,7 +318,7 @@ void MeshFaceAddition::showMarker(SoPickedPoint* pp) } int point_index = -1; - float distance = FLT_MAX; + float distance = std::numeric_limits::max(); Base::Vector3f pnt; SbVec3f face_pnt; @@ -654,7 +654,7 @@ float MeshFillHole::findClosestPoint(const SbLine& ray, SbVec3f& closestPoint) const { // now check which vertex of the polygon is closest to the ray - float minDist = FLT_MAX; + float minDist = std::numeric_limits::max(); vertex_index = MeshCore::POINT_INDEX_MAX; const MeshCore::MeshKernel& rMesh = myMesh->Mesh.getValue().getKernel(); diff --git a/src/Mod/Mesh/Gui/MeshSelection.cpp b/src/Mod/Mesh/Gui/MeshSelection.cpp index 56876c9b52..728a3a978c 100644 --- a/src/Mod/Mesh/Gui/MeshSelection.cpp +++ b/src/Mod/Mesh/Gui/MeshSelection.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include -#include #include #include diff --git a/src/Mod/Mesh/Gui/PreCompiled.h b/src/Mod/Mesh/Gui/PreCompiled.h index 5db5693792..8fe2574154 100644 --- a/src/Mod/Mesh/Gui/PreCompiled.h +++ b/src/Mod/Mesh/Gui/PreCompiled.h @@ -39,7 +39,6 @@ // standard #include -#include // STL #include diff --git a/src/Mod/Mesh/Gui/RemoveComponents.cpp b/src/Mod/Mesh/Gui/RemoveComponents.cpp index 0f8c9644d5..5e54c225b7 100644 --- a/src/Mod/Mesh/Gui/RemoveComponents.cpp +++ b/src/Mod/Mesh/Gui/RemoveComponents.cpp @@ -41,9 +41,9 @@ RemoveComponents::RemoveComponents(QWidget* parent, Qt::WindowFlags fl) { ui->setupUi(this); setupConnections(); - ui->spSelectComp->setRange(1, INT_MAX); + ui->spSelectComp->setRange(1, std::numeric_limits::max()); ui->spSelectComp->setValue(10); - ui->spDeselectComp->setRange(1, INT_MAX); + ui->spDeselectComp->setRange(1, std::numeric_limits::max()); ui->spDeselectComp->setValue(10); Gui::Selection().clearSelection(); diff --git a/src/Mod/Mesh/Gui/Segmentation.cpp b/src/Mod/Mesh/Gui/Segmentation.cpp index 235ecd43d4..050e9f5327 100644 --- a/src/Mod/Mesh/Gui/Segmentation.cpp +++ b/src/Mod/Mesh/Gui/Segmentation.cpp @@ -44,18 +44,19 @@ Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags , ui(new Ui_Segmentation) , myMesh(mesh) { + constexpr int max = std::numeric_limits::max(); ui->setupUi(this); - ui->numPln->setRange(1, INT_MAX); + ui->numPln->setRange(1, max); ui->numPln->setValue(100); - ui->crvCyl->setRange(0, INT_MAX); - ui->numCyl->setRange(1, INT_MAX); + ui->crvCyl->setRange(0, max); + ui->numCyl->setRange(1, max); ui->numCyl->setValue(100); - ui->crvSph->setRange(0, INT_MAX); - ui->numSph->setRange(1, INT_MAX); + ui->crvSph->setRange(0, max); + ui->numSph->setRange(1, max); ui->numSph->setValue(100); - ui->crv1Free->setRange(-INT_MAX, INT_MAX); - ui->crv2Free->setRange(-INT_MAX, INT_MAX); - ui->numFree->setRange(1, INT_MAX); + ui->crv1Free->setRange(-max, max); + ui->crv2Free->setRange(-max, max); + ui->numFree->setRange(1, max); ui->numFree->setValue(100); ui->checkBoxSmooth->setChecked(false); diff --git a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp index 464ffda0aa..2a147ac04b 100644 --- a/src/Mod/Mesh/Gui/SegmentationBestFit.cpp +++ b/src/Mod/Mesh/Gui/SegmentationBestFit.cpp @@ -57,7 +57,7 @@ public: std::vector values; MeshCore::PlaneFit fit; fit.AddPoints(pts.points); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetBase(); Base::Vector3f axis = fit.GetNormal(); values.push_back(base.x); @@ -90,7 +90,7 @@ public: #endif } - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base, top; fit.GetBounding(base, top); Base::Vector3f axis = fit.GetAxis(); @@ -145,7 +145,7 @@ public: std::vector values; MeshCore::SphereFit fit; fit.AddPoints(pts.points); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetCenter(); float radius = fit.GetRadius(); values.push_back(base.x); @@ -228,7 +228,7 @@ ParametersDialog::ParametersDialog(std::vector& val, QDoubleSpinBox* doubleSpinBox = new QDoubleSpinBox(groupBox); doubleSpinBox->setObjectName(it.first); - doubleSpinBox->setRange(-INT_MAX, INT_MAX); + doubleSpinBox->setRange(-std::numeric_limits::max(), std::numeric_limits::max()); doubleSpinBox->setValue(it.second); layout->addWidget(doubleSpinBox, index, 1, 1, 1); spinBoxes.push_back(doubleSpinBox); @@ -335,11 +335,11 @@ SegmentationBestFit::SegmentationBestFit(Mesh::Feature* mesh, QWidget* parent, Q ui->setupUi(this); setupConnections(); - ui->numPln->setRange(1, INT_MAX); + ui->numPln->setRange(1, std::numeric_limits::max()); ui->numPln->setValue(100); - ui->numCyl->setRange(1, INT_MAX); + ui->numCyl->setRange(1, std::numeric_limits::max()); ui->numCyl->setValue(100); - ui->numSph->setRange(1, INT_MAX); + ui->numSph->setRange(1, std::numeric_limits::max()); ui->numSph->setValue(100); Gui::SelectionObject obj(myMesh); diff --git a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp index 080e0584b2..be7c40a5ea 100644 --- a/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp +++ b/src/Mod/Mesh/Gui/SoFCIndexedFaceSet.cpp @@ -30,7 +30,6 @@ #ifndef _PreComp_ #include -#include #ifdef FC_OS_MACOSX #include #include @@ -459,7 +458,7 @@ void SoFCIndexedFaceSet::initClass() } SoFCIndexedFaceSet::SoFCIndexedFaceSet() - : renderTriangleLimit(UINT_MAX) + : renderTriangleLimit(std::numeric_limits::max()) { SO_NODE_CONSTRUCTOR(SoFCIndexedFaceSet); SO_NODE_ADD_FIELD(updateGLArray, (false)); diff --git a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp index 7ff55890e4..904f6fdf48 100644 --- a/src/Mod/Mesh/Gui/SoFCMeshObject.cpp +++ b/src/Mod/Mesh/Gui/SoFCMeshObject.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ #include -#include #ifdef FC_OS_WIN32 #include #endif @@ -607,7 +606,7 @@ void SoFCMeshObjectShape::initClass() } SoFCMeshObjectShape::SoFCMeshObjectShape() - : renderTriangleLimit(UINT_MAX) + : renderTriangleLimit(std::numeric_limits::max()) { SO_NODE_CONSTRUCTOR(SoFCMeshObjectShape); setName(SoFCMeshObjectShape::getClassTypeId().getName()); @@ -1235,7 +1234,7 @@ void SoFCMeshSegmentShape::initClass() } SoFCMeshSegmentShape::SoFCMeshSegmentShape() - : renderTriangleLimit(UINT_MAX) + : renderTriangleLimit(std::numeric_limits::max()) { SO_NODE_CONSTRUCTOR(SoFCMeshSegmentShape); SO_NODE_ADD_FIELD(index, (0)); diff --git a/src/Mod/Mesh/Gui/SoPolygon.cpp b/src/Mod/Mesh/Gui/SoPolygon.cpp index acc5701058..a5b242c82b 100644 --- a/src/Mod/Mesh/Gui/SoPolygon.cpp +++ b/src/Mod/Mesh/Gui/SoPolygon.cpp @@ -31,7 +31,6 @@ #include #endif #include -#include #include #include @@ -145,8 +144,9 @@ void SoPolygon::computeBBox(SoAction* action, SbBox3f& box, SbVec3f& center) if (!points) { return; } - float maxX = -FLT_MAX, minX = FLT_MAX, maxY = -FLT_MAX, minY = FLT_MAX, maxZ = -FLT_MAX, - minZ = FLT_MAX; + constexpr float floatMax = std::numeric_limits::max(); + float maxX = -floatMax, minX = floatMax, maxY = -floatMax, minY = floatMax, maxZ = -floatMax, + minZ = floatMax; int32_t len = coords->getNum(); int32_t beg = startIndex.getValue(); int32_t cnt = numVertices.getValue(); diff --git a/src/Mod/MeshPart/App/CurveProjector.cpp b/src/Mod/MeshPart/App/CurveProjector.cpp index ceab83bff4..db9926b50d 100644 --- a/src/Mod/MeshPart/App/CurveProjector.cpp +++ b/src/Mod/MeshPart/App/CurveProjector.cpp @@ -180,7 +180,7 @@ void CurveProjectorShape::projectCurve(const TopoDS_Edge& aEdge, / ((cP1 - cP0) * (cP1 - cP0)); // is the Point on the Edge of the facet? if (l < 0.0 || l > 1.0) { - PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0); + PointOnEdge[i] = Base::Vector3f(std::numeric_limits::max(), 0, 0); } else { cSplitPoint = (1 - l) * cP0 + l * cP1; @@ -191,11 +191,11 @@ void CurveProjectorShape::projectCurve(const TopoDS_Edge& aEdge, // no intersection } else if (Alg.NbPoints() == 0) { - PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0); + PointOnEdge[i] = Base::Vector3f(std::numeric_limits::max(), 0, 0); // more the one intersection (@ToDo) } else if (Alg.NbPoints() > 1) { - PointOnEdge[i] = Base::Vector3f(FLOAT_MAX, 0, 0); + PointOnEdge[i] = Base::Vector3f(std::numeric_limits::max(), 0, 0); Base::Console().Log("MeshAlgos::projectCurve(): More then one intersection in " "Facet %lu, Edge %d\n", uCurFacetIdx, @@ -234,7 +234,7 @@ bool CurveProjectorShape::findStartPoint(const MeshKernel& MeshK, MeshCore::FacetIndex& FaceIndex) { Base::Vector3f TempResultPoint; - float MinLength = FLOAT_MAX; + float MinLength = std::numeric_limits::max(); bool bHit = false; // go through the whole Mesh @@ -363,7 +363,7 @@ bool CurveProjectorSimple::findStartPoint(const MeshKernel& MeshK, MeshCore::FacetIndex& FaceIndex) { Base::Vector3f TempResultPoint; - float MinLength = FLOAT_MAX; + float MinLength = std::numeric_limits::max(); bool bHit = false; // go through the whole Mesh @@ -465,11 +465,11 @@ void CurveProjectorWithToolMesh::makeToolMesh(const TopoDS_Edge& aEdge, // build up the new mesh - Base::Vector3f lp(FLOAT_MAX, 0, 0), ln, p1, p2, p3, p4, p5, p6; + Base::Vector3f lp(std::numeric_limits::max(), 0, 0), ln, p1, p2, p3, p4, p5, p6; float ToolSize = 0.2f; for (const auto& It2 : LineSegs) { - if (lp.x != FLOAT_MAX) { + if (lp.x != std::numeric_limits::max()) { p1 = lp + (ln * (-ToolSize)); p2 = lp + (ln * ToolSize); p3 = lp; diff --git a/src/Mod/MeshPart/App/CurveProjector.h b/src/Mod/MeshPart/App/CurveProjector.h index f2c84e4c2b..d8fd6386d1 100644 --- a/src/Mod/MeshPart/App/CurveProjector.h +++ b/src/Mod/MeshPart/App/CurveProjector.h @@ -66,7 +66,8 @@ public: std::hash hasher; return hasher(x) < hasher(y); #else - return x.HashCode(INT_MAX - 1) < y.HashCode(INT_MAX - 1); + constexpr int max = std::numeric_limits::max(); + return x.HashCode(max - 1) < y.HashCode(max - 1); #endif } }; diff --git a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp index 1071e0c9c8..4c73f3f651 100644 --- a/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp +++ b/src/Mod/MeshPart/App/MeshFlatteningLscmRelax.cpp @@ -26,14 +26,11 @@ #include #include #include +#include #include #include #endif -#ifndef M_PI -#define M_PI 3.14159265358979323846f -#endif - #include #include "MeshFlatteningLscmRelax.h" @@ -649,7 +646,7 @@ void LscmRelax::rotate_by_min_bound_area() // rotate vector by 90 degree and find min area for (int i = 0; i < n + 1; i++ ) { - phi = i * M_PI / n; + phi = i * std::numbers::pi / n; Eigen::VectorXd x_proj = this->flat_vertices.transpose() * Vector2(std::cos(phi), std::sin(phi)); Eigen::VectorXd y_proj = this->flat_vertices.transpose() * Vector2(-std::sin(phi), std::cos(phi)); double x_distance = x_proj.maxCoeff() - x_proj.minCoeff(); @@ -663,7 +660,7 @@ void LscmRelax::rotate_by_min_bound_area() } } Eigen::Matrix rot; - min_phi += x_dominant * M_PI / 2; + min_phi += x_dominant * std::numbers::pi / 2; rot << std::cos(min_phi), std::sin(min_phi), -std::sin(min_phi), std::cos(min_phi); this->flat_vertices = rot * this->flat_vertices; } diff --git a/src/Mod/MeshPart/App/PreCompiled.h b/src/Mod/MeshPart/App/PreCompiled.h index 7c1101f012..6b867c5e80 100644 --- a/src/Mod/MeshPart/App/PreCompiled.h +++ b/src/Mod/MeshPart/App/PreCompiled.h @@ -43,6 +43,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Mod/MeshPart/Gui/CrossSections.cpp b/src/Mod/MeshPart/Gui/CrossSections.cpp index 01ba18888e..2ba73eeeac 100644 --- a/src/Mod/MeshPart/Gui/CrossSections.cpp +++ b/src/Mod/MeshPart/Gui/CrossSections.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include @@ -179,9 +178,10 @@ CrossSections::CrossSections(const Base::BoundBox3d& bb, QWidget* parent, Qt::Wi ui->setupUi(this); setupConnections(); - ui->position->setRange(-DBL_MAX, DBL_MAX); + constexpr double max = std::numeric_limits::max(); + ui->position->setRange(-max, max); ui->position->setUnit(Base::Unit::Length); - ui->distance->setRange(0, DBL_MAX); + ui->distance->setRange(0, max); ui->distance->setUnit(Base::Unit::Length); ui->spinEpsilon->setMinimum(0.0001); vp = new ViewProviderCrossSections(); diff --git a/src/Mod/MeshPart/Gui/PreCompiled.h b/src/Mod/MeshPart/Gui/PreCompiled.h index 7b8b8dda80..408fcd88ed 100644 --- a/src/Mod/MeshPart/Gui/PreCompiled.h +++ b/src/Mod/MeshPart/Gui/PreCompiled.h @@ -34,7 +34,6 @@ #ifdef _PreComp_ // STL -#include #include // Qt Toolkit diff --git a/src/Mod/MeshPart/Gui/Tessellation.cpp b/src/Mod/MeshPart/Gui/Tessellation.cpp index f063bd91be..c726659bbe 100644 --- a/src/Mod/MeshPart/Gui/Tessellation.cpp +++ b/src/Mod/MeshPart/Gui/Tessellation.cpp @@ -71,11 +71,11 @@ Tessellation::Tessellation(QWidget* parent) relative = handle->GetBool("RelativeLinearDeflection", relative); ui->relativeDeviation->setChecked(relative); - ui->spinSurfaceDeviation->setMaximum(INT_MAX); + ui->spinSurfaceDeviation->setMaximum(std::numeric_limits::max()); ui->spinSurfaceDeviation->setValue(value); ui->spinAngularDeviation->setValue(angle); - ui->spinMaximumEdgeLength->setRange(0, INT_MAX); + ui->spinMaximumEdgeLength->setRange(0, std::numeric_limits::max()); ui->comboFineness->setCurrentIndex(2); onComboFinenessCurrentIndexChanged(2); diff --git a/src/Mod/Part/App/AppPartPy.cpp b/src/Mod/Part/App/AppPartPy.cpp index 0a9042c300..b6734ca17b 100644 --- a/src/Mod/Part/App/AppPartPy.cpp +++ b/src/Mod/Part/App/AppPartPy.cpp @@ -1622,7 +1622,8 @@ private: } Py::Object makeRevolution(const Py::Tuple& args) { - double vmin = DBL_MAX, vmax=-DBL_MAX; + constexpr double doubleMax = std::numeric_limits::max(); + double vmin = doubleMax, vmax=-doubleMax; double angle=360; PyObject *pPnt=nullptr, *pDir=nullptr, *pCrv; Handle(Geom_Curve) curve; @@ -1641,10 +1642,10 @@ private: if (curve.IsNull()) { throw Py::Exception(PyExc_TypeError, "geometry is not a curve"); } - if (vmin == DBL_MAX) + if (vmin == doubleMax) vmin = curve->FirstParameter(); - if (vmax == -DBL_MAX) + if (vmax == -doubleMax) vmax = curve->LastParameter(); break; } @@ -1675,9 +1676,9 @@ private: throw Py::Exception(PartExceptionOCCError, "invalid curve in edge"); } - if (vmin == DBL_MAX) + if (vmin == doubleMax) vmin = adapt.FirstParameter(); - if (vmax == -DBL_MAX) + if (vmax == -doubleMax) vmax = adapt.LastParameter(); break; } diff --git a/src/Mod/Part/App/Attacher.cpp b/src/Mod/Part/App/Attacher.cpp index 5009ce260b..255d54b702 100644 --- a/src/Mod/Part/App/Attacher.cpp +++ b/src/Mod/Part/App/Attacher.cpp @@ -1912,7 +1912,7 @@ AttachEngine3D::_calculateAttachedPlacement(const std::vectormapReverse) { - rot = rot * Base::Rotation(Base::Vector3d(0, 1, 0), D_PI); + rot = rot * Base::Rotation(Base::Vector3d(0, 1, 0), std::numbers::pi); } Base::Placement plm = Base::Placement( diff --git a/src/Mod/Part/App/FeatureExtrusion.cpp b/src/Mod/Part/App/FeatureExtrusion.cpp index 800199733c..abffc334bd 100644 --- a/src/Mod/Part/App/FeatureExtrusion.cpp +++ b/src/Mod/Part/App/FeatureExtrusion.cpp @@ -200,6 +200,8 @@ bool Extrusion::fetchAxisLink(const App::PropertyLinkSub& axisLink, Base::Vector ExtrusionParameters Extrusion::computeFinalParameters() { + using std::numbers::pi; + ExtrusionParameters result; Base::Vector3d dir; switch (this->DirMode.getValue()) { @@ -244,11 +246,11 @@ ExtrusionParameters Extrusion::computeFinalParameters() result.solid = this->Solid.getValue(); - result.taperAngleFwd = this->TaperAngle.getValue() * M_PI / 180.0; - if (fabs(result.taperAngleFwd) > M_PI * 0.5 - Precision::Angular()) + result.taperAngleFwd = this->TaperAngle.getValue() * pi / 180.0; + if (fabs(result.taperAngleFwd) > pi * 0.5 - Precision::Angular()) throw Base::ValueError("Magnitude of taper angle matches or exceeds 90 degrees. That is too much."); - result.taperAngleRev = this->TaperAngleRev.getValue() * M_PI / 180.0; - if (fabs(result.taperAngleRev) > M_PI * 0.5 - Precision::Angular()) + result.taperAngleRev = this->TaperAngleRev.getValue() * pi / 180.0; + if (fabs(result.taperAngleRev) > pi * 0.5 - Precision::Angular()) throw Base::ValueError("Magnitude of taper angle matches or exceeds 90 degrees. That is too much."); result.faceMakerClass = this->FaceMakerClass.getValue(); diff --git a/src/Mod/Part/App/FeatureRevolution.cpp b/src/Mod/Part/App/FeatureRevolution.cpp index e27007f98a..2a59f99bce 100644 --- a/src/Mod/Part/App/FeatureRevolution.cpp +++ b/src/Mod/Part/App/FeatureRevolution.cpp @@ -143,7 +143,7 @@ App::DocumentObjectExecReturn *Revolution::execute() gp_Ax1 revAx(pnt, dir); //read out revolution angle - double angle = Angle.getValue()/180.0f*M_PI; + double angle = Angle.getValue()/180.0f * std::numbers::pi; if (fabs(angle) < Precision::Angular()) angle = angle_edge; diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index bb3d7d2a8d..571b91cd18 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -2640,7 +2640,7 @@ GeomCurve* GeomCircle::createArc(double first, double last) const GeomBSplineCurve* GeomCircle::toNurbs(double first, double last) const { // for an arc of circle use the generic method - if (first != 0 || last != 2*M_PI) { + if (first != 0 || last != 2 * std::numbers::pi) { return GeomConic::toNurbs(first, last); } @@ -2674,8 +2674,8 @@ GeomBSplineCurve* GeomCircle::toNurbs(double first, double last) const TColStd_Array1OfReal knots(1, 3); knots(1) = 0; - knots(2) = M_PI; - knots(3) = 2*M_PI; + knots(2) = std::numbers::pi; + knots(3) = 2 * std::numbers::pi; Handle(Geom_BSplineCurve) spline = new Geom_BSplineCurve(poles, weights,knots, mults, 3, Standard_False, Standard_True); @@ -2906,9 +2906,9 @@ void GeomArcOfCircle::getRange(double& u, double& v, bool emulateCCWXY) const } if (v < u) - v += 2*M_PI; - if (v-u > 2*M_PI) - v -= 2*M_PI; + v += 2 * std::numbers::pi; + if (v-u > 2 * std::numbers::pi) + v -= 2 * std::numbers::pi; } } @@ -3086,7 +3086,7 @@ GeomCurve* GeomEllipse::createArc(double first, double last) const GeomBSplineCurve* GeomEllipse::toNurbs(double first, double last) const { // for an arc of ellipse use the generic method - if (first != 0 || last != 2*M_PI) { + if (first != 0 || last != 2 * std::numbers::pi) { return GeomConic::toNurbs(first, last); } @@ -3465,9 +3465,9 @@ void GeomArcOfEllipse::getRange(double& u, double& v, bool emulateCCWXY) const std::swap(u,v); u = -u; v = -v; if (v < u) - v += 2*M_PI; - if (v-u > 2*M_PI) - v -= 2*M_PI; + v += 2 * std::numbers::pi; + if (v-u > 2 * std::numbers::pi) + v -= 2 * std::numbers::pi; } } } @@ -4683,11 +4683,12 @@ void GeomLineSegment::Restore (Base::XMLReader &reader) // for other objects, the best effort may be just to leave default values. reader.setPartialRestore(true); + constexpr double increment{std::numeric_limits::epsilon()}; if(start.x == 0) { - end = start + Base::Vector3d(DBL_EPSILON,0,0); + end = start + Base::Vector3d(increment, 0, 0); } else { - end = start + Base::Vector3d(start.x*DBL_EPSILON,0,0); + end = start + Base::Vector3d(start.x * increment, 0, 0); } setPoints(start, end); @@ -5409,7 +5410,7 @@ gp_Vec GeomCone::getDN(double u, double v, int Nu, int Nv) const { gp_XYZ Xdir = Pos.XDirection().XYZ(); gp_XYZ Ydir = Pos.YDirection().XYZ(); - Standard_Real Um = U + Nu * M_PI_2; // M_PI * 0.5 + Standard_Real Um = U + Nu * std::numbers::pi/2; Xdir.Multiply(cos(Um)); Ydir.Multiply(sin(Um)); Xdir.Add(Ydir); @@ -6228,11 +6229,11 @@ GeomArcOfCircle *createFilletGeometry(const GeomLineSegment *lineSeg1, const Geo if (endAngle < startAngle) std::swap(startAngle, endAngle); - if (endAngle > 2*M_PI ) - endAngle -= 2*M_PI; + if (endAngle > 2 * std::numbers::pi) + endAngle -= 2 * std::numbers::pi; - if (startAngle < 0 ) - endAngle += 2*M_PI; + if (startAngle < 0) + endAngle += 2 * std::numbers::pi; // Create Arc Segment GeomArcOfCircle *arc = new GeomArcOfCircle(); diff --git a/src/Mod/Part/App/PreCompiled.h b/src/Mod/Part/App/PreCompiled.h index ca53f56d20..a537ca9c03 100644 --- a/src/Mod/Part/App/PreCompiled.h +++ b/src/Mod/Part/App/PreCompiled.h @@ -43,6 +43,7 @@ #include #include #include +#include // STL #include @@ -52,6 +53,7 @@ #include #include #include +#include #include #include #include diff --git a/src/Mod/Part/App/PrimitiveFeature.cpp b/src/Mod/Part/App/PrimitiveFeature.cpp index 095ce83a3c..02d13f8825 100644 --- a/src/Mod/Part/App/PrimitiveFeature.cpp +++ b/src/Mod/Part/App/PrimitiveFeature.cpp @@ -22,7 +22,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include +# include # include # include # include @@ -57,7 +57,7 @@ namespace Part { const App::PropertyQuantityConstraint::Constraints torusRangeV = {-180.0, 180.0, 1.0}; const App::PropertyQuantityConstraint::Constraints angleRangeU = {0.0, 360.0, 1.0}; const App::PropertyQuantityConstraint::Constraints angleRangeV = {-90.0, 90.0, 1.0}; - const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0, FLT_MAX, 0.1}; + const App::PropertyQuantityConstraint::Constraints quantityRange = {0.0, std::numeric_limits::max(), 0.1}; } using namespace Part; diff --git a/src/Mod/Part/App/ShapeMapHasher.h b/src/Mod/Part/App/ShapeMapHasher.h index 6b0fe94c4c..24ab2a5b30 100644 --- a/src/Mod/Part/App/ShapeMapHasher.h +++ b/src/Mod/Part/App/ShapeMapHasher.h @@ -38,7 +38,7 @@ public: size_t operator()(const TopoDS_Shape& theShape) const { #if OCC_VERSION_HEX < 0x070800 - return theShape.HashCode(INT_MAX); + return theShape.HashCode(std::numeric_limits::max()); #else return std::hash{}(theShape); #endif diff --git a/src/Mod/Part/App/Tools.cpp b/src/Mod/Part/App/Tools.cpp index 93ce969ec9..12cfe3f949 100644 --- a/src/Mod/Part/App/Tools.cpp +++ b/src/Mod/Part/App/Tools.cpp @@ -773,9 +773,9 @@ bool Part::Tools::isConcave(const TopoDS_Face &face, const gp_Pnt &pointOfVue, c // check normals orientation gp_Dir dirdU(dU); - result = (dirdU.Angle(direction) - M_PI_2) <= Precision::Confusion(); + result = (dirdU.Angle(direction) - std::numbers::pi/2) <= Precision::Confusion(); gp_Dir dirdV(dV); - result = result || ((dirdV.Angle(direction) - M_PI_2) <= Precision::Confusion()); + result = result || ((dirdV.Angle(direction) - std::numbers::pi/2) <= Precision::Confusion()); return result; } diff --git a/src/Mod/Part/App/TopoShape.cpp b/src/Mod/Part/App/TopoShape.cpp index 8d70e4c3c1..951b6086dc 100644 --- a/src/Mod/Part/App/TopoShape.cpp +++ b/src/Mod/Part/App/TopoShape.cpp @@ -2004,7 +2004,7 @@ TopoDS_Shape TopoShape::makeTube(double radius, double tol, int cont, int maxdeg //circular profile Handle(Geom_Circle) aCirc = new Geom_Circle (gp::XOY(), theRadius); - aCirc->Rotate (gp::OZ(), M_PI/2.); + aCirc->Rotate (gp::OZ(), std::numbers::pi/2.); //perpendicular section Handle(Law_Function) myEvol = ::CreateBsFunction (myPath->FirstParameter(), myPath->LastParameter(), theRadius); @@ -2116,6 +2116,8 @@ TopoDS_Shape TopoShape::makeHelix(Standard_Real pitch, Standard_Real height, Standard_Boolean leftHanded, Standard_Boolean newStyle) const { + using std::numbers::pi; + if (fabs(pitch) < Precision::Confusion()) Standard_Failure::Raise("Pitch of helix too small"); @@ -2140,24 +2142,24 @@ TopoDS_Shape TopoShape::makeHelix(Standard_Real pitch, Standard_Real height, } gp_Pnt2d aPnt(0, 0); - gp_Dir2d aDir(2. * M_PI, pitch); + gp_Dir2d aDir(2. * pi, pitch); Standard_Real coneDir = 1.0; if (leftHanded) { - aDir.SetCoord(-2. * M_PI, pitch); + aDir.SetCoord(-2. * pi, pitch); coneDir = -1.0; } gp_Ax2d aAx2d(aPnt, aDir); Handle(Geom2d_Line) line = new Geom2d_Line(aAx2d); gp_Pnt2d beg = line->Value(0); - gp_Pnt2d end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*(height/pitch)); + gp_Pnt2d end = line->Value(sqrt(4.0*pi*pi+pitch*pitch)*(height/pitch)); if (newStyle) { // See discussion at 0001247: Part Conical Helix Height/Pitch Incorrect if (angle >= Precision::Confusion()) { // calculate end point for conical helix Standard_Real v = height / cos(angle); - Standard_Real u = coneDir * (height/pitch) * 2.0 * M_PI; + Standard_Real u = coneDir * (height/pitch) * 2.0 * pi; gp_Pnt2d cend(u, v); end = cend; } @@ -2179,6 +2181,8 @@ TopoDS_Shape TopoShape::makeLongHelix(Standard_Real pitch, Standard_Real height, Standard_Real radius, Standard_Real angle, Standard_Boolean leftHanded) const { + using std::numbers::pi; + if (pitch < Precision::Confusion()) Standard_Failure::Raise("Pitch of helix too small"); @@ -2206,10 +2210,10 @@ TopoDS_Shape TopoShape::makeLongHelix(Standard_Real pitch, Standard_Real height, Standard_Real partTurn = turns - wholeTurns; gp_Pnt2d aPnt(0, 0); - gp_Dir2d aDir(2. * M_PI, pitch); + gp_Dir2d aDir(2. * pi, pitch); Standard_Real coneDir = 1.0; if (leftHanded) { - aDir.SetCoord(-2. * M_PI, pitch); + aDir.SetCoord(-2. * pi, pitch); coneDir = -1.0; } gp_Ax2d aAx2d(aPnt, aDir); @@ -2223,10 +2227,10 @@ TopoDS_Shape TopoShape::makeLongHelix(Standard_Real pitch, Standard_Real height, for (unsigned long i = 0; i < wholeTurns; i++) { if (isCylinder) { - end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*(i+1)); + end = line->Value(sqrt(4.0*pi*pi+pitch*pitch)*(i+1)); } else { - u = coneDir * (i+1) * 2.0 * M_PI; + u = coneDir * (i+1) * 2.0 * pi; v = ((i+1) * pitch) / cos(angle); end = gp_Pnt2d(u, v); } @@ -2238,10 +2242,10 @@ TopoDS_Shape TopoShape::makeLongHelix(Standard_Real pitch, Standard_Real height, if (partTurn > Precision::Confusion()) { if (isCylinder) { - end = line->Value(sqrt(4.0*M_PI*M_PI+pitch*pitch)*turns); + end = line->Value(sqrt(4.0*pi*pi+pitch*pitch)*turns); } else { - u = coneDir * turns * 2.0 * M_PI; + u = coneDir * turns * 2.0 * pi; v = height / cos(angle); end = gp_Pnt2d(u, v); } @@ -2283,9 +2287,9 @@ TopoDS_Shape TopoShape::makeSpiralHelix(Standard_Real radiusbottom, Standard_Rea gp_Pnt2d beg(0, 0); gp_Pnt2d end(0, 0); - gp_Vec2d dir(breakperiod * 2.0 * M_PI, 1 / nbPeriods); + gp_Vec2d dir(breakperiod * 2.0 * std::numbers::pi, 1 / nbPeriods); if (leftHanded == Standard_True) - dir = gp_Vec2d(-breakperiod * 2.0 * M_PI, 1 / nbPeriods); + dir = gp_Vec2d(-breakperiod * 2.0 * std::numbers::pi, 1 / nbPeriods); Handle(Geom2d_TrimmedCurve) segm; TopoDS_Edge edgeOnSurf; BRepBuilderAPI_MakeWire mkWire; @@ -2314,6 +2318,7 @@ TopoDS_Shape TopoShape::makeThread(Standard_Real pitch, Standard_Real height, Standard_Real radius) const { + using std::numbers::pi; if (pitch < Precision::Confusion()) Standard_Failure::Raise("Pitch of thread too small"); @@ -2332,21 +2337,21 @@ TopoDS_Shape TopoShape::makeThread(Standard_Real pitch, Handle(Geom_CylindricalSurface) aCyl2 = new Geom_CylindricalSurface(cylAx2 , radius+depth); //Threading : Define 2D Curves - gp_Pnt2d aPnt(2. * M_PI , height / 2.); - gp_Dir2d aDir(2. * M_PI , height / 4.); + gp_Pnt2d aPnt(2. * pi , height / 2.); + gp_Dir2d aDir(2. * pi , height / 4.); gp_Ax2d aAx2d(aPnt , aDir); - Standard_Real aMajor = 2. * M_PI; + Standard_Real aMajor = 2. * pi; Standard_Real aMinor = pitch; Handle(Geom2d_Ellipse) anEllipse1 = new Geom2d_Ellipse(aAx2d , aMajor , aMinor); Handle(Geom2d_Ellipse) anEllipse2 = new Geom2d_Ellipse(aAx2d , aMajor , aMinor / 4); - Handle(Geom2d_TrimmedCurve) aArc1 = new Geom2d_TrimmedCurve(anEllipse1 , 0 , M_PI); - Handle(Geom2d_TrimmedCurve) aArc2 = new Geom2d_TrimmedCurve(anEllipse2 , 0 , M_PI); + Handle(Geom2d_TrimmedCurve) aArc1 = new Geom2d_TrimmedCurve(anEllipse1 , 0 , pi); + Handle(Geom2d_TrimmedCurve) aArc2 = new Geom2d_TrimmedCurve(anEllipse2 , 0 , pi); gp_Pnt2d anEllipsePnt1 = anEllipse1->Value(0); - gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(M_PI); + gp_Pnt2d anEllipsePnt2 = anEllipse1->Value(pi); Handle(Geom2d_TrimmedCurve) aSegment = GCE2d_MakeSegment(anEllipsePnt1 , anEllipsePnt2); diff --git a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp index 6b39d05fd8..b3257c90fd 100644 --- a/src/Mod/Part/App/TopoShapeEdgePyImp.cpp +++ b/src/Mod/Part/App/TopoShapeEdgePyImp.cpp @@ -126,7 +126,8 @@ int TopoShapeEdgePy::PyInit(PyObject* args, PyObject* /*kwd*/) PyErr_Clear(); PyObject *pcObj, *pcObj2; - double first=DBL_MAX, last=DBL_MAX; + double first = std::numeric_limits::max(); + double last = std::numeric_limits::max(); if (PyArg_ParseTuple(args, "O!|dd", &(Part::GeometryPy::Type), &pcObj, &first, &last)) { Geometry* geom = static_cast(pcObj)->getGeometryPtr(); Handle(Geom_Curve) curve = Handle(Geom_Curve)::DownCast(geom->handle()); @@ -135,9 +136,9 @@ int TopoShapeEdgePy::PyInit(PyObject* args, PyObject* /*kwd*/) return -1; } - if (first==DBL_MAX) + if (first == std::numeric_limits::max()) first = curve->FirstParameter(); - if (last==DBL_MAX) + if (last == std::numeric_limits::max()) last = curve->LastParameter(); try { diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 5118bcf94b..39fd232357 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1611,6 +1611,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape, bool delayed = false; while (true) { + constexpr int intMin = std::numeric_limits::min(); // Construct the names for modification/generation info collected in // the previous step @@ -1632,7 +1633,7 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape, const auto& first_key = names.begin()->first; auto& first_info = names.begin()->second; - if (!delayed && first_key.shapetype >= 3 && first_info.index > INT_MIN + 1) { + if (!delayed && first_key.shapetype >= 3 && first_info.index > intMin + 1) { // This name is mapped from high level (shell, solid, etc.) // Delay till next round. // @@ -1680,10 +1681,10 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape, // 'K' marks the additional source shape of this // generate (or modified) shape. ss2 << elementMapPrefix() << 'K'; - if (other_info.index == INT_MIN) { + if (other_info.index == intMin) { ss2 << '0'; } - else if (other_info.index == INT_MIN + 1) { + else if (other_info.index == intMin + 1) { ss2 << "00"; } else { @@ -1740,10 +1741,10 @@ TopoShape& TopoShape::makeShapeWithElementMap(const TopoDS_Shape& shape, else { ss << modgenPostfix(); } - if (first_info.index == INT_MIN) { + if (first_info.index == intMin) { ss << '0'; } - else if (first_info.index == INT_MIN + 1) { + else if (first_info.index == intMin + 1) { ss << "00"; } else if (abs(first_info.index) > 1) { diff --git a/src/Mod/Part/App/TopoShapeMapper.h b/src/Mod/Part/App/TopoShapeMapper.h index 5ec165efab..0febe93d47 100644 --- a/src/Mod/Part/App/TopoShapeMapper.h +++ b/src/Mod/Part/App/TopoShapeMapper.h @@ -46,7 +46,7 @@ struct ShapeHasher #if OCC_VERSION_HEX >= 0x070800 return std::hash {}(s.getShape()); #else - return s.getShape().HashCode(INT_MAX); + return s.getShape().HashCode(std::numeric_limits::max()); #endif } inline size_t operator()(const TopoDS_Shape& s) const @@ -54,7 +54,7 @@ struct ShapeHasher #if OCC_VERSION_HEX >= 0x070800 return std::hash {}(s); #else - return s.HashCode(INT_MAX); + return s.HashCode(std::numeric_limits::max()); #endif } inline bool operator()(const TopoShape& a, const TopoShape& b) const @@ -78,8 +78,8 @@ struct ShapeHasher size_t res = std::hash {}(s.first.getShape()); hash_combine(res, std::hash {}(s.second.getShape())); #else - size_t res = s.first.getShape().HashCode(INT_MAX); - hash_combine(res, s.second.getShape().HashCode(INT_MAX)); + size_t res = s.first.getShape().HashCode(std::numeric_limits::max()); + hash_combine(res, s.second.getShape().HashCode(std::numeric_limits::max())); #endif return res; } @@ -89,8 +89,8 @@ struct ShapeHasher size_t res = std::hash {}(s.first); hash_combine(res, std::hash {}(s.second)); #else - size_t res = s.first.HashCode(INT_MAX); - hash_combine(res, s.second.HashCode(INT_MAX)); + size_t res = s.first.HashCode(std::numeric_limits::max()); + hash_combine(res, s.second.HashCode(std::numeric_limits::max())); #endif return res; } diff --git a/src/Mod/Part/App/TopoShapePyImp.cpp b/src/Mod/Part/App/TopoShapePyImp.cpp index 246c0c7e1a..c0b2ca1d2e 100644 --- a/src/Mod/Part/App/TopoShapePyImp.cpp +++ b/src/Mod/Part/App/TopoShapePyImp.cpp @@ -117,7 +117,8 @@ static Py_hash_t _TopoShapeHash(PyObject* self) #if OCC_VERSION_HEX >= 0x070800 return std::hash {}(static_cast(self)->getTopoShapePtr()->getShape()); #else - return static_cast(self)->getTopoShapePtr()->getShape().HashCode(INT_MAX); + return static_cast(self)->getTopoShapePtr()->getShape().HashCode( + std::numeric_limits::max()); #endif } diff --git a/src/Mod/Part/App/WireJoiner.cpp b/src/Mod/Part/App/WireJoiner.cpp index 0987454766..abe3cf1326 100644 --- a/src/Mod/Part/App/WireJoiner.cpp +++ b/src/Mod/Part/App/WireJoiner.cpp @@ -784,11 +784,12 @@ public: const bool isLinear) { std::unique_ptr geo; - for (auto vit = vmap.qbegin(bgi::nearest(p1, INT_MAX)); vit != vmap.qend(); ++vit) { + constexpr int max = std::numeric_limits::max(); + for (auto vit = vmap.qbegin(bgi::nearest(p1, max)); vit != vmap.qend(); ++vit) { auto& vinfo = *vit; if (canShowShape()) { #if OCC_VERSION_HEX < 0x070800 - FC_MSG("addcheck " << vinfo.edge().HashCode(INT_MAX)); + FC_MSG("addcheck " << vinfo.edge().HashCode(max)); #else FC_MSG("addcheck " << std::hash {}(vinfo.edge())); #endif @@ -1568,7 +1569,8 @@ public: } info.iEnd[ic] = info.iStart[ic] = (int)adjacentList.size(); - for (auto vit = vmap.qbegin(bgi::nearest(pt[ic], INT_MAX)); vit != vmap.qend(); + constexpr int max = std::numeric_limits::max(); + for (auto vit = vmap.qbegin(bgi::nearest(pt[ic], max)); vit != vmap.qend(); ++vit) { auto& vinfo = *vit; if (vinfo.pt().SquareDistance(pt[ic]) > myTol2) { @@ -2717,7 +2719,8 @@ public: FC_MSG("init:"); for (const auto& shape : sourceEdges) { #if OCC_VERSION_HEX < 0x070800 - FC_MSG(shape.getShape().TShape().get() << ", " << shape.getShape().HashCode(INT_MAX)); + constexpr int max = std::numeric_limits::max(); + FC_MSG(shape.getShape().TShape().get() << ", " << shape.getShape().HashCode(max)); #else FC_MSG(shape.getShape().TShape().get() << ", " << std::hash {}(shape.getShape())); @@ -2736,7 +2739,8 @@ public: for (int i = 1; i <= wireData->NbEdges(); ++i) { auto shape = wireData->Edge(i); #if OCC_VERSION_HEX < 0x070800 - FC_MSG(shape.TShape().get() << ", " << shape.HashCode(INT_MAX)); + constexpr int max = std::numeric_limits::max(); + FC_MSG(shape.TShape().get() << ", " << shape.HashCode(max)); #else FC_MSG(shape.TShape().get() << ", " << std::hash {}(shape)); #endif @@ -2800,9 +2804,10 @@ public: for (TopTools_ListIteratorOfListOfShape it(hist->Modified(shape.getShape())); it.More(); it.Next()) { #if OCC_VERSION_HEX < 0x070800 - FC_MSG(shape.getShape().TShape().get() - << ", " << shape.getShape().HashCode(INT_MAX) << " -> " - << it.Value().TShape().get() << ", " << it.Value().HashCode(INT_MAX)); + constexpr int max = std::numeric_limits::max(); + FC_MSG(shape.getShape().TShape().get() + << ", " << shape.getShape().HashCode(max) << " -> " + << it.Value().TShape().get() << ", " << it.Value().HashCode(max)); #else FC_MSG(shape.getShape().TShape().get() << ", " << std::hash {}(shape.getShape()) << " -> " diff --git a/src/Mod/Part/App/modelRefine.cpp b/src/Mod/Part/App/modelRefine.cpp index ebf58c6c27..0c6338f979 100644 --- a/src/Mod/Part/App/modelRefine.cpp +++ b/src/Mod/Part/App/modelRefine.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ # include +# include # include # include # include @@ -613,8 +614,8 @@ bool wireEncirclesAxis(const TopoDS_Wire& wire, const Handle(Geom_CylindricalSur // For an exact calculation, only two results would be possible: // totalArc = 0.0: The wire does not encircle the axis - // totalArc = 2 * M_PI * radius: The wire encircles the axis - return (fabs(totalArc) > M_PI * radius); + // totalArc = 2 * std::numbers::pi * radius: The wire encircles the axis + return (fabs(totalArc) > std::numbers::pi * radius); } TopoDS_Face FaceTypedCylinder::buildFace(const FaceVectorType &faces) const diff --git a/src/Mod/Part/Gui/CrossSections.cpp b/src/Mod/Part/Gui/CrossSections.cpp index ae425a6776..ed2f1f8dad 100644 --- a/src/Mod/Part/Gui/CrossSections.cpp +++ b/src/Mod/Part/Gui/CrossSections.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include # include @@ -126,9 +125,10 @@ CrossSections::CrossSections(const Base::BoundBox3d& bb, QWidget* parent, Qt::Wi ui->setupUi(this); setupConnections(); - ui->position->setRange(-DBL_MAX, DBL_MAX); + constexpr double max = std::numeric_limits::max(); + ui->position->setRange(-max, max); ui->position->setUnit(Base::Unit::Length); - ui->distance->setRange(0, DBL_MAX); + ui->distance->setRange(0, max); ui->distance->setUnit(Base::Unit::Length); vp = new ViewProviderCrossSections(); diff --git a/src/Mod/Part/Gui/DlgFilletEdges.cpp b/src/Mod/Part/Gui/DlgFilletEdges.cpp index 7a1ece5eec..ea0356bd02 100644 --- a/src/Mod/Part/Gui/DlgFilletEdges.cpp +++ b/src/Mod/Part/Gui/DlgFilletEdges.cpp @@ -89,7 +89,7 @@ QWidget *FilletRadiusDelegate::createEditor(QWidget *parent, const QStyleOptionV Gui::QuantitySpinBox *editor = new Gui::QuantitySpinBox(parent); editor->setUnit(Base::Unit::Length); editor->setMinimum(0.0); - editor->setMaximum(INT_MAX); + editor->setMaximum(std::numeric_limits::max()); editor->setSingleStep(0.1); return editor; @@ -234,11 +234,11 @@ DlgFilletEdges::DlgFilletEdges(FilletType type, Part::FilletBase* fillet, QWidge ui->setupUi(this); setupConnections(); - ui->filletStartRadius->setMaximum(INT_MAX); + ui->filletStartRadius->setMaximum(std::numeric_limits::max()); ui->filletStartRadius->setMinimum(0); ui->filletStartRadius->setUnit(Base::Unit::Length); - ui->filletEndRadius->setMaximum(INT_MAX); + ui->filletEndRadius->setMaximum(std::numeric_limits::max()); ui->filletEndRadius->setMinimum(0); ui->filletEndRadius->setUnit(Base::Unit::Length); diff --git a/src/Mod/Part/Gui/DlgPrimitives.cpp b/src/Mod/Part/Gui/DlgPrimitives.cpp index bde63661a4..ef411ecb96 100644 --- a/src/Mod/Part/Gui/DlgPrimitives.cpp +++ b/src/Mod/Part/Gui/DlgPrimitives.cpp @@ -239,8 +239,8 @@ PlanePrimitive::PlanePrimitive(std::shared_ptr ui, Part::Plane : AbstractPrimitive(feature) , ui(ui) { - ui->planeLength->setRange(0, INT_MAX); - ui->planeWidth->setRange(0, INT_MAX); + ui->planeLength->setRange(0, std::numeric_limits::max()); + ui->planeWidth->setRange(0, std::numeric_limits::max()); if (feature) { ui->planeLength->setValue(feature->Length.getQuantityValue()); @@ -308,9 +308,9 @@ BoxPrimitive::BoxPrimitive(std::shared_ptr ui, Part::Box* feat : AbstractPrimitive(feature) , ui(ui) { - ui->boxLength->setRange(0, INT_MAX); - ui->boxWidth->setRange(0, INT_MAX); - ui->boxHeight->setRange(0, INT_MAX); + ui->boxLength->setRange(0, std::numeric_limits::max()); + ui->boxWidth->setRange(0, std::numeric_limits::max()); + ui->boxHeight->setRange(0, std::numeric_limits::max()); if (feature) { ui->boxLength->setValue(feature->Length.getQuantityValue()); @@ -388,8 +388,8 @@ CylinderPrimitive::CylinderPrimitive(std::shared_ptr ui, Part: : AbstractPrimitive(feature) , ui(ui) { - ui->cylinderRadius->setRange(0, INT_MAX); - ui->cylinderHeight->setRange(0, INT_MAX); + ui->cylinderRadius->setRange(0, std::numeric_limits::max()); + ui->cylinderHeight->setRange(0, std::numeric_limits::max()); ui->cylinderAngle->setRange(0, 360); if (feature) { @@ -488,9 +488,9 @@ ConePrimitive::ConePrimitive(std::shared_ptr ui, Part::Cone* f : AbstractPrimitive(feature) , ui(ui) { - ui->coneRadius1->setRange(0, INT_MAX); - ui->coneRadius2->setRange(0, INT_MAX); - ui->coneHeight->setRange(0, INT_MAX); + ui->coneRadius1->setRange(0, std::numeric_limits::max()); + ui->coneRadius2->setRange(0, std::numeric_limits::max()); + ui->coneHeight->setRange(0, std::numeric_limits::max()); ui->coneAngle->setRange(0, 360); if (feature) { @@ -579,7 +579,7 @@ SpherePrimitive::SpherePrimitive(std::shared_ptr ui, Part::Sph : AbstractPrimitive(feature) , ui(ui) { - ui->sphereRadius->setRange(0, INT_MAX); + ui->sphereRadius->setRange(0, std::numeric_limits::max()); ui->sphereAngle1->setRange(-90, 90); ui->sphereAngle2->setRange(-90, 90); ui->sphereAngle3->setRange(0, 360); @@ -670,9 +670,9 @@ EllipsoidPrimitive::EllipsoidPrimitive(std::shared_ptr ui, Par : AbstractPrimitive(feature) , ui(ui) { - ui->ellipsoidRadius1->setRange(0, INT_MAX); - ui->ellipsoidRadius2->setRange(0, INT_MAX); - ui->ellipsoidRadius3->setRange(0, INT_MAX); + ui->ellipsoidRadius1->setRange(0, std::numeric_limits::max()); + ui->ellipsoidRadius2->setRange(0, std::numeric_limits::max()); + ui->ellipsoidRadius3->setRange(0, std::numeric_limits::max()); ui->ellipsoidAngle1->setRange(-90, 90); ui->ellipsoidAngle2->setRange(-90, 90); ui->ellipsoidAngle3->setRange(0, 360); @@ -784,8 +784,8 @@ TorusPrimitive::TorusPrimitive(std::shared_ptr ui, Part::Torus : AbstractPrimitive(feature) , ui(ui) { - ui->torusRadius1->setRange(0, INT_MAX); - ui->torusRadius2->setRange(0, INT_MAX); + ui->torusRadius1->setRange(0, std::numeric_limits::max()); + ui->torusRadius2->setRange(0, std::numeric_limits::max()); ui->torusAngle1->setRange(-180, 180); ui->torusAngle2->setRange(-180, 180); ui->torusAngle3->setRange(0, 360); @@ -886,8 +886,8 @@ PrismPrimitive::PrismPrimitive(std::shared_ptr ui, Part::Prism : AbstractPrimitive(feature) , ui(ui) { - ui->prismCircumradius->setRange(0, INT_MAX); - ui->prismHeight->setRange(0, INT_MAX); + ui->prismCircumradius->setRange(0, std::numeric_limits::max()); + ui->prismHeight->setRange(0, std::numeric_limits::max()); if (feature) { ui->prismPolygon->setValue(feature->Polygon.getValue()); @@ -984,26 +984,28 @@ WedgePrimitive::WedgePrimitive(std::shared_ptr ui, Part::Wedge : AbstractPrimitive(feature) , ui(ui) { - ui->wedgeXmin->setMinimum(INT_MIN); - ui->wedgeXmin->setMaximum(INT_MAX); - ui->wedgeYmin->setMinimum(INT_MIN); - ui->wedgeYmin->setMaximum(INT_MAX); - ui->wedgeZmin->setMinimum(INT_MIN); - ui->wedgeZmin->setMaximum(INT_MAX); - ui->wedgeX2min->setMinimum(INT_MIN); - ui->wedgeX2min->setMaximum(INT_MAX); - ui->wedgeZ2min->setMinimum(INT_MIN); - ui->wedgeZ2min->setMaximum(INT_MAX); - ui->wedgeXmax->setMinimum(INT_MIN); - ui->wedgeXmax->setMaximum(INT_MAX); - ui->wedgeYmax->setMinimum(INT_MIN); - ui->wedgeYmax->setMaximum(INT_MAX); - ui->wedgeZmax->setMinimum(INT_MIN); - ui->wedgeZmax->setMaximum(INT_MAX); - ui->wedgeX2max->setMinimum(INT_MIN); - ui->wedgeX2max->setMaximum(INT_MAX); - ui->wedgeZ2max->setMinimum(INT_MIN); - ui->wedgeZ2max->setMaximum(INT_MAX); + constexpr int min = std::numeric_limits::min(); + constexpr int max = std::numeric_limits::max(); + ui->wedgeXmin->setMinimum(min); + ui->wedgeXmin->setMaximum(max); + ui->wedgeYmin->setMinimum(min); + ui->wedgeYmin->setMaximum(max); + ui->wedgeZmin->setMinimum(min); + ui->wedgeZmin->setMaximum(max); + ui->wedgeX2min->setMinimum(min); + ui->wedgeX2min->setMaximum(max); + ui->wedgeZ2min->setMinimum(min); + ui->wedgeZ2min->setMaximum(max); + ui->wedgeXmax->setMinimum(min); + ui->wedgeXmax->setMaximum(max); + ui->wedgeYmax->setMinimum(min); + ui->wedgeYmax->setMaximum(max); + ui->wedgeZmax->setMinimum(min); + ui->wedgeZmax->setMaximum(max); + ui->wedgeX2max->setMinimum(min); + ui->wedgeX2max->setMaximum(max); + ui->wedgeZ2max->setMinimum(min); + ui->wedgeZ2max->setMaximum(max); if (feature) { ui->wedgeXmin->setValue(feature->Xmin.getQuantityValue()); @@ -1151,9 +1153,9 @@ HelixPrimitive::HelixPrimitive(std::shared_ptr ui, Part::Helix : AbstractPrimitive(feature) , ui(ui) { - ui->helixPitch->setRange(0, INT_MAX); - ui->helixHeight->setRange(0, INT_MAX); - ui->helixRadius->setRange(0, INT_MAX); + ui->helixPitch->setRange(0, std::numeric_limits::max()); + ui->helixHeight->setRange(0, std::numeric_limits::max()); + ui->helixRadius->setRange(0, std::numeric_limits::max()); ui->helixAngle->setRange(-89.9, 89.9); if (feature) { @@ -1252,9 +1254,9 @@ SpiralPrimitive::SpiralPrimitive(std::shared_ptr ui, Part::Spi : AbstractPrimitive(feature) , ui(ui) { - ui->spiralGrowth->setRange(0, INT_MAX); - ui->spiralRotation->setRange(0, INT_MAX); - ui->spiralRadius->setRange(0, INT_MAX); + ui->spiralGrowth->setRange(0, std::numeric_limits::max()); + ui->spiralRotation->setRange(0, std::numeric_limits::max()); + ui->spiralRadius->setRange(0, std::numeric_limits::max()); if (feature) { ui->spiralGrowth->setValue(feature->Growth.getQuantityValue()); @@ -1331,7 +1333,7 @@ CirclePrimitive::CirclePrimitive(std::shared_ptr ui, Part::Cir : AbstractPrimitive(feature) , ui(ui) { - ui->circleRadius->setRange(0, INT_MAX); + ui->circleRadius->setRange(0, std::numeric_limits::max()); ui->circleAngle1->setRange(0, 360); ui->circleAngle2->setRange(0, 360); @@ -1411,8 +1413,8 @@ EllipsePrimitive::EllipsePrimitive(std::shared_ptr ui, Part::E : AbstractPrimitive(feature) , ui(ui) { - ui->ellipseMajorRadius->setRange(0, INT_MAX); - ui->ellipseMinorRadius->setRange(0, INT_MAX); + ui->ellipseMajorRadius->setRange(0, std::numeric_limits::max()); + ui->ellipseMinorRadius->setRange(0, std::numeric_limits::max()); ui->ellipseAngle1->setRange(0, 360); ui->ellipseAngle2->setRange(0, 360); @@ -1502,7 +1504,7 @@ PolygonPrimitive::PolygonPrimitive(std::shared_ptr ui, Part::R : AbstractPrimitive(feature) , ui(ui) { - ui->regularPolygonCircumradius->setRange(0, INT_MAX); + ui->regularPolygonCircumradius->setRange(0, std::numeric_limits::max()); if (feature) { ui->regularPolygonPolygon->setValue(feature->Polygon.getValue()); @@ -1569,18 +1571,20 @@ LinePrimitive::LinePrimitive(std::shared_ptr ui, Part::Line* f : AbstractPrimitive(feature) , ui(ui) { - ui->edgeX1->setMaximum(INT_MAX); - ui->edgeX1->setMinimum(INT_MIN); - ui->edgeY1->setMaximum(INT_MAX); - ui->edgeY1->setMinimum(INT_MIN); - ui->edgeZ1->setMaximum(INT_MAX); - ui->edgeZ1->setMinimum(INT_MIN); - ui->edgeX2->setMaximum(INT_MAX); - ui->edgeX2->setMinimum(INT_MIN); - ui->edgeY2->setMaximum(INT_MAX); - ui->edgeY2->setMinimum(INT_MIN); - ui->edgeZ2->setMaximum(INT_MAX); - ui->edgeZ2->setMinimum(INT_MIN); + constexpr int min = std::numeric_limits::min(); + constexpr int max = std::numeric_limits::max(); + ui->edgeX1->setMaximum(max); + ui->edgeX1->setMinimum(min); + ui->edgeY1->setMaximum(max); + ui->edgeY1->setMinimum(min); + ui->edgeZ1->setMaximum(max); + ui->edgeZ1->setMinimum(min); + ui->edgeX2->setMaximum(max); + ui->edgeX2->setMinimum(min); + ui->edgeY2->setMaximum(max); + ui->edgeY2->setMinimum(min); + ui->edgeZ2->setMaximum(max); + ui->edgeZ2->setMinimum(min); if (feature) { ui->edgeX1->setValue(feature->X1.getQuantityValue()); @@ -1688,12 +1692,14 @@ VertexPrimitive::VertexPrimitive(std::shared_ptr ui, Part::Ver : AbstractPrimitive(feature) , ui(ui) { - ui->vertexX->setMaximum(INT_MAX); - ui->vertexY->setMaximum(INT_MAX); - ui->vertexZ->setMaximum(INT_MAX); - ui->vertexX->setMinimum(INT_MIN); - ui->vertexY->setMinimum(INT_MIN); - ui->vertexZ->setMinimum(INT_MIN); + constexpr int min = std::numeric_limits::min(); + constexpr int max = std::numeric_limits::max(); + ui->vertexX->setMaximum(max); + ui->vertexY->setMaximum(max); + ui->vertexZ->setMaximum(max); + ui->vertexX->setMinimum(min); + ui->vertexY->setMinimum(min); + ui->vertexZ->setMinimum(min); if (feature) { ui->vertexX->setValue(feature->X.getQuantityValue()); diff --git a/src/Mod/Part/Gui/DlgRevolution.cpp b/src/Mod/Part/Gui/DlgRevolution.cpp index 950552184b..04672dd218 100644 --- a/src/Mod/Part/Gui/DlgRevolution.cpp +++ b/src/Mod/Part/Gui/DlgRevolution.cpp @@ -103,16 +103,17 @@ DlgRevolution::DlgRevolution(QWidget* parent, Qt::WindowFlags fl) ui->setupUi(this); setupConnections(); - ui->xPos->setRange(-DBL_MAX,DBL_MAX); - ui->yPos->setRange(-DBL_MAX,DBL_MAX); - ui->zPos->setRange(-DBL_MAX,DBL_MAX); + constexpr double max = std::numeric_limits::max(); + ui->xPos->setRange(-max, max); + ui->yPos->setRange(-max, max); + ui->zPos->setRange(-max, max); ui->xPos->setUnit(Base::Unit::Length); ui->yPos->setUnit(Base::Unit::Length); ui->zPos->setUnit(Base::Unit::Length); - ui->xDir->setRange(-DBL_MAX,DBL_MAX); - ui->yDir->setRange(-DBL_MAX,DBL_MAX); - ui->zDir->setRange(-DBL_MAX,DBL_MAX); + ui->xDir->setRange(-max, max); + ui->yDir->setRange(-max, max); + ui->zDir->setRange(-max, max); ui->xDir->setUnit(Base::Unit()); ui->yDir->setUnit(Base::Unit()); ui->zDir->setUnit(Base::Unit()); @@ -307,7 +308,7 @@ bool DlgRevolution::validate() //check angle if (!axisLinkHasAngle){ - if (fabs(this->getAngle() / 180.0 * M_PI) < Precision::Angular()) { + if (fabs(this->getAngle() / 180.0 * std::numbers::pi) < Precision::Angular()) { QMessageBox::critical(this, windowTitle(), tr("Revolution angle span is zero. It must be non-zero.")); ui->angle->setFocus(); diff --git a/src/Mod/Part/Gui/Mirroring.cpp b/src/Mod/Part/Gui/Mirroring.cpp index ad456338cb..09881413da 100644 --- a/src/Mod/Part/Gui/Mirroring.cpp +++ b/src/Mod/Part/Gui/Mirroring.cpp @@ -24,9 +24,6 @@ #ifndef _PreComp_ -// to avoid compiler warnings of redefining contents of basic.h -// later by #include -# define _USE_MATH_DEFINES # include # include @@ -40,7 +37,6 @@ # include # include -# include # include # include # include @@ -182,9 +178,10 @@ Mirroring::Mirroring(QWidget* parent) : QWidget(parent), ui(new Ui_Mirroring) { ui->setupUi(this); - ui->baseX->setRange(-DBL_MAX, DBL_MAX); - ui->baseY->setRange(-DBL_MAX, DBL_MAX); - ui->baseZ->setRange(-DBL_MAX, DBL_MAX); + constexpr double max = std::numeric_limits::max(); + ui->baseX->setRange(-max, max); + ui->baseY->setRange(-max, max); + ui->baseZ->setRange(-max, max); ui->baseX->setUnit(Base::Unit::Length); ui->baseY->setUnit(Base::Unit::Length); ui->baseZ->setUnit(Base::Unit::Length); diff --git a/src/Mod/Part/Gui/PreCompiled.h b/src/Mod/Part/Gui/PreCompiled.h index 2f667b09ab..2eabeb2acf 100644 --- a/src/Mod/Part/Gui/PreCompiled.h +++ b/src/Mod/Part/Gui/PreCompiled.h @@ -45,7 +45,6 @@ #ifdef _PreComp_ // standard -#include #include // STL diff --git a/src/Mod/Part/Gui/PropertyEnumAttacherItem.cpp b/src/Mod/Part/Gui/PropertyEnumAttacherItem.cpp index 4907910d5d..15956d3bd9 100644 --- a/src/Mod/Part/Gui/PropertyEnumAttacherItem.cpp +++ b/src/Mod/Part/Gui/PropertyEnumAttacherItem.cpp @@ -24,10 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef _MSC_VER -# define _USE_MATH_DEFINES -# include -# endif //_MSC_VER +# include #endif // _PreComp_ #include diff --git a/src/Mod/Part/Gui/SectionCutting.cpp b/src/Mod/Part/Gui/SectionCutting.cpp index 55043207c6..0885ffa9ed 100644 --- a/src/Mod/Part/Gui/SectionCutting.cpp +++ b/src/Mod/Part/Gui/SectionCutting.cpp @@ -23,10 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ - -// to avoid compiler warnings of redefining contents of basic.h -// later by #include -# define _USE_MATH_DEFINES // NOLINT # include # include @@ -136,9 +132,10 @@ SectionCut::SectionCut(QWidget* parent) void SectionCut::initSpinBoxes() { - ui->cutX->setRange(-INT_MAX, INT_MAX); - ui->cutY->setRange(-INT_MAX, INT_MAX); - ui->cutZ->setRange(-INT_MAX, INT_MAX); + constexpr int max = std::numeric_limits::max(); + ui->cutX->setRange(-max, max); + ui->cutY->setRange(-max, max); + ui->cutZ->setRange(-max, max); } void SectionCut::initControls(const Base::BoundBox3d& BoundCompound) diff --git a/src/Mod/Part/Gui/SoBrepEdgeSet.cpp b/src/Mod/Part/Gui/SoBrepEdgeSet.cpp index dbb959bea4..6d8c5d2bba 100644 --- a/src/Mod/Part/Gui/SoBrepEdgeSet.cpp +++ b/src/Mod/Part/Gui/SoBrepEdgeSet.cpp @@ -32,7 +32,6 @@ # include # endif # include -# include # include # include # include @@ -85,7 +84,7 @@ void SoBrepEdgeSet::GLRender(SoGLRenderAction *action) selContext2->sl.push_back(-1); }else if(ctx) selContext2->sl = ctx->sl; - if(selContext2->highlightIndex==INT_MAX) { + if(selContext2->highlightIndex == std::numeric_limits::max()) { selContext2->hl.clear(); selContext2->hl.push_back(-1); }else if(ctx) @@ -93,7 +92,7 @@ void SoBrepEdgeSet::GLRender(SoGLRenderAction *action) ctx = selContext2; } - if(ctx && ctx->highlightIndex==INT_MAX) { + if(ctx && ctx->highlightIndex == std::numeric_limits::max()) { if(ctx->selectionIndex.empty() || ctx->isSelectAll()) { if(ctx2) { ctx2->selectionColor = ctx->highlightColor; @@ -329,7 +328,7 @@ void SoBrepEdgeSet::doAction(SoAction* action) if (!detail) { SelContextPtr ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext); ctx->highlightColor = hlaction->getColor(); - ctx->highlightIndex = INT_MAX; + ctx->highlightIndex = std::numeric_limits::max(); ctx->hl.clear(); ctx->hl.push_back(-1); touch(); diff --git a/src/Mod/Part/Gui/SoBrepFaceSet.cpp b/src/Mod/Part/Gui/SoBrepFaceSet.cpp index 14e716f20c..1f0c9be301 100644 --- a/src/Mod/Part/Gui/SoBrepFaceSet.cpp +++ b/src/Mod/Part/Gui/SoBrepFaceSet.cpp @@ -30,7 +30,6 @@ #ifndef _PreComp_ # include -# include # include # include # include @@ -194,7 +193,7 @@ void SoBrepFaceSet::doAction(SoAction* action) const SoDetail* detail = hlaction->getElement(); if (!detail) { SelContextPtr ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext); - ctx->highlightIndex = INT_MAX; + ctx->highlightIndex = std::numeric_limits::max(); ctx->highlightColor = hlaction->getColor(); touch(); }else { @@ -549,7 +548,7 @@ void SoBrepFaceSet::GLRender(SoGLRenderAction *action) // Transparency complicates stuff even more, but not here. It will be handled inside // overrideMaterialBinding() // - if(ctx && ctx->highlightIndex==INT_MAX) { + if(ctx && ctx->highlightIndex == std::numeric_limits::max()) { if(ctx->selectionIndex.empty() || ctx->isSelectAll()) { if(ctx2) { ctx2->selectionColor = ctx->highlightColor; @@ -1222,7 +1221,7 @@ void SoBrepFaceSet::renderHighlight(SoGLRenderAction *action, SelContextPtr ctx) mb.sendFirst(); // make sure we have the correct material int id = ctx->highlightIndex; - if (id!=INT_MAX && id >= this->partIndex.getNum()) { + if (id != std::numeric_limits::max() && id >= this->partIndex.getNum()) { SoDebugError::postWarning("SoBrepFaceSet::renderHighlight", "highlightIndex out of range"); } else { @@ -1234,7 +1233,7 @@ void SoBrepFaceSet::renderHighlight(SoGLRenderAction *action, SelContextPtr ctx) // coords int start=0; int length; - if(id==INT_MAX) { + if(id == std::numeric_limits::max()) { length = numindices; id = 0; } else { diff --git a/src/Mod/Part/Gui/SoBrepPointSet.cpp b/src/Mod/Part/Gui/SoBrepPointSet.cpp index def234fcd6..e8cef49446 100644 --- a/src/Mod/Part/Gui/SoBrepPointSet.cpp +++ b/src/Mod/Part/Gui/SoBrepPointSet.cpp @@ -32,7 +32,6 @@ # include # endif # include -# include # include # include # include @@ -82,7 +81,7 @@ void SoBrepPointSet::GLRender(SoGLRenderAction *action) if(selContext2->checkGlobal(ctx)) ctx = selContext2; - if(ctx && ctx->highlightIndex==INT_MAX) { + if(ctx && ctx->highlightIndex == std::numeric_limits::max()) { if(ctx->selectionIndex.empty() || ctx->isSelectAll()) { if(ctx2) { ctx2->selectionColor = ctx->highlightColor; @@ -192,7 +191,7 @@ void SoBrepPointSet::renderHighlight(SoGLRenderAction *action, SelContextPtr ctx int id = ctx->highlightIndex; const SbVec3f * coords3d = coords->getArrayPtr3(); if(coords3d) { - if(id == INT_MAX) { + if(id == std::numeric_limits::max()) { glBegin(GL_POINTS); for(int idx=startIndex.getValue();idxgetNum();++idx) glVertex3fv((const GLfloat*) (coords3d + idx)); @@ -269,7 +268,7 @@ void SoBrepPointSet::doAction(SoAction* action) SelContextPtr ctx = Gui::SoFCSelectionRoot::getActionContext(action,this,selContext); const SoDetail* detail = hlaction->getElement(); if (!detail) { - ctx->highlightIndex = INT_MAX; + ctx->highlightIndex = std::numeric_limits::max(); ctx->highlightColor = hlaction->getColor(); touch(); return; diff --git a/src/Mod/Part/Gui/SoFCShapeObject.cpp b/src/Mod/Part/Gui/SoFCShapeObject.cpp index 50691d970b..1ee21830ce 100644 --- a/src/Mod/Part/Gui/SoFCShapeObject.cpp +++ b/src/Mod/Part/Gui/SoFCShapeObject.cpp @@ -32,7 +32,6 @@ # include # endif # include -# include # include # include # include @@ -160,9 +159,10 @@ void SoFCControlPoints::computeBBox(SoAction *action, SbBox3f &box, SbVec3f &cen const SbVec3f * points = coords->getArrayPtr3(); if (!points) return; - float maxX=-FLT_MAX, minX=FLT_MAX, - maxY=-FLT_MAX, minY=FLT_MAX, - maxZ=-FLT_MAX, minZ=FLT_MAX; + constexpr float floatMax = std::numeric_limits::max(); + float maxX=-floatMax, minX=floatMax, + maxY=-floatMax, minY=floatMax, + maxZ=-floatMax, minZ=floatMax; int32_t len = coords->getNum(); if (len > 0) { for (int32_t i=0; iui.spinOffset->setUnit(Base::Unit::Length); - d->ui.spinOffset->setRange(-INT_MAX, INT_MAX); + d->ui.spinOffset->setRange(-std::numeric_limits::max(), + std::numeric_limits::max()); d->ui.spinOffset->setSingleStep(0.1); d->ui.facesButton->hide(); diff --git a/src/Mod/Part/Gui/TaskThickness.cpp b/src/Mod/Part/Gui/TaskThickness.cpp index 09ed63c457..cc5e27dafc 100644 --- a/src/Mod/Part/Gui/TaskThickness.cpp +++ b/src/Mod/Part/Gui/TaskThickness.cpp @@ -91,7 +91,8 @@ ThicknessWidget::ThicknessWidget(Part::Thickness* thickness, QWidget* parent) d->ui.fillOffset->hide(); QSignalBlocker blockOffset(d->ui.spinOffset); - d->ui.spinOffset->setRange(-INT_MAX, INT_MAX); + d->ui.spinOffset->setRange(-std::numeric_limits::max(), + std::numeric_limits::max()); d->ui.spinOffset->setSingleStep(0.1); d->ui.spinOffset->setValue(d->thickness->Value.getValue()); diff --git a/src/Mod/Part/Gui/ViewProvider2DObject.cpp b/src/Mod/Part/Gui/ViewProvider2DObject.cpp index 50f8a20502..b54dab267f 100644 --- a/src/Mod/Part/Gui/ViewProvider2DObject.cpp +++ b/src/Mod/Part/Gui/ViewProvider2DObject.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include @@ -57,7 +56,8 @@ using namespace std; // Construction/Destruction const char* ViewProvider2DObjectGrid::GridStyleEnums[]= {"Dashed","Light",nullptr}; -App::PropertyQuantityConstraint::Constraints ViewProvider2DObjectGrid::GridSizeRange = {0.001,DBL_MAX,1.0}; +App::PropertyQuantityConstraint::Constraints ViewProvider2DObjectGrid::GridSizeRange = { + 0.001, std::numeric_limits::max(), 1.0}; PROPERTY_SOURCE(PartGui::ViewProvider2DObjectGrid, PartGui::ViewProvider2DObject) @@ -106,10 +106,11 @@ SoSeparator* ViewProvider2DObjectGrid::createGrid() else { // make sure that nine of the numbers are exactly zero because log(0) // is not defined - float xMin = std::abs(MinX) < FLT_EPSILON ? 0.01f : MinX; - float xMax = std::abs(MaxX) < FLT_EPSILON ? 0.01f : MaxX; - float yMin = std::abs(MinY) < FLT_EPSILON ? 0.01f : MinY; - float yMax = std::abs(MaxY) < FLT_EPSILON ? 0.01f : MaxY; + constexpr float floatEpsilon = std::numeric_limits::epsilon(); + float xMin = std::abs(MinX) < floatEpsilon ? 0.01f : MinX; + float xMax = std::abs(MaxX) < floatEpsilon ? 0.01f : MaxX; + float yMin = std::abs(MinY) < floatEpsilon ? 0.01f : MinY; + float yMax = std::abs(MaxY) < floatEpsilon ? 0.01f : MaxY; MiX = -exp(ceil(log(std::abs(xMin)))); MiX = std::min(MiX,(float)-exp(ceil(log(std::abs(0.1f*xMax))))); MaX = exp(ceil(log(std::abs(xMax)))); diff --git a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp index 848fa93336..0a99471950 100644 --- a/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderAttachExtension.cpp @@ -23,10 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef _MSC_VER -# define _USE_MATH_DEFINES -# include -# endif # include # include #endif diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index 0c23016cd6..6c771fa64e 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -976,7 +976,7 @@ void ViewProviderPartExt::updateVisual() //deflection = std::min(deflection, 20.0); // 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; IMeshTools_Parameters meshParams; meshParams.Deflection = deflection; diff --git a/src/Mod/Part/Gui/ViewProviderGridExtension.cpp b/src/Mod/Part/Gui/ViewProviderGridExtension.cpp index d0d0a84eee..f624823a22 100644 --- a/src/Mod/Part/Gui/ViewProviderGridExtension.cpp +++ b/src/Mod/Part/Gui/ViewProviderGridExtension.cpp @@ -23,7 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# include # include # include @@ -60,7 +59,8 @@ using namespace std; EXTENSION_PROPERTY_SOURCE(PartGui::ViewProviderGridExtension, Gui::ViewProviderExtension) -App::PropertyQuantityConstraint::Constraints ViewProviderGridExtension::GridSizeRange = { 0.001,DBL_MAX,1.0 }; +App::PropertyQuantityConstraint::Constraints ViewProviderGridExtension::GridSizeRange = { + 0.001, std::numeric_limits::max(), 1.0 }; namespace PartGui { diff --git a/src/Mod/Part/Gui/ViewProviderReference.cpp b/src/Mod/Part/Gui/ViewProviderReference.cpp index d6f272d076..b679a7d60a 100644 --- a/src/Mod/Part/Gui/ViewProviderReference.cpp +++ b/src/Mod/Part/Gui/ViewProviderReference.cpp @@ -23,9 +23,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -// to avoid compiler warnings of redefining contents of basic.h -// later by #include "ViewProvider.h" -# define _USE_MATH_DEFINES # include # include diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 9a0bfab347..c09aa683d2 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -35,6 +35,8 @@ # include #endif +#include + #include #include #include @@ -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::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); diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index 7b74b486fc..d317b77863 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -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 { diff --git a/src/Mod/PartDesign/App/FeatureExtrude.cpp b/src/Mod/PartDesign/App/FeatureExtrude.cpp index 73659cc6bd..fbe4560184 100644 --- a/src/Mod/PartDesign/App/FeatureExtrude.cpp +++ b/src/Mod/PartDesign/App/FeatureExtrude.cpp @@ -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::max(), std::numeric_limits::max(), 1.0 }; double FeatureExtrude::maxAngle = 90 - Base::toDegrees(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")); diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index 25d60c2778..c44653a76f 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -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::max(), 0.1}; Fillet::Fillet() { diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index 66f27fdcd3..3df6e019eb 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -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 diff --git a/src/Mod/PartDesign/App/FeatureHelix.cpp b/src/Mod/PartDesign/App/FeatureHelix.cpp index 94cfab1c86..7acc3f267b 100644 --- a/src/Mod/PartDesign/App/FeatureHelix.cpp +++ b/src/Mod/PartDesign/App/FeatureHelix.cpp @@ -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::max(), 1.0 }; +const App::PropertyFloatConstraint::Constraints Helix::floatTolerance = { 0.1, std::numeric_limits::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(); diff --git a/src/Mod/PartDesign/App/FeatureHole.cpp b/src/Mod/PartDesign/App/FeatureHole.cpp index 18dbb723ec..d3fc78e2f9 100644 --- a/src/Mod/PartDesign/App/FeatureHole.cpp +++ b/src/Mod/PartDesign/App/FeatureHole.cpp @@ -732,7 +732,7 @@ PROPERTY_SOURCE(PartDesign::Hole, PartDesign::ProfileBased) const App::PropertyAngle::Constraints Hole::floatAngle = { Base::toDegrees(Precision::Angular()), 180.0 - Base::toDegrees(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::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); diff --git a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp index 58455b4624..9d01fc33ab 100644 --- a/src/Mod/PartDesign/App/FeatureLinearPattern.cpp +++ b/src/Mod/PartDesign/App/FeatureLinearPattern.cpp @@ -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::max(), 1 }; const char* LinearPattern::ModeEnums[] = { "length", "offset", nullptr }; diff --git a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp index 0647a3ee17..7272147711 100644 --- a/src/Mod/PartDesign/App/FeaturePolarPattern.cpp +++ b/src/Mod/PartDesign/App/FeaturePolarPattern.cpp @@ -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::max(), 1 }; const App::PropertyAngle::Constraints PolarPattern::floatAngle = { Base::toDegrees(Precision::Angular()), 360.0, 1.0 }; const char* PolarPattern::ModeEnums[] = {"angle", "offset", nullptr}; diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index 21cc034d8d..72e772765a 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -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::max(), 0.1 }; +const App::PropertyQuantityConstraint::Constraints quantityRangeZero = { 0.0, std::numeric_limits::max(), 0.1 }; PROPERTY_SOURCE_WITH_EXTENSIONS(PartDesign::FeaturePrimitive, PartDesign::FeatureAddSub) diff --git a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp index 539ed47128..a6d37a9362 100644 --- a/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPrimitiveParameters.cpp @@ -222,26 +222,26 @@ TaskBoxPrimitives::TaskBoxPrimitives(ViewProviderPrimitive* vp, QWidget* parent) ui->wedgeZ2max->bind(getObject()->Z2max); ui->wedgeZ2min->setValue(getObject()->Z2min.getValue()); ui->wedgeZ2min->bind(getObject()->Z2min); - ui->wedgeXmin->setMinimum(INT_MIN); + ui->wedgeXmin->setMinimum(std::numeric_limits::min()); ui->wedgeXmin->setMaximum(ui->wedgeXmax->rawValue()); // must be < than wedgeXmax - ui->wedgeYmin->setMinimum(INT_MIN); + ui->wedgeYmin->setMinimum(std::numeric_limits::min()); ui->wedgeYmin->setMaximum(ui->wedgeYmax->rawValue()); // must be < than wedgeYmax - ui->wedgeZmin->setMinimum(INT_MIN); + ui->wedgeZmin->setMinimum(std::numeric_limits::min()); ui->wedgeZmin->setMaximum(ui->wedgeZmax->rawValue()); // must be < than wedgeZmax - ui->wedgeX2min->setMinimum(INT_MIN); + ui->wedgeX2min->setMinimum(std::numeric_limits::min());; ui->wedgeX2min->setMaximum(ui->wedgeX2max->rawValue()); // must be <= than wedgeXmax - ui->wedgeZ2min->setMinimum(INT_MIN); + ui->wedgeZ2min->setMinimum(std::numeric_limits::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::max()); ui->wedgeYmax->setMinimum(ui->wedgeYmin->rawValue()); - ui->wedgeYmax->setMaximum(INT_MAX); + ui->wedgeYmax->setMaximum(std::numeric_limits::max()); ui->wedgeZmax->setMinimum(ui->wedgeZmin->rawValue()); - ui->wedgeZmax->setMaximum(INT_MAX); + ui->wedgeZmax->setMaximum(std::numeric_limits::max()); ui->wedgeX2max->setMinimum(ui->wedgeX2min->rawValue()); - ui->wedgeX2max->setMaximum(INT_MAX); + ui->wedgeX2max->setMaximum(std::numeric_limits::max()); ui->wedgeZ2max->setMinimum(ui->wedgeZ2min->rawValue()); - ui->wedgeZ2max->setMaximum(INT_MAX); + ui->wedgeZ2max->setMaximum(std::numeric_limits::max()); break; } diff --git a/src/Mod/PartDesign/Gui/TaskScaledParameters.cpp b/src/Mod/PartDesign/Gui/TaskScaledParameters.cpp index c6b30c4b75..ffb399a6ed 100644 --- a/src/Mod/PartDesign/Gui/TaskScaledParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskScaledParameters.cpp @@ -78,7 +78,7 @@ void TaskScaledParameters::setupParameterUI(QWidget* widget) auto pcScaled = getObject(); ui->spinFactor->bind(pcScaled->Factor); - ui->spinOccurrences->setMaximum(INT_MAX); + ui->spinOccurrences->setMaximum(std::numeric_limits::max()); ui->spinOccurrences->bind(pcScaled->Occurrences); ui->spinFactor->setEnabled(true); ui->spinOccurrences->setEnabled(true); diff --git a/src/Mod/PartDesign/Gui/Utils.cpp b/src/Mod/PartDesign/Gui/Utils.cpp index 3976f848cf..09346de5d7 100644 --- a/src/Mod/PartDesign/Gui/Utils.cpp +++ b/src/Mod/PartDesign/Gui/Utils.cpp @@ -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"); diff --git a/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp b/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp index 8f44733ad8..66ad7b123d 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderAddSub.cpp @@ -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 diff --git a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp index 2961cc4a4e..6c7f7f77c3 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderDatumCS.cpp @@ -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::max(), 0.2}; +const App::PropertyIntegerConstraint::Constraints FontConstraint = { + 1,std::numeric_limits::max(), 1}; ViewProviderDatumCoordinateSystem::ViewProviderDatumCoordinateSystem() { diff --git a/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp b/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp index cca6ab97d7..b3edfa0efe 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderTransformed.cpp @@ -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 diff --git a/src/Mod/Points/App/PointsGrid.cpp b/src/Mod/Points/App/PointsGrid.cpp index 162b7cbc21..6b43641d5a 100644 --- a/src/Mod/Points/App/PointsGrid.cpp +++ b/src/Mod/Points/App/PointsGrid.cpp @@ -808,7 +808,7 @@ bool PointsGridIterator::InitOnRay(const Base::Vector3d& rclPt, // needed in NextOnRay() to avoid an infinite loop _cSearchPositions.clear(); - _fMaxSearchArea = FLOAT_MAX; + _fMaxSearchArea = std::numeric_limits::max(); raulElements.clear(); diff --git a/src/Mod/Points/App/PointsGrid.h b/src/Mod/Points/App/PointsGrid.h index 6965751178..52a6fc248a 100644 --- a/src/Mod/Points/App/PointsGrid.h +++ b/src/Mod/Points/App/PointsGrid.h @@ -293,7 +293,7 @@ private: Base::Vector3d _clPt; /**< Base point of search ray. */ Base::Vector3d _clDir; /**< Direction of search ray. */ bool _bValidRay {false}; /**< Search ray ok? */ - float _fMaxSearchArea {FLOAT_MAX}; + float _fMaxSearchArea {std::numeric_limits::max()}; /** Checks if a grid position is already visited by NextOnRay(). */ struct GridElement { diff --git a/src/Mod/ReverseEngineering/App/RegionGrowing.cpp b/src/Mod/ReverseEngineering/App/RegionGrowing.cpp index 1bdcd2cd83..68ce1df37f 100644 --- a/src/Mod/ReverseEngineering/App/RegionGrowing.cpp +++ b/src/Mod/ReverseEngineering/App/RegionGrowing.cpp @@ -88,7 +88,7 @@ void RegionGrowing::perform(int ksearch) reg.setInputCloud(cloud); // reg.setIndices (indices); reg.setInputNormals(normals); - reg.setSmoothnessThreshold(3.0 / 180.0 * M_PI); + reg.setSmoothnessThreshold(3.0 / 180.0 * std::numbers::pi); reg.setCurvatureThreshold(1.0); std::vector clusters; @@ -142,7 +142,7 @@ void RegionGrowing::perform(const std::vector& myNormals) reg.setInputCloud(cloud); // reg.setIndices (indices); reg.setInputNormals(normals); - reg.setSmoothnessThreshold(3.0 / 180.0 * M_PI); + reg.setSmoothnessThreshold(3.0 / 180.0 * std::numbers::pi); reg.setCurvatureThreshold(1.0); std::vector clusters; diff --git a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp index 7da03c93a7..a718e20d6d 100644 --- a/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp +++ b/src/Mod/ReverseEngineering/App/SurfaceTriangulation.cpp @@ -114,9 +114,9 @@ void SurfaceTriangulation::perform(int ksearch) gp3.setSearchRadius(searchRadius); gp3.setMu(mu); gp3.setMaximumNearestNeighbors(100); - gp3.setMaximumSurfaceAngle(M_PI / 4); // 45 degrees - gp3.setMinimumAngle(M_PI / 18); // 10 degrees - gp3.setMaximumAngle(2 * M_PI / 3); // 120 degrees + gp3.setMaximumSurfaceAngle(std::numbers::pi / 4); // 45 degrees + gp3.setMinimumAngle(std::numbers::pi / 18); // 10 degrees + gp3.setMaximumAngle(2 * std::numbers::pi / 3); // 120 degrees gp3.setNormalConsistency(false); gp3.setConsistentVertexOrdering(true); @@ -171,9 +171,9 @@ void SurfaceTriangulation::perform(const std::vector& normals) gp3.setSearchRadius(searchRadius); gp3.setMu(mu); gp3.setMaximumNearestNeighbors(100); - gp3.setMaximumSurfaceAngle(M_PI / 4); // 45 degrees - gp3.setMinimumAngle(M_PI / 18); // 10 degrees - gp3.setMaximumAngle(2 * M_PI / 3); // 120 degrees + gp3.setMaximumSurfaceAngle(std::numbers::pi / 4); // 45 degrees + gp3.setMinimumAngle(std::numbers::pi / 18); // 10 degrees + gp3.setMaximumAngle(2 * std::numbers::pi / 3); // 120 degrees gp3.setNormalConsistency(true); gp3.setConsistentVertexOrdering(true); diff --git a/src/Mod/ReverseEngineering/Gui/Command.cpp b/src/Mod/ReverseEngineering/Gui/Command.cpp index aac035434c..2b184c39fa 100644 --- a/src/Mod/ReverseEngineering/Gui/Command.cpp +++ b/src/Mod/ReverseEngineering/Gui/Command.cpp @@ -272,7 +272,7 @@ void CmdApproxCylinder::activated(int) fit.SetInitialValues(base, axis); } - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base, top; fit.GetBounding(base, top); float height = Base::Distance(base, top); @@ -329,7 +329,7 @@ void CmdApproxSphere::activated(int) const MeshCore::MeshKernel& kernel = mesh.getKernel(); MeshCore::SphereFit fit; fit.AddPoints(kernel.GetPoints()); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetCenter(); std::stringstream str; @@ -378,7 +378,7 @@ void CmdApproxPolynomial::activated(int) const MeshCore::MeshKernel& kernel = mesh.getKernel(); MeshCore::SurfaceFit fit; fit.AddPoints(kernel.GetPoints()); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::BoundBox3f bbox = fit.GetBoundings(); std::vector poles = fit.toBezier(bbox.MinX, bbox.MaxX, bbox.MinY, bbox.MaxY); diff --git a/src/Mod/ReverseEngineering/Gui/FitBSplineSurface.cpp b/src/Mod/ReverseEngineering/Gui/FitBSplineSurface.cpp index d109879661..de9da74cec 100644 --- a/src/Mod/ReverseEngineering/Gui/FitBSplineSurface.cpp +++ b/src/Mod/ReverseEngineering/Gui/FitBSplineSurface.cpp @@ -122,7 +122,7 @@ void FitBSplineSurfaceWidget::onMakePlacementClicked() }); MeshCore::PlaneFit fit; fit.AddPoints(data); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetBase(); Base::Vector3f dirU = fit.GetDirU(); Base::Vector3f norm = fit.GetNormal(); diff --git a/src/Mod/ReverseEngineering/Gui/Segmentation.cpp b/src/Mod/ReverseEngineering/Gui/Segmentation.cpp index 54ab2b9d49..6a47a77e86 100644 --- a/src/Mod/ReverseEngineering/Gui/Segmentation.cpp +++ b/src/Mod/ReverseEngineering/Gui/Segmentation.cpp @@ -59,7 +59,7 @@ Segmentation::Segmentation(Mesh::Feature* mesh, QWidget* parent, Qt::WindowFlags , myMesh(mesh) { ui->setupUi(this); - ui->numPln->setRange(1, INT_MAX); + ui->numPln->setRange(1, std::numeric_limits::max()); ui->numPln->setValue(100); ui->checkBoxSmooth->setChecked(false); @@ -115,7 +115,7 @@ void Segmentation::accept() std::vector indexes = kernel.GetFacetPoints(jt); MeshCore::PlaneFit fit; fit.AddPoints(kernel.GetPoints(indexes)); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetBase(); Base::Vector3f axis = fit.GetNormal(); MeshCore::AbstractSurfaceFit* fitter = diff --git a/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp b/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp index 55b7d376cb..0b0bac5e83 100644 --- a/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp +++ b/src/Mod/ReverseEngineering/Gui/SegmentationManual.cpp @@ -47,7 +47,7 @@ SegmentationManual::SegmentationManual(QWidget* parent, Qt::WindowFlags fl) { ui->setupUi(this); setupConnections(); - ui->spSelectComp->setRange(1, INT_MAX); + ui->spSelectComp->setRange(1, std::numeric_limits::max()); ui->spSelectComp->setValue(10); Gui::Selection().clearSelection(); @@ -215,7 +215,7 @@ void SegmentationManual::onPlaneDetectClicked() MeshCore::PlaneFit fit; fit.AddPoints(points); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetBase(); Base::Vector3f axis = fit.GetNormal(); return new MeshCore::PlaneSurfaceFit(base, axis); @@ -239,7 +239,7 @@ void SegmentationManual::onCylinderDetectClicked() Base::Vector3f axis = fit.GetInitialAxisFromNormals(normal); fit.SetInitialValues(base, axis); } - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetBase(); Base::Vector3f axis = fit.GetAxis(); float radius = fit.GetRadius(); @@ -259,7 +259,7 @@ void SegmentationManual::onSphereDetectClicked() MeshCore::SphereFit fit; fit.AddPoints(points); - if (fit.Fit() < FLOAT_MAX) { + if (fit.Fit() < std::numeric_limits::max()) { Base::Vector3f base = fit.GetCenter(); float radius = fit.GetRadius(); return new MeshCore::SphereSurfaceFit(base, radius); diff --git a/src/Mod/Robot/App/kdl_cp/chainiksolverpos_nr_jl.cpp b/src/Mod/Robot/App/kdl_cp/chainiksolverpos_nr_jl.cpp index 1ed3c4d72a..3814a77b79 100644 --- a/src/Mod/Robot/App/kdl_cp/chainiksolverpos_nr_jl.cpp +++ b/src/Mod/Robot/App/kdl_cp/chainiksolverpos_nr_jl.cpp @@ -21,17 +21,10 @@ // License along with this library; if not, write to the Free Software // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#include + #include "chainiksolverpos_nr_jl.hpp" -// FreeCAD change -#ifndef M_PI - #define M_PI 3.14159265358979323846 /* pi */ -#endif - -#ifndef M_PI_2 - #define M_PI_2 1.57079632679489661923 /* pi/2 */ -#endif - namespace KDL { ChainIkSolverPos_NR_JL::ChainIkSolverPos_NR_JL(const Chain& _chain, const JntArray& _q_min, const JntArray& _q_max, ChainFkSolverPos& _fksolver,ChainIkSolverVel& _iksolver, @@ -60,14 +53,14 @@ namespace KDL for(unsigned int j=0; j q_max(j)) //q_out(j) = q_max(j); // FreeCAD change - q_out(j) = q_out(j) - M_PI *2; + q_out(j) = q_out(j) - std::numbers::pi *2; } } diff --git a/src/Mod/Robot/App/kdl_cp/frames.cpp b/src/Mod/Robot/App/kdl_cp/frames.cpp index 67baff97a5..ff24c29f6e 100644 --- a/src/Mod/Robot/App/kdl_cp/frames.cpp +++ b/src/Mod/Robot/App/kdl_cp/frames.cpp @@ -26,9 +26,7 @@ ***************************************************************************/ #include "frames.hpp" - -#define _USE_MATH_DEFINES // For MSVC -#include +#include namespace KDL { @@ -244,7 +242,7 @@ void Rotation::GetRPY(double& roll,double& pitch,double& yaw) const { double epsilon=1E-12; pitch = atan2(-data[6], sqrt( sqr(data[0]) +sqr(data[3]) ) ); - if ( fabs(pitch) > (M_PI/2.0-epsilon) ) { + if ( fabs(pitch) > (std::numbers::pi/2.0-epsilon) ) { yaw = atan2( -data[1], data[4]); roll = 0.0 ; } else { @@ -358,7 +356,7 @@ double Rotation::GetRotAngle(Vector& axis,double eps) const { return 0; } if (ca < -1+t) { - // The case of angles consisting of multiples of M_PI: + // The case of angles consisting of multiples of std::numbers::pi: // two solutions, choose a positive Z-component of the axis double x = sqrt( (data[0]+1.0)/2); double y = sqrt( (data[4]+1.0)/2); diff --git a/src/Mod/Robot/App/kdl_cp/path_roundedcomposite.hpp b/src/Mod/Robot/App/kdl_cp/path_roundedcomposite.hpp index 79c2657f57..ddb4bf7cc2 100644 --- a/src/Mod/Robot/App/kdl_cp/path_roundedcomposite.hpp +++ b/src/Mod/Robot/App/kdl_cp/path_roundedcomposite.hpp @@ -96,7 +96,7 @@ class Path_RoundedComposite : public Path * - 3101 if the eq. radius <= 0 * - 3102 if the first segment in a rounding has zero length. * - 3103 if the second segment in a rounding has zero length. - * - 3104 if the angle between the first and the second segment is close to M_PI. + * - 3104 if the angle between the first and the second segment is close to std::numbers::pi. * (meaning that the segments are on top of each other) * - 3105 if the distance needed for the rounding is larger then the first segment. * - 3106 if the distance needed for the rounding is larger then the second segment. diff --git a/src/Mod/Robot/App/kdl_cp/utilities/rall2d.h b/src/Mod/Robot/App/kdl_cp/utilities/rall2d.h index ef90674391..b80c27d13a 100644 --- a/src/Mod/Robot/App/kdl_cp/utilities/rall2d.h +++ b/src/Mod/Robot/App/kdl_cp/utilities/rall2d.h @@ -26,7 +26,7 @@ #ifndef Rall2D_H #define Rall2D_H -#include +#include #include #include "utility.h" diff --git a/src/Mod/Robot/Gui/ViewProviderRobotObject.cpp b/src/Mod/Robot/Gui/ViewProviderRobotObject.cpp index ec3ecd8feb..5b1852c2ba 100644 --- a/src/Mod/Robot/Gui/ViewProviderRobotObject.cpp +++ b/src/Mod/Robot/Gui/ViewProviderRobotObject.cpp @@ -173,6 +173,8 @@ void ViewProviderRobotObject::onChanged(const App::Property* prop) void ViewProviderRobotObject::updateData(const App::Property* prop) { + using std::numbers::pi; + Robot::RobotObject* robObj = static_cast(pcObject); if (prop == &robObj->RobotVrmlFile) { // read also from file @@ -269,33 +271,33 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) } if (Axis1Node) { Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis1.getValue() * (M_PI / 180)); + robObj->Axis1.getValue() * (pi / 180)); } if (Axis2Node) { Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis2.getValue() * (M_PI / 180)); + robObj->Axis2.getValue() * (pi / 180)); } if (Axis3Node) { Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis3.getValue() * (M_PI / 180)); + robObj->Axis3.getValue() * (pi / 180)); } if (Axis4Node) { Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis4.getValue() * (M_PI / 180)); + robObj->Axis4.getValue() * (pi / 180)); } if (Axis5Node) { Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis5.getValue() * (M_PI / 180)); + robObj->Axis5.getValue() * (pi / 180)); } if (Axis6Node) { Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis6.getValue() * (M_PI / 180)); + robObj->Axis6.getValue() * (pi / 180)); } } else if (prop == &robObj->Axis1) { if (Axis1Node) { Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis1.getValue() * (M_PI / 180)); + robObj->Axis1.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -305,7 +307,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) else if (prop == &robObj->Axis2) { if (Axis2Node) { Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis2.getValue() * (M_PI / 180)); + robObj->Axis2.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -315,7 +317,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) else if (prop == &robObj->Axis3) { if (Axis3Node) { Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis3.getValue() * (M_PI / 180)); + robObj->Axis3.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -325,7 +327,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) else if (prop == &robObj->Axis4) { if (Axis4Node) { Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis4.getValue() * (M_PI / 180)); + robObj->Axis4.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -335,7 +337,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) else if (prop == &robObj->Axis5) { if (Axis5Node) { Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis5.getValue() * (M_PI / 180)); + robObj->Axis5.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -345,7 +347,7 @@ void ViewProviderRobotObject::updateData(const App::Property* prop) else if (prop == &robObj->Axis6) { if (Axis6Node) { Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), - robObj->Axis6.getValue() * (M_PI / 180)); + robObj->Axis6.getValue() * (pi / 180)); if (toolShape) { toolShape->setTransformation( (robObj->Tcp.getValue() * (robObj->ToolBase.getValue().inverse())).toMatrix()); @@ -395,27 +397,29 @@ void ViewProviderRobotObject::setAxisTo(float A1, float A6, const Base::Placement& Tcp) { + using std::numbers::pi; + Robot::RobotObject* robObj = static_cast(pcObject); if (Axis1Node) { // FIXME Ugly hack for the wrong transformation of the Kuka 500 robot VRML the minus sign on // Axis 1 - Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A1 * (M_PI / 180)); + Axis1Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A1 * (pi / 180)); } if (Axis2Node) { - Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A2 * (M_PI / 180)); + Axis2Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A2 * (pi / 180)); } if (Axis3Node) { - Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A3 * (M_PI / 180)); + Axis3Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A3 * (pi / 180)); } if (Axis4Node) { - Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A4 * (M_PI / 180)); + Axis4Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A4 * (pi / 180)); } if (Axis5Node) { - Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A5 * (M_PI / 180)); + Axis5Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A5 * (pi / 180)); } if (Axis6Node) { - Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A6 * (M_PI / 180)); + Axis6Node->rotation.setValue(SbVec3f(0.0, 1.0, 0.0), A6 * (pi / 180)); } // update tool position if (toolShape) { diff --git a/src/Mod/Sketcher/App/Sketch.cpp b/src/Mod/Sketcher/App/Sketch.cpp index fef264d601..24d350825d 100644 --- a/src/Mod/Sketcher/App/Sketch.cpp +++ b/src/Mod/Sketcher/App/Sketch.cpp @@ -3060,6 +3060,7 @@ int Sketch::addAngleAtPointConstraint(int geoId1, ConstraintType cTyp, bool driving) { + using std::numbers::pi; if (!(cTyp == Angle || cTyp == Tangent || cTyp == Perpendicular)) { // assert(0);//none of the three types. Why are we here?? return -1; @@ -3132,28 +3133,28 @@ int Sketch::addAngleAtPointConstraint(int geoId1, // the desired angle value (and we are to decide if 180* should be added to it) double angleDesire = 0.0; if (cTyp == Tangent) { - angleOffset = -M_PI / 2; + angleOffset = -pi / 2; angleDesire = 0.0; } if (cTyp == Perpendicular) { angleOffset = 0; - angleDesire = M_PI / 2; + angleDesire = pi / 2; } if (*value == 0.0) { // autodetect tangency internal/external (and same for perpendicularity) double angleErr = GCSsys.calculateAngleViaPoint(*crv1, *crv2, p) - angleDesire; // bring angleErr to -pi..pi - if (angleErr > M_PI) { - angleErr -= M_PI * 2; + if (angleErr > pi) { + angleErr -= pi * 2; } - if (angleErr < -M_PI) { - angleErr += M_PI * 2; + if (angleErr < -pi) { + angleErr += pi * 2; } // the autodetector - if (fabs(angleErr) > M_PI / 2) { - angleDesire += M_PI; + if (fabs(angleErr) > pi / 2) { + angleDesire += pi; } *angle = angleDesire; @@ -4542,7 +4543,7 @@ bool Sketch::updateNonDrivingConstraints() } else if ((*it).constr->Type == Angle) { - (*it).constr->setValue(std::fmod(*((*it).value), 2.0 * M_PI)); + (*it).constr->setValue(std::fmod(*((*it).value), 2.0 * std::numbers::pi)); } else if ((*it).constr->Type == Diameter && (*it).constr->First >= 0) { diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index e2e4751771..81d20781ef 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -591,7 +591,7 @@ void SketchAnalysis::analyseMissingPointOnPointCoincident(double angleprecision) if (fabs(tgv1 * tgv2) > fabs(cos(angleprecision))) { vc.Type = Sketcher::Tangent; } - else if (fabs(tgv1 * tgv2) < fabs(cos(M_PI / 2 - angleprecision))) { + else if (fabs(tgv1 * tgv2) < fabs(cos(std::numbers::pi / 2 - angleprecision))) { vc.Type = Sketcher::Perpendicular; } } @@ -726,7 +726,8 @@ void SketchAnalysis::makeMissingVerticalHorizontalOneByOne() bool SketchAnalysis::checkVertical(Base::Vector3d dir, double angleprecision) { - return (dir.x == 0. && dir.y != 0.) || (fabs(dir.y / dir.x) > tan(M_PI / 2 - angleprecision)); + return (dir.x == 0. && dir.y != 0.) + || (fabs(dir.y / dir.x) > tan(std::numbers::pi / 2 - angleprecision)); } bool SketchAnalysis::checkHorizontal(Base::Vector3d dir, double angleprecision) diff --git a/src/Mod/Sketcher/App/SketchAnalysis.h b/src/Mod/Sketcher/App/SketchAnalysis.h index 4695254d29..dc354b6d80 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.h +++ b/src/Mod/Sketcher/App/SketchAnalysis.h @@ -94,7 +94,7 @@ public: int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); /// Point on Point constraint simple routine Analyse step (see constructor) - void analyseMissingPointOnPointCoincident(double angleprecision = M_PI / 8); + void analyseMissingPointOnPointCoincident(double angleprecision = std::numbers::pi / 8); /// Point on Point constraint simple routine Get step (see constructor) std::vector& getMissingPointOnPointConstraints() { @@ -113,7 +113,7 @@ public: void makeMissingPointOnPointCoincidentOneByOne(); /// Vertical/Horizontal constraints simple routine Detect step (see constructor) - int detectMissingVerticalHorizontalConstraints(double angleprecision = M_PI / 8); + int detectMissingVerticalHorizontalConstraints(double angleprecision = std::numbers::pi / 8); /// Vertical/Horizontal constraints simple routine Get step (see constructor) std::vector& getMissingVerticalHorizontalConstraints() { @@ -168,7 +168,7 @@ public: /// /// It applies coincidents - vertical/horizontal constraints and equality constraints. int autoconstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 8, + double angleprecision = std::numbers::pi / 8, bool includeconstruction = true); // helper functions, which may be used by more complex methods, and/or called directly by user diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index ced32138b6..c456d45f16 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -1144,7 +1144,7 @@ void SketchObject::reverseAngleConstraintToSupplementary(Constraint* constr, int } else { double actAngle = constr->getValue(); - constr->setValue(M_PI - actAngle); + constr->setValue(std::numbers::pi - actAngle); } } @@ -3249,12 +3249,12 @@ int SketchObject::fillet(int GeoId1, int GeoId2, const Base::Vector3d& refPnt1, std::swap(startAngle, endAngle); } - if (endAngle > 2 * M_PI) { - endAngle -= 2 * M_PI; + if (endAngle > 2 * std::numbers::pi) { + endAngle -= 2 * std::numbers::pi; } if (startAngle < 0) { - endAngle += 2 * M_PI; + endAngle += 2 * std::numbers::pi; } // Create Arc Segment @@ -4906,6 +4906,8 @@ std::vector SketchObject::getSymmetric(const std::vector& int refGeoId, Sketcher::PointPos refPosId) { + using std::numbers::pi; + std::vector symmetricVals; bool refIsLine = refPosId == Sketcher::PointPos::none; int cgeoid = getHighestCurveIndex() + 1; @@ -4981,8 +4983,8 @@ std::vector SketchObject::getSymmetric(const std::vector& Base::Vector3d scp = cp + 2.0 * (cp.Perpendicular(refGeoLine->getStartPoint(), vectline) - cp); - double theta1 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * M_PI); - double theta2 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * M_PI); + double theta1 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * std::numbers::pi); + double theta2 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * std::numbers::pi); geoaoc->setCenter(scp); geoaoc->setRange(theta1, theta2, true); @@ -5029,12 +5031,12 @@ std::vector SketchObject::getSymmetric(const std::vector& double theta1, theta2; geosymaoe->getRange(theta1, theta2, true); - theta1 = 2.0 * M_PI - theta1; - theta2 = 2.0 * M_PI - theta2; + theta1 = 2.0 * pi - theta1; + theta2 = 2.0 * pi - theta2; std::swap(theta1, theta2); if (theta1 < 0) { - theta1 += 2.0 * M_PI; - theta2 += 2.0 * M_PI; + theta1 += 2.0 * pi; + theta2 += 2.0 * pi; } geosymaoe->setRange(theta1, theta2, true); @@ -5179,8 +5181,8 @@ std::vector SketchObject::getSymmetric(const std::vector& Base::Vector3d sep = ep + 2.0 * (refpoint - ep); Base::Vector3d scp = cp + 2.0 * (refpoint - cp); - double theta1 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * M_PI); - double theta2 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * M_PI); + double theta1 = Base::fmod(atan2(ssp.y - scp.y, ssp.x - scp.x), 2.f * pi); + double theta2 = Base::fmod(atan2(sep.y - scp.y, sep.x - scp.x), 2.f * pi); geoaoc->setCenter(scp); geoaoc->setRange(theta1, theta2, true); @@ -8569,6 +8571,8 @@ void processEdge(const TopoDS_Edge& edge, gp_Ax3& sketchAx3, TopoDS_Shape& aProjFace) { + using std::numbers::pi; + BRepAdaptor_Curve curve(edge); if (curve.GetType() == GeomAbs_Line) { geos.emplace_back(projectLine(curve, gPlane, invPlm)); @@ -8642,11 +8646,11 @@ void processEdge(const TopoDS_Edge& edge, int tours = 0; double startAngle = baseAngle + alpha; // bring startAngle back in [-pi/2 , 3pi/2[ - while (startAngle < -M_PI / 2.0 && tours < 10) { - startAngle = baseAngle + ++tours * 2.0 * M_PI + alpha; + while (startAngle < -pi / 2.0 && tours < 10) { + startAngle = baseAngle + ++tours * 2.0 * pi + alpha; } - while (startAngle >= 3.0 * M_PI / 2.0 && tours > -10) { - startAngle = baseAngle + --tours * 2.0 * M_PI + alpha; + while (startAngle >= 3.0 * pi / 2.0 && tours > -10) { + startAngle = baseAngle + --tours * 2.0 * pi + alpha; } // apply same offset to end angle @@ -8662,7 +8666,7 @@ void processEdge(const TopoDS_Edge& edge, // P2 = P2 already defined P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); } - else if (endAngle < M_PI) { + else if (endAngle < pi) { // P2 = P2, already defined P1 = ProjPointOnPlane_XYZ(end, sketchPlane); } @@ -8672,16 +8676,16 @@ void processEdge(const TopoDS_Edge& edge, } } } - else if (startAngle < M_PI) { - if (endAngle < M_PI) { + else if (startAngle < pi) { + if (endAngle < pi) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } - else if (endAngle < 2.0 * M_PI - startAngle) { + else if (endAngle < 2.0 * pi - startAngle) { P2 = ProjPointOnPlane_XYZ(beg, sketchPlane); // P1 = P1, already defined } - else if (endAngle < 2.0 * M_PI) { + else if (endAngle < 2.0 * pi) { P2 = ProjPointOnPlane_XYZ(end, sketchPlane); // P1 = P1, already defined } @@ -8691,15 +8695,15 @@ void processEdge(const TopoDS_Edge& edge, } } else { - if (endAngle < 2 * M_PI) { + if (endAngle < 2 * pi) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } - else if (endAngle < 4 * M_PI - startAngle) { + else if (endAngle < 4 * pi - startAngle) { P1 = ProjPointOnPlane_XYZ(beg, sketchPlane); // P2 = P2, already defined } - else if (endAngle < 3 * M_PI) { + else if (endAngle < 3 * pi) { // P1 = P1, already defined P2 = ProjPointOnPlane_XYZ(end, sketchPlane); } @@ -8819,7 +8823,7 @@ void processEdge(const TopoDS_Edge& edge, gp_Vec2d PB = ProjVecOnPlane_UV(origAxisMinor, sketchPlane); double t_max = 2.0 * PA.Dot(PB) / (PA.SquareMagnitude() - PB.SquareMagnitude()); t_max = 0.5 * atan(t_max);// gives new major axis is most cases, but not all - double t_min = t_max + 0.5 * M_PI; + double t_min = t_max + 0.5 * pi; // ON_max = OM(t_max) gives the point, which projected on the sketch plane, // becomes the apoapse of the projected ellipse. @@ -9314,7 +9318,7 @@ void SketchObject::rebuildExternalGeometry(std::optional extToAdd processEdge(edge, geos, gPlane, invPlm, mov, sketchPlane, invRot, sketchAx3, aProjFace); } - if (fabs(dnormal.Angle(snormal) - M_PI_2) < Precision::Confusion()) { + if (fabs(dnormal.Angle(snormal) - std::numbers::pi/2) < Precision::Confusion()) { // The face is normal to the sketch plane // We don't want to keep the projection of all the edges of the face. // We need a single line that goes from min to max of all the projections. @@ -11311,6 +11315,8 @@ int SketchObject::port_reversedExternalArcs(bool justAnalyze) /// false - fail (this indicates an error, or that a constraint locking isn't supported). bool SketchObject::AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce, bool bLock) { + using std::numbers::pi; + try { // assert ( cstr->Type == Tangent || cstr->Type == Perpendicular); /*tangency type already set. If not bForce - don't touch.*/ @@ -11360,25 +11366,25 @@ bool SketchObject::AutoLockTangencyAndPerpty(Constraint* cstr, bool bForce, bool // the desired angle value (and we are to decide if 180* should be added to it) double angleDesire = 0.0; if (cstr->Type == Tangent) { - angleOffset = -M_PI / 2; + angleOffset = -pi / 2; angleDesire = 0.0; } if (cstr->Type == Perpendicular) { angleOffset = 0; - angleDesire = M_PI / 2; + angleDesire = pi / 2; } double angleErr = calculateAngleViaPoint(geoId1, geoId2, p.x, p.y) - angleDesire; // bring angleErr to -pi..pi - if (angleErr > M_PI) - angleErr -= M_PI * 2; - if (angleErr < -M_PI) - angleErr += M_PI * 2; + if (angleErr > pi) + angleErr -= pi * 2; + if (angleErr < -pi) + angleErr += pi * 2; // the autodetector - if (fabs(angleErr) > M_PI / 2) - angleDesire += M_PI; + if (fabs(angleErr) > pi / 2) + angleDesire += pi; // external tangency. The angle stored is offset by Pi/2 so that a value of 0.0 is // invalid and treated as "undecided". diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 05a484c7be..4d17218403 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -841,13 +841,13 @@ public: public: // Analyser functions int autoConstraint(double precision = Precision::Confusion() * 1000, - double angleprecision = M_PI / 20, + double angleprecision = std::numbers::pi / 20, bool includeconstruction = true); int detectMissingPointOnPointConstraints(double precision = Precision::Confusion() * 1000, bool includeconstruction = true); - void analyseMissingPointOnPointCoincident(double angleprecision = M_PI / 8); - int detectMissingVerticalHorizontalConstraints(double angleprecision = M_PI / 8); + void analyseMissingPointOnPointCoincident(double angleprecision = std::numbers::pi / 8); + int detectMissingVerticalHorizontalConstraints(double angleprecision = std::numbers::pi / 8); int detectMissingEqualityConstraints(double precision); std::vector& getMissingPointOnPointConstraints(); diff --git a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp index eaf4156d1a..28cc485a3f 100644 --- a/src/Mod/Sketcher/App/SketchObjectPyImp.cpp +++ b/src/Mod/Sketcher/App/SketchObjectPyImp.cpp @@ -1918,7 +1918,7 @@ PyObject* SketchObjectPy::insertBSplineKnot(PyObject* args) PyObject* SketchObjectPy::autoconstraint(PyObject* args) { double precision = Precision::Confusion() * 1000; - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; PyObject* includeconstruction = Py_True; @@ -1960,7 +1960,7 @@ PyObject* SketchObjectPy::detectMissingPointOnPointConstraints(PyObject* args) PyObject* SketchObjectPy::detectMissingVerticalHorizontalConstraints(PyObject* args) { - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; if (!PyArg_ParseTuple(args, "|d", &angleprecision)) { return nullptr; @@ -1984,7 +1984,7 @@ PyObject* SketchObjectPy::detectMissingEqualityConstraints(PyObject* args) PyObject* SketchObjectPy::analyseMissingPointOnPointCoincident(PyObject* args) { - double angleprecision = M_PI / 8; + double angleprecision = std::numbers::pi / 8; if (!PyArg_ParseTuple(args, "|d", &angleprecision)) { return nullptr; diff --git a/src/Mod/Sketcher/App/planegcs/Constraints.cpp b/src/Mod/Sketcher/App/planegcs/Constraints.cpp index 539dfd9f95..336d20e3d2 100644 --- a/src/Mod/Sketcher/App/planegcs/Constraints.cpp +++ b/src/Mod/Sketcher/App/planegcs/Constraints.cpp @@ -24,8 +24,8 @@ #pragma warning(disable : 4251) #endif -#define _USE_MATH_DEFINES #include +#include #include #define DEBUG_DERIVS 0 @@ -864,6 +864,8 @@ double ConstraintP2PAngle::grad(double* param) double ConstraintP2PAngle::maxStep(MAP_pD_D& dir, double lim) { + constexpr double pi_18 = std::numbers::pi / 18; + MAP_pD_D::iterator it = dir.find(angle()); if (it != dir.end()) { double step = std::abs(it->second); @@ -1444,6 +1446,8 @@ double ConstraintL2LAngle::grad(double* param) double ConstraintL2LAngle::maxStep(MAP_pD_D& dir, double lim) { + constexpr double pi_18 = std::numbers::pi / 18; + MAP_pD_D::iterator it = dir.find(angle()); if (it != dir.end()) { double step = std::abs(it->second); @@ -3536,10 +3540,10 @@ void ConstraintArcLength::errorgrad(double* err, double* grad, double* param) double startA = *arc.startAngle; // Assume positive angles and CCW arc while (startA < 0.) { - startA += 2. * M_PI; + startA += 2. * std::numbers::pi; } while (endA < startA) { - endA += 2. * M_PI; + endA += 2. * std::numbers::pi; } if (err) { *err = rad * (endA - startA) - *distance(); diff --git a/src/Mod/Sketcher/App/planegcs/GCS.cpp b/src/Mod/Sketcher/App/planegcs/GCS.cpp index f397db6a10..bc63d84608 100644 --- a/src/Mod/Sketcher/App/planegcs/GCS.cpp +++ b/src/Mod/Sketcher/App/planegcs/GCS.cpp @@ -47,10 +47,10 @@ #endif #include -#include #include #include #include +#include #include "GCS.h" #include "qp_eq.h" @@ -1029,6 +1029,8 @@ int System::addConstraintPerpendicularLine2Arc(Point& p1, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PCoincident(p2, a.start, tagId, driving); double dx = *(p2.x) - *(p1.x); double dy = *(p2.y) - *(p1.y); @@ -1046,6 +1048,8 @@ int System::addConstraintPerpendicularArc2Line(Arc& a, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PCoincident(p1, a.end, tagId, driving); double dx = *(p2.x) - *(p1.x); double dy = *(p2.y) - *(p1.y); @@ -1063,8 +1067,10 @@ int System::addConstraintPerpendicularCircle2Arc(Point& center, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PDistance(a.start, center, radius, tagId, driving); - double incrAngle = *(a.startAngle) < *(a.endAngle) ? pi_2 : -pi_2; + double incrAngle = *(a.startAngle) < *(a.endAngle) ? pi / 2 : -pi / 2; double tangAngle = *a.startAngle + incrAngle; double dx = *(a.start.x) - *(center.x); double dy = *(a.start.y) - *(center.y); @@ -1082,8 +1088,10 @@ int System::addConstraintPerpendicularArc2Circle(Arc& a, int tagId, bool driving) { + using std::numbers::pi; + addConstraintP2PDistance(a.end, center, radius, tagId, driving); - double incrAngle = *(a.startAngle) < *(a.endAngle) ? -pi_2 : pi_2; + double incrAngle = *(a.startAngle) < *(a.endAngle) ? -pi / 2 : pi / 2; double tangAngle = *a.endAngle + incrAngle; double dx = *(a.end.x) - *(center.x); double dy = *(a.end.y) - *(center.y); @@ -2270,12 +2278,13 @@ int System::solve_LM(SubSystem* subsys, bool isRedundantsolving) x_new = x + h; h_norm = h.squaredNorm(); + constexpr double epsilon = std::numeric_limits::epsilon(); if (h_norm <= eps1 * eps1 * x.norm()) { // relative change in p is small, stop stop = 3; break; } - else if (h_norm >= (x.norm() + eps1) / (DBL_EPSILON * DBL_EPSILON)) { + else if (h_norm >= (x.norm() + eps1) / (epsilon * epsilon)) { // almost singular stop = 4; break; diff --git a/src/Mod/Sketcher/App/planegcs/Geo.h b/src/Mod/Sketcher/App/planegcs/Geo.h index 4604c55b26..bbfdf39736 100644 --- a/src/Mod/Sketcher/App/planegcs/Geo.h +++ b/src/Mod/Sketcher/App/planegcs/Geo.h @@ -53,9 +53,6 @@ public: }; using VEC_P = std::vector; -static constexpr double pi = boost::math::constants::pi(); -static constexpr double pi_2 = pi / 2.0; -static constexpr double pi_18 = pi / 18.0; /// Class DeriVector2 holds a vector value and its derivative on the /// parameter that the derivatives are being calculated for now. x,y is the diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index d46109ce7f..8ed676bb93 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include @@ -114,10 +113,10 @@ void finishDatumConstraint(Gui::Command* cmd, if (lastConstraintType == Radius || lastConstraintType == Diameter) { labelPosition = hGrp->GetFloat("RadiusDiameterConstraintDisplayBaseAngle", 15.0) - * (M_PI / 180);// Get radius/diameter constraint display angle + * (std::numbers::pi / 180);// Get radius/diameter constraint display angle labelPositionRandomness = hGrp->GetFloat("RadiusDiameterConstraintDisplayAngleRandomness", 0.0) - * (M_PI / 180);// Get randomness + * (std::numbers::pi / 180);// Get randomness // Adds a random value around the base angle, so that possibly overlapping labels get likely // a different position. @@ -320,7 +319,7 @@ bool SketcherGui::calculateAngle(Sketcher::SketchObject* Obj, int& GeoId1, int& } else { // if all points are collinear - double length = DBL_MAX; + double length = std::numeric_limits::max(); for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { double tmp = Base::DistanceP2(p2[j], p1[i]); diff --git a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp index 3b6e6819d0..ee3f9b5381 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherBSpline.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp index 4dc6673d96..0e0158f73e 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherOverlay.cpp @@ -24,7 +24,6 @@ #ifndef _PreComp_ #include #include -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp index 1fbfc714cb..4058d4e827 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherTools.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include @@ -1205,6 +1204,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { if (QApplication::keyboardModifiers() == Qt::ControlModifier) @@ -1218,14 +1219,14 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI / 36)) * M_PI / 36; + angle = round(angle / (pi / 36)) * pi / 36; endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } @@ -1781,6 +1782,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { if (QApplication::keyboardModifiers() == Qt::ControlModifier) @@ -1794,14 +1797,14 @@ public: Base::Vector2d endpoint = onSketchPos; if (snapMode == SnapMode::Snap5Degree) { - angle = round(angle / (M_PI / 36)) * M_PI / 36; + angle = round(angle / (pi / 36)) * pi / 36; endpoint = EditCurve[0] + length * Base::Vector2d(cos(angle), sin(angle)); } if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(endpoint, text); } diff --git a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp index 6fcfdbfdf9..4af8107eb2 100644 --- a/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp +++ b/src/Mod/Sketcher/Gui/CommandSketcherVirtualSpace.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #endif #include diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp index e378625ac1..b6ff76dfd8 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp +++ b/src/Mod/Sketcher/Gui/DrawSketchHandler.cpp @@ -425,6 +425,8 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested const Base::Vector2d& Dir, AutoConstraint::TargetType type) { + using std::numbers::pi; + suggestedConstraints.clear(); SketchObject* obj = sketchgui->getSketchObject(); @@ -550,18 +552,18 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested // Number of Degree of deviation from horizontal or vertical lines const double angleDev = 2; - const double angleDevRad = angleDev * M_PI / 180.; + const double angleDevRad = angleDev * pi / 180.; AutoConstraint constr; constr.Type = Sketcher::None; constr.GeoId = GeoEnum::GeoUndef; constr.PosId = PointPos::none; double angle = std::abs(atan2(Dir.y, Dir.x)); - if (angle < angleDevRad || (M_PI - angle) < angleDevRad) { + if (angle < angleDevRad || (pi - angle) < angleDevRad) { // Suggest horizontal constraint constr.Type = Sketcher::Horizontal; } - else if (std::abs(angle - M_PI_2) < angleDevRad) { + else if (std::abs(angle - pi / 2) < angleDevRad) { // Suggest vertical constraint constr.Type = Sketcher::Vertical; } @@ -665,7 +667,7 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested double angle = atan2(projPnt.y, projPnt.x); while (angle < startAngle) { - angle += 2 * D_PI; // Bring it to range of arc + angle += 2 * pi; // Bring it to range of arc } // if the point is on correct side of arc @@ -714,10 +716,10 @@ int DrawSketchHandler::seekAutoConstraint(std::vector& suggested aoe->getMinorRadius() * ((tmpPos.x - center.x) * majdir.x + (tmpPos.y - center.y) * majdir.y)) - startAngle, - 2.f * M_PI); + 2.f * pi); while (angle < startAngle) { - angle += 2 * D_PI; // Bring it to range of arc + angle += 2 * pi; // Bring it to range of arc } // if the point is on correct side of arc @@ -978,7 +980,7 @@ void DrawSketchHandler::drawDirectionAtCursor(const Base::Vector2d& position, SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / std::numbers::pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(position, text); } @@ -1009,7 +1011,7 @@ void DrawSketchHandler::drawDoubleAtCursor(const Base::Vector2d& position, SbString text; std::string doubleString = unit == Base::Unit::Length ? lengthToDisplayFormat(val, 1) - : angleToDisplayFormat(val * 180.0 / M_PI, 1); + : angleToDisplayFormat(val * 180.0 / std::numbers::pi, 1); text.sprintf(" (%s)", doubleString.c_str()); setPositionText(position, text); } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h index af25729b50..54123fb115 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArc.h @@ -132,7 +132,7 @@ private: if (constructionMethod() == ConstructionMethod::Center) { secondPoint = onSketchPos; double angle1 = (onSketchPos - centerPoint).Angle() - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; if (arcAngle > 0) { @@ -183,7 +183,7 @@ private: } startAngle = std::max(angle1, angle2); endAngle = std::min(angle1, angle2); - arcAngle = 2 * M_PI - (startAngle - endAngle); + arcAngle = 2 * std::numbers::pi - (startAngle - endAngle); } } @@ -562,7 +562,7 @@ void DSHArcControllerBase::doEnforceControlParameters(Base::Vector2d& onSketchPo if (onViewParameters[OnViewParameter::Fifth]->isSet) { double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fifth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fifth].get()); return; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h index 5185010b1c..a4ebaad0f1 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfEllipse.h @@ -68,6 +68,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); seekAndRenderAutoConstraint(sugConstr1, @@ -78,7 +80,7 @@ public: double rx0 = onSketchPos.x - EditCurve[0].x; double ry0 = onSketchPos.y - EditCurve[0].y; for (int i = 0; i < 16; i++) { - double angle = i * M_PI / 16.0; + double angle = i * pi / 16.0; double rx1 = rx0 * cos(angle) + ry0 * sin(angle); double ry1 = -rx0 * sin(angle) + ry0 * cos(angle); EditCurve[1 + i] = Base::Vector2d(EditCurve[0].x + rx1, EditCurve[0].y + ry1); @@ -115,7 +117,7 @@ public: / (sin(angleatpoint) * cos(phi)); for (int i = 1; i < 16; i++) { - double angle = i * M_PI / 16.0; + double angle = i * pi / 16.0; double rx1 = a * cos(angle) * cos(phi) - b * sin(angle) * sin(phi); double ry1 = a * cos(angle) * sin(phi) + b * sin(angle) * cos(phi); EditCurve[1 + i] = Base::Vector2d(EditCurve[0].x + rx1, EditCurve[0].y + ry1); @@ -161,7 +163,7 @@ public: + (onSketchPos.y - centerPoint.y) * sin(phi))) - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; for (int i = 0; i < 34; i++) { @@ -178,7 +180,7 @@ public: SbString text; std::string aString = lengthToDisplayFormat(a, 1); std::string bString = lengthToDisplayFormat(b, 1); - std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / pi, 1); text.sprintf(" (R%s, R%s, %s)", aString.c_str(), bString.c_str(), @@ -222,6 +224,9 @@ public: bool releaseButton(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); + + using std::numbers::pi; + if (Mode == STATUS_Close) { unsetCursor(); resetPositionText(); @@ -245,7 +250,7 @@ public: + (endPoint.y - centerPoint.y) * sin(phi))) - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; bool isOriginalArcCCW = true; @@ -281,8 +286,8 @@ public: perp.Scale(abs(b)); majAxisPoint = centerPoint + perp; minAxisPoint = centerPoint + minAxisDir; - endAngle += M_PI / 2; - startAngle += M_PI / 2; + endAngle += pi / 2; + startAngle += pi / 2; } int currentgeoid = getHighestCurveIndex(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h index 620f1bc0a1..9f96e3f169 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcOfHyperbola.h @@ -103,7 +103,7 @@ public: if (!boost::math::isnan(b)) { for (int i = 15; i >= -15; i--) { // P(U) = O + MajRad*Cosh(U)*XDir + MinRad*Sinh(U)*YDir - // double angle = i*M_PI/16.0; + // double angle = i*std::numbers::pi/16.0; double angle = i * angleatpoint / 15; double rx = a * cosh(angle) * cos(phi) - b * sinh(angle) * sin(phi); double ry = a * cosh(angle) * sin(phi) + b * sinh(angle) * cos(phi); @@ -150,7 +150,7 @@ public: /*double angle1 = angleatpoint - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI ; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi ; arcAngle = abs(angle1-arcAngle) < abs(angle2-arcAngle) ? angle1 : angle2;*/ arcAngle = angleatpoint - startAngle; @@ -290,8 +290,8 @@ public: perp.Scale(abs(b)); majAxisPoint = centerPoint + perp; minAxisPoint = centerPoint + minAxisDir; - endAngle += M_PI / 2; - startAngle += M_PI / 2; + endAngle += std::numbers::pi / 2; + startAngle += std::numbers::pi / 2; } int currentgeoid = getHighestCurveIndex(); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h index 354930156a..cbd996489a 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerArcSlot.h @@ -133,7 +133,7 @@ private: startAngle = startAngleBackup; double angle1 = (onSketchPos - centerPoint).Angle() - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; arcAngle = abs(angle1 - arcAngle) < abs(angle2 - arcAngle) ? angle1 : angle2; reverseIfNecessary(); @@ -305,6 +305,8 @@ private: void createShape(bool onlyeditoutline) override { + using std::numbers::pi; + ShapeGeometry.clear(); if (radius < Precision::Confusion()) { @@ -331,14 +333,14 @@ private: isConstructionMode()); addArcToShapeGeometry(toVector3d(startPoint), - angleReversed ? endAngle : startAngle + M_PI, - angleReversed ? endAngle + M_PI : startAngle + 2 * M_PI, + angleReversed ? endAngle : startAngle + pi, + angleReversed ? endAngle + pi : startAngle + 2 * pi, r, isConstructionMode()); addArcToShapeGeometry(toVector3d(endPoint), - angleReversed ? startAngle + M_PI : endAngle, - angleReversed ? startAngle + 2 * M_PI : M_PI + endAngle, + angleReversed ? startAngle + pi : endAngle, + angleReversed ? startAngle + 2 * pi : pi + endAngle, r, isConstructionMode()); @@ -635,7 +637,7 @@ void DSHArcSlotControllerBase::doEnforceControlParameters(Base::Vector2d& onSket if (onViewParameters[OnViewParameter::Fifth]->isSet) { double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fifth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fifth].get()); } else { diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h index f6561f017d..587db8d527 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerExtend.h @@ -110,6 +110,9 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { Q_UNUSED(onSketchPos); + + using std::numbers::pi; + if (Mode == STATUS_SEEK_Second) { const Part::Geometry* geom = sketchgui->getSketchObject()->getGeometry(BaseGeoId); if (geom->is()) { @@ -142,7 +145,7 @@ public: */ bool inCurve = (projection.Length() < recenteredLine.Length() && projection.GetAngle(recenteredLine) - < 0.1); // Two possible values here, M_PI and 0, but 0.1 is to + < 0.1); // Two possible values here, pi and 0, but 0.1 is to // avoid floating point problems. if (inCurve) { Increment = SavedExtendFromStart @@ -185,8 +188,8 @@ public: bool isCCWFromStart = crossProduct(angle, startAngle) < 0; if (outOfArc) { if (isCCWFromStart) { - modStartAngle -= 2 * M_PI - angleToStartAngle; - modArcAngle += 2 * M_PI - angleToStartAngle; + modStartAngle -= 2 * pi - angleToStartAngle; + modArcAngle += 2 * pi - angleToStartAngle; } else { modStartAngle -= angleToStartAngle; @@ -199,8 +202,8 @@ public: modArcAngle -= angleToStartAngle; } else { - modStartAngle += 2 * M_PI - angleToStartAngle; - modArcAngle -= 2 * M_PI - angleToStartAngle; + modStartAngle += 2 * pi - angleToStartAngle; + modArcAngle -= 2 * pi - angleToStartAngle; } } } @@ -208,7 +211,7 @@ public: bool isCWFromEnd = crossProduct(angle, endAngle) >= 0; if (outOfArc) { if (isCWFromEnd) { - modArcAngle += 2 * M_PI - angleToEndAngle; + modArcAngle += 2 * pi - angleToEndAngle; } else { modArcAngle += angleToEndAngle; @@ -219,7 +222,7 @@ public: modArcAngle -= angleToEndAngle; } else { - modArcAngle -= 2 * M_PI - angleToEndAngle; + modArcAngle -= 2 * pi - angleToEndAngle; } } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h index efbe278b5e..50f7ea7377 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLine.h @@ -646,16 +646,17 @@ void DSHLineController::addConstraints() }; auto constraintp4angle = [&]() { + using std::numbers::pi; + double angle = Base::toRadians(p4); - if (fabs(angle - M_PI) < Precision::Confusion() - || fabs(angle + M_PI) < Precision::Confusion() + if (fabs(angle - pi) < Precision::Confusion() || fabs(angle + pi) < Precision::Confusion() || fabs(angle) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Horizontal',%d)) ", firstCurve); } - else if (fabs(angle - M_PI / 2) < Precision::Confusion() - || fabs(angle + M_PI / 2) < Precision::Confusion()) { + else if (fabs(angle - pi / 2) < Precision::Confusion() + || fabs(angle + pi / 2) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Vertical',%d)) ", firstCurve); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h index 798f9f674b..37b0f6834e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerLineSet.h @@ -188,6 +188,8 @@ public: void mouseMove(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + suppressTransition = false; if (Mode == STATUS_SEEK_First) { setPositionText(onSketchPos); @@ -222,7 +224,7 @@ public: if (showCursorCoords()) { SbString text; std::string lengthString = lengthToDisplayFormat(length, 1); - std::string angleString = angleToDisplayFormat(angle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(angle * 180.0 / pi, 1); text.sprintf(" (%s, %s)", lengthString.c_str(), angleString.c_str()); setPositionText(EditCurve[1], text); } @@ -289,14 +291,14 @@ public: arcAngle = 0.f; } if (arcRadius >= 0 && arcAngle > 0) { - arcAngle -= 2 * M_PI; + arcAngle -= 2 * pi; } if (arcRadius < 0 && arcAngle < 0) { - arcAngle += 2 * M_PI; + arcAngle += 2 * pi; } if (SnapMode == SNAP_MODE_45Degree) { - arcAngle = round(arcAngle / (M_PI / 4)) * M_PI / 4; + arcAngle = round(arcAngle / (pi / 4)) * pi / 4; } endAngle = startAngle + arcAngle; @@ -316,7 +318,7 @@ public: if (showCursorCoords()) { SbString text; std::string radiusString = lengthToDisplayFormat(std::abs(arcRadius), 1); - std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / M_PI, 1); + std::string angleString = angleToDisplayFormat(arcAngle * 180.0 / pi, 1); text.sprintf(" (R%s, %s)", radiusString.c_str(), angleString.c_str()); setPositionText(onSketchPos, text); } @@ -536,8 +538,8 @@ public: // #3974: if in radians, the printf %f defaults to six decimals, which leads to // loss of precision - double arcAngle = - abs(round((endAngle - startAngle) / (M_PI / 4)) * 45); // in degrees + double arcAngle = abs(round((endAngle - startAngle) / (std::numbers::pi / 4)) + * 45); // in degrees Gui::cmdAppObjectArgs(sketchgui->getObject(), "addConstraint(Sketcher.Constraint('Angle',%i,App.Units." diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h index 0bf9697039..509d347027 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h @@ -932,7 +932,7 @@ private: void findOffsetLength() { - double newOffsetLength = DBL_MAX; + double newOffsetLength = std::numeric_limits::max(); BRepBuilderAPI_MakeVertex mkVertex({endpoint.x, endpoint.y, 0.0}); TopoDS_Vertex vertex = mkVertex.Vertex(); @@ -960,7 +960,7 @@ private: } } - if (newOffsetLength != DBL_MAX) { + if (newOffsetLength != std::numeric_limits::max()) { offsetLength = newOffsetLength; } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h index 0a6a242da7..54ce11d364 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerPolygon.h @@ -242,7 +242,8 @@ private: return; } - double angleOfSeparation = 2.0 * M_PI / static_cast(numberOfCorners); // NOLINT + double angleOfSeparation = + 2.0 * std::numbers::pi / static_cast(numberOfCorners); // NOLINT double cos_v = cos(angleOfSeparation); double sin_v = sin(angleOfSeparation); diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h index 8070c64436..f3ba68f73f 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRectangle.h @@ -111,6 +111,8 @@ public: private: void updateDataAndDrawToPosition(Base::Vector2d onSketchPos) override { + using std::numbers::pi; + switch (state()) { case SelectMode::SeekFirst: { toolWidgetManager.drawPositionAtCursor(onSketchPos); @@ -144,8 +146,8 @@ private: corner2 = Base::Vector2d(corner1.x, onSketchPos.y); cornersReversed = true; } - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; } else if (constructionMethod() == ConstructionMethod::CenterAndCorner) { toolWidgetManager.drawDirectionAtCursor(onSketchPos, center); @@ -162,8 +164,8 @@ private: corner2 = Base::Vector2d(corner1.x, onSketchPos.y); cornersReversed = true; } - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; } else if (constructionMethod() == ConstructionMethod::ThreePoints) { toolWidgetManager.drawDirectionAtCursor(onSketchPos, corner1); @@ -174,8 +176,8 @@ private: perpendicular.y = (corner2 - corner1).x; corner3 = corner2 + perpendicular; corner4 = corner1 + perpendicular; - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; corner2Initial = corner2; side = getPointSideOfVector(corner3, corner2 - corner1, corner1); } @@ -189,8 +191,8 @@ private: perpendicular.y = (onSketchPos - center).x; corner2 = center + perpendicular; corner4 = center - perpendicular; - angle123 = M_PI / 2; - angle412 = M_PI / 2; + angle123 = pi / 2; + angle412 = pi / 2; side = getPointSideOfVector(corner2, corner3 - corner1, corner1); } @@ -247,7 +249,7 @@ private: acos((a.x * b.x + a.y * b.y) / (sqrt(a.x * a.x + a.y * a.y) * sqrt(b.x * b.x + b.y * b.y))); } - angle412 = M_PI - angle123; + angle412 = pi - angle123; if (roundCorners) { radius = std::min(length, width) / 6 // NOLINT * std::min(sqrt(1 - cos(angle412) * cos(angle412)), @@ -276,7 +278,7 @@ private: acos((a.x * b.x + a.y * b.y) / (sqrt(a.x * a.x + a.y * a.y) * sqrt(b.x * b.x + b.y * b.y))); } - angle123 = M_PI - angle412; + angle123 = pi - angle412; if (roundCorners) { radius = std::min(length, width) / 6 // NOLINT * std::min(sqrt(1 - cos(angle412) * cos(angle412)), @@ -677,7 +679,7 @@ private: width = vecW.Length(); angle = vecL.Angle(); if (length < Precision::Confusion() || width < Precision::Confusion() - || fmod(fabs(angle123), M_PI) < Precision::Confusion()) { + || fmod(fabs(angle123), std::numbers::pi) < Precision::Confusion()) { return; } @@ -738,9 +740,11 @@ private: void createFirstRectangleFillets(Base::Vector2d vecL, Base::Vector2d vecW, double L1, double L2) { + using std::numbers::pi; + // center points required later for special case of round corner frame with // radiusFrame = 0. - double end = angle - M_PI / 2; + double end = angle - pi / 2; Base::Vector2d b1 = (vecL + vecW) / (vecL + vecW).Length(); Base::Vector2d b2 = (vecL - vecW) / (vecL - vecW).Length(); @@ -749,16 +753,18 @@ private: center3 = toVector3d(corner3 - b1 * L2); center4 = toVector3d(corner4 + b2 * L1); - addArcToShapeGeometry(center1, end - M_PI + angle412, end, radius, isConstructionMode()); - addArcToShapeGeometry(center2, end, end - M_PI - angle123, radius, isConstructionMode()); - addArcToShapeGeometry(center3, end + angle412, end - M_PI, radius, isConstructionMode()); - addArcToShapeGeometry(center4, end - M_PI, end - angle123, radius, isConstructionMode()); + addArcToShapeGeometry(center1, end - pi + angle412, end, radius, isConstructionMode()); + addArcToShapeGeometry(center2, end, end - pi - angle123, radius, isConstructionMode()); + addArcToShapeGeometry(center3, end + angle412, end - pi, radius, isConstructionMode()); + addArcToShapeGeometry(center4, end - pi, end - angle123, radius, isConstructionMode()); } void createSecondRectangleGeometries(Base::Vector2d vecL, Base::Vector2d vecW, double L1, double L2) { - double end = angle - M_PI / 2; + using std::numbers::pi; + + double end = angle - pi / 2; if (radius < Precision::Confusion()) { radiusFrame = 0.; @@ -800,22 +806,22 @@ private: Base::Vector2d b2 = (vecL - vecW) / (vecL - vecW).Length(); addArcToShapeGeometry(toVector3d(frameCorner1 + b1 * L2F), - end - M_PI + angle412, + end - pi + angle412, end, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner2 - b2 * L1F), end, - end - M_PI - angle123, + end - pi - angle123, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner3 - b1 * L2F), end + angle412, - end - M_PI, + end - pi, radiusFrame, isConstructionMode()); addArcToShapeGeometry(toVector3d(frameCorner4 + b2 * L1F), - end - M_PI, + end - pi, end - angle123, radiusFrame, isConstructionMode()); @@ -1313,7 +1319,7 @@ private: firstCurve + 1, Sketcher::PointPos::none, firstCurve + 3); - if (fabs(angle123 - M_PI / 2) < Precision::Confusion()) { + if (fabs(angle123 - std::numbers::pi / 2) < Precision::Confusion()) { addToShapeConstraints(Sketcher::Perpendicular, firstCurve, Sketcher::PointPos::none, @@ -1932,7 +1938,7 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (onViewParameters[OnViewParameter::Sixth]->isSet) { double angle = Base::toRadians(onViewParameters[OnViewParameter::Sixth]->getValue()); - if (fmod(angle, M_PI) < Precision::Confusion()) { + if (fmod(angle, std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Sixth].get()); return; } @@ -1944,8 +1950,8 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk int sign = handler->side != sign1 ? 1 : -1; - double angle123 = - (handler->corner2Initial - handler->corner1).Angle() + M_PI + sign * angle; + double angle123 = (handler->corner2Initial - handler->corner1).Angle() + + std::numbers::pi + sign * angle; onSketchPos.x = handler->corner2Initial.x + cos(angle123) * width; onSketchPos.y = handler->corner2Initial.y + sin(angle123) * width; @@ -1969,12 +1975,12 @@ void DSHRectangleControllerBase::doEnforceControlParameters(Base::Vector2d& onSk if (onViewParameters[OnViewParameter::Sixth]->isSet) { double c = Base::toRadians(onViewParameters[OnViewParameter::Sixth]->getValue()); - if (fmod(c, M_PI) < Precision::Confusion()) { + if (fmod(c, std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Sixth].get()); return; } - double a = asin(width * sin(M_PI - c) + double a = asin(width * sin(std::numbers::pi - c) / (handler->corner3 - handler->corner1).Length()); int sign1 = handler->getPointSideOfVector(onSketchPos, @@ -2399,6 +2405,8 @@ void DSHRectangleController::doChangeDrawSketchHandlerMode() template<> void DSHRectangleController::addConstraints() { + using std::numbers::pi; + App::DocumentObject* obj = handler->sketchgui->getObject(); int firstCurve = handler->firstCurve; @@ -2569,15 +2577,15 @@ void DSHRectangleController::addConstraints() if (handler->constructionMethod() == ConstructionMethod::ThreePoints) { if (angleSet) { - if (fabs(angle - M_PI) < Precision::Confusion() - || fabs(angle + M_PI) < Precision::Confusion() + if (fabs(angle - pi) < Precision::Confusion() + || fabs(angle + pi) < Precision::Confusion() || fabs(angle) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Horizontal',%d)) ", firstCurve); } - else if (fabs(angle - M_PI / 2) < Precision::Confusion() - || fabs(angle + M_PI / 2) < Precision::Confusion()) { + else if (fabs(angle - pi / 2) < Precision::Confusion() + || fabs(angle + pi / 2) < Precision::Confusion()) { Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Vertical',%d)) ", firstCurve); @@ -2591,7 +2599,7 @@ void DSHRectangleController::addConstraints() } } if (innerAngleSet) { - if (fabs(innerAngle - M_PI / 2) > Precision::Confusion()) { + if (fabs(innerAngle - pi / 2) > Precision::Confusion()) { // if 90? then perpendicular already created. Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", @@ -2617,7 +2625,7 @@ void DSHRectangleController::addConstraints() obj); } if (innerAngleSet) { - if (fabs(innerAngle - M_PI / 2) > Precision::Confusion()) { + if (fabs(innerAngle - pi / 2) > Precision::Confusion()) { // if 90? then perpendicular already created. Gui::cmdAppObjectArgs(obj, "addConstraint(Sketcher.Constraint('Angle',%d,%d,%d,%d,%f)) ", diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h index 32266e9d38..03be54ee61 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerRotate.h @@ -103,7 +103,7 @@ private: endpoint = centerPoint + length * Base::Vector2d(cos(endAngle), sin(endAngle)); double angle1 = endAngle - startAngle; - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; totalAngle = abs(angle1 - totalAngle) < abs(angle2 - totalAngle) ? angle1 : angle2; CreateAndDrawShapeGeometry(); @@ -408,10 +408,11 @@ private: // the new geometry. /*if (cstr->Type == DistanceX || cstr->Type == DistanceY) { //DistanceX/Y can be applied only if the rotation if 90 or 180. - if (fabs(fmod(individualAngle, M_PI)) < Precision::Confusion()) { + if (fabs(fmod(individualAngle, std::numbers::pi)) < + Precision::Confusion()) { // ok and nothing to do actually } - else if (fabs(fmod(individualAngle, M_PI * 0.5)) < + else if (fabs(fmod(individualAngle, std::numbers::pi * 0.5)) < Precision::Confusion()) { cstr->Type = cstr->Type == DistanceX ? DistanceY : DistanceX; } @@ -567,7 +568,7 @@ void DSHRotateControllerBase::doEnforceControlParameters(Base::Vector2d& onSketc double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Third]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Third].get()); return; } @@ -580,7 +581,7 @@ void DSHRotateControllerBase::doEnforceControlParameters(Base::Vector2d& onSketc double arcAngle = Base::toRadians(onViewParameters[OnViewParameter::Fourth]->getValue()); - if (fmod(fabs(arcAngle), 2 * M_PI) < Precision::Confusion()) { + if (fmod(fabs(arcAngle), 2 * std::numbers::pi) < Precision::Confusion()) { unsetOnViewParameter(onViewParameters[OnViewParameter::Fourth].get()); return; } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h index 1108aa244e..46b27d58b3 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerSlot.h @@ -241,6 +241,8 @@ private: void createShape(bool onlyeditoutline) override { + using std::numbers::pi; + ShapeGeometry.clear(); if (length < Precision::Confusion() || radius < Precision::Confusion()) { @@ -248,14 +250,14 @@ private: } Part::GeomArcOfCircle* arc1 = addArcToShapeGeometry(toVector3d(startPoint), - M_PI / 2 + angle, - 1.5 * M_PI + angle, + pi / 2 + angle, + 1.5 * pi + angle, radius, isConstructionMode()); Part::GeomArcOfCircle* arc2 = addArcToShapeGeometry(toVector3d(secondPoint), - 1.5 * M_PI + angle, - M_PI / 2 + angle, + 1.5 * pi + angle, + pi / 2 + angle, radius, isConstructionMode()); @@ -323,13 +325,15 @@ private: void checkHorizontalVertical() { + using std::numbers::pi; + isHorizontal = false; isVertical = false; - if (fmod(fabs(angle), M_PI) < Precision::Confusion()) { + if (fmod(fabs(angle), pi) < Precision::Confusion()) { isHorizontal = true; } - else if (fmod(fabs(angle + M_PI / 2), M_PI) < Precision::Confusion()) { + else if (fmod(fabs(angle + pi / 2), pi) < Precision::Confusion()) { isVertical = true; } } diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h index bac2d51208..f1412f8d7c 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerTranslate.h @@ -584,7 +584,8 @@ void DSHTranslateControllerBase::doEnforceControlParameters(Base::Vector2d& onSk } if (onViewParameters[OnViewParameter::Fourth]->isSet) { - double angle = onViewParameters[OnViewParameter::Fourth]->getValue() * M_PI / 180; + double angle = + onViewParameters[OnViewParameter::Fourth]->getValue() * std::numbers::pi / 180; onSketchPos.x = handler->referencePoint.x + cos(angle) * length; onSketchPos.y = handler->referencePoint.y + sin(angle) * length; } @@ -607,7 +608,8 @@ void DSHTranslateControllerBase::doEnforceControlParameters(Base::Vector2d& onSk } if (onViewParameters[OnViewParameter::Sixth]->isSet) { - double angle = onViewParameters[OnViewParameter::Sixth]->getValue() * M_PI / 180; + double angle = + onViewParameters[OnViewParameter::Sixth]->getValue() * std::numbers::pi / 180; onSketchPos.x = handler->referencePoint.x + cos(angle) * length; onSketchPos.y = handler->referencePoint.y + sin(angle) * length; } @@ -647,7 +649,7 @@ void DSHTranslateController::adaptParameters(Base::Vector2d onSketchPos) Base::Vector2d vec2d = Base::Vector2d(handler->firstTranslationVector.x, handler->firstTranslationVector.y); double angle = vec2d.Angle(); - double range = angle * 180 / M_PI; + double range = angle * 180 / std::numbers::pi; if (!onViewParameters[OnViewParameter::Fourth]->isSet) { setOnViewParameterValue(OnViewParameter::Fourth, range, Base::Unit::Angle); @@ -669,7 +671,7 @@ void DSHTranslateController::adaptParameters(Base::Vector2d onSketchPos) Base::Vector2d vec2d = Base::Vector2d(handler->secondTranslationVector.x, handler->secondTranslationVector.y); double angle = vec2d.Angle(); - double range = angle * 180 / M_PI; + double range = angle * 180 / std::numbers::pi; if (!onViewParameters[OnViewParameter::Sixth]->isSet) { setOnViewParameterValue(OnViewParameter::Sixth, range, Base::Unit::Angle); diff --git a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp index e368a8d7de..f69d71d71e 100644 --- a/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp +++ b/src/Mod/Sketcher/Gui/EditModeConstraintCoinManager.cpp @@ -114,6 +114,8 @@ void EditModeConstraintCoinManager::updateVirtualSpace() void EditModeConstraintCoinManager::processConstraints(const GeoListFacade& geolistfacade) { + using std::numbers::pi; + const auto& constrlist = ViewProviderSketchCoinAttorney::getConstraints(viewProvider); auto zConstrH = ViewProviderSketchCoinAttorney::getViewOrientationFactor(viewProvider) @@ -262,7 +264,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo); ra = circle->getRadius(); - angle = M_PI / 4; + angle = pi / 4; midpos = circle->getCenter(); } else if (geo->is()) { @@ -281,7 +283,7 @@ Restart: rb = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle = atan2(majdir.y, majdir.x); - angleplus = M_PI / 4; + angleplus = pi / 4; midpos = ellipse->getCenter(); } else if (geo->is()) { @@ -460,7 +462,7 @@ Restart: norm1.Normalize(); dir1 = norm1; - dir1.RotateZ(-M_PI / 2.0); + dir1.RotateZ(-pi / 2.0); } else if (Constr->FirstPos == Sketcher::PointPos::none) { @@ -485,7 +487,7 @@ Restart: else if (geo1->is()) { const Part::GeomCircle* circle = static_cast(geo1); - norm1 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0); + norm1 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0); dir1 = Base::Vector3d(-norm1.y, norm1.x, 0); midpos1 = circle->getCenter() + circle->getRadius() * norm1; } @@ -514,7 +516,7 @@ Restart: else if (geo2->is()) { const Part::GeomCircle* circle = static_cast(geo2); - norm2 = Base::Vector3d(cos(M_PI / 4), sin(M_PI / 4), 0); + norm2 = Base::Vector3d(cos(pi / 4), sin(pi / 4), 0); dir2 = Base::Vector3d(-norm2.y, norm2.x, 0); midpos2 = circle->getCenter() + circle->getRadius() * norm2; } @@ -576,7 +578,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo1); r1a = circle->getRadius(); - angle1 = M_PI / 4; + angle1 = pi / 4; midpos1 = circle->getCenter(); } else if (geo1->is()) { @@ -595,7 +597,7 @@ Restart: r1b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle1 = atan2(majdir.y, majdir.x); - angle1plus = M_PI / 4; + angle1plus = pi / 4; midpos1 = ellipse->getCenter(); } else if (geo1->is()) { @@ -641,7 +643,7 @@ Restart: const Part::GeomCircle* circle = static_cast(geo2); r2a = circle->getRadius(); - angle2 = M_PI / 4; + angle2 = pi / 4; midpos2 = circle->getCenter(); } else if (geo2->is()) { @@ -660,7 +662,7 @@ Restart: r2b = ellipse->getMinorRadius(); Base::Vector3d majdir = ellipse->getMajorAxisDir(); angle2 = atan2(majdir.y, majdir.x); - angle2plus = M_PI / 4; + angle2plus = pi / 4; midpos2 = ellipse->getCenter(); } else if (geo2->is()) { @@ -968,7 +970,7 @@ Restart: // otherwise We still use findHelperAngles before to find if helper // is needed. helperStartAngle1 = endAngle; - helperRange1 = 2 * M_PI - (endAngle - startAngle); + helperRange1 = 2 * pi - (endAngle - startAngle); numPoints++; } @@ -991,7 +993,7 @@ Restart: if (helperRange2 != 0.) { helperStartAngle2 = endAngle; - helperRange2 = 2 * M_PI - (endAngle - startAngle); + helperRange2 = 2 * pi - (endAngle - startAngle); numPoints++; } @@ -1089,7 +1091,7 @@ Restart: // getSolvedSketch().calculateNormalAtPoint(Constr->Second, pos.x, pos.y); norm.Normalize(); Base::Vector3d dir = norm; - dir.RotateZ(-M_PI / 2.0); + dir.RotateZ(-pi / 2.0); relPos = seekConstraintPosition( pos, @@ -1340,7 +1342,7 @@ Restart: p1[1] = line1->getEndPoint(); p2[0] = line2->getStartPoint(); p2[1] = line2->getEndPoint(); - double length = DBL_MAX; + double length = std::numeric_limits::max(); for (int i = 0; i <= 1; i++) { for (int j = 0; j <= 1; j++) { double tmp = (p2[j] - p1[i]).Length(); @@ -1385,12 +1387,12 @@ Restart: // TODO: Check // dir1 = getSolvedSketch().calculateNormalAtPoint(Constr->First, // p.x, p.y); - dir1.RotateZ(-M_PI / 2); // convert to vector of tangency by rotating + dir1.RotateZ(-pi / 2); // convert to vector of tangency by rotating dir2 = getNormal(geolistfacade, Constr->Second, p); // TODO: Check // dir2 = getSolvedSketch().calculateNormalAtPoint(Constr->Second, // p.x, p.y); - dir2.RotateZ(-M_PI / 2); + dir2.RotateZ(-pi / 2); startangle = atan2(dir1.y, dir1.x); range = atan2(dir1.x * dir2.y - dir1.y * dir2.x, @@ -1632,26 +1634,28 @@ void EditModeConstraintCoinManager::findHelperAngles(double& helperStartAngle, double startAngle, double endAngle) { + using std::numbers::pi; + double margin = 0.2; // about 10deg if (angle < 0) { - angle = angle + 2 * M_PI; + angle = angle + 2 * pi; } // endAngle can be more than 2*pi as its startAngle + arcAngle - if (endAngle > 2 * M_PI && angle < endAngle - 2 * M_PI) { - angle = angle + 2 * M_PI; + if (endAngle > 2 * pi && angle < endAngle - 2 * pi) { + angle = angle + 2 * pi; } if (!(angle > startAngle && angle < endAngle)) { - if ((angle < startAngle && startAngle - angle < angle + 2 * M_PI - endAngle) - || (angle > endAngle && startAngle + 2 * M_PI - angle < angle - endAngle)) { + if ((angle < startAngle && startAngle - angle < angle + 2 * pi - endAngle) + || (angle > endAngle && startAngle + 2 * pi - angle < angle - endAngle)) { if (angle > startAngle) { - angle -= 2 * M_PI; + angle -= 2 * pi; } helperStartAngle = angle - margin; helperRange = startAngle - angle + margin; } else { if (angle < endAngle) { - angle += 2 * M_PI; + angle += 2 * pi; } helperStartAngle = endAngle; helperRange = angle - endAngle + margin; diff --git a/src/Mod/Sketcher/Gui/PreCompiled.h b/src/Mod/Sketcher/Gui/PreCompiled.h index 8d2c1892ce..d4a2ac5e7c 100644 --- a/src/Mod/Sketcher/Gui/PreCompiled.h +++ b/src/Mod/Sketcher/Gui/PreCompiled.h @@ -32,7 +32,6 @@ #ifdef _PreComp_ // standard -#include #include #include diff --git a/src/Mod/Sketcher/Gui/SnapManager.cpp b/src/Mod/Sketcher/Gui/SnapManager.cpp index 399688add4..fd34a6df0e 100644 --- a/src/Mod/Sketcher/Gui/SnapManager.cpp +++ b/src/Mod/Sketcher/Gui/SnapManager.cpp @@ -122,7 +122,8 @@ void SnapManager::ParameterObserver::updateSnapAngleParameter(const std::string& { ParameterGrp::handle hGrp = getParameterGrpHandle(); - client.snapAngle = fmod(hGrp->GetFloat(parametername.c_str(), 5.) * M_PI / 180, 2 * M_PI); + client.snapAngle = fmod(hGrp->GetFloat(parametername.c_str(), 5.) * std::numbers::pi / 180, + 2 * std::numbers::pi); } void SnapManager::ParameterObserver::subscribeToParameters() @@ -222,7 +223,7 @@ bool SnapManager::snapAtAngle(double& x, double& y) double length = (pointToOverride - referencePoint).Length(); double angle1 = (pointToOverride - referencePoint).Angle(); - double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * M_PI; + double angle2 = angle1 + (angle1 < 0. ? 2 : -2) * std::numbers::pi; lastMouseAngle = abs(angle1 - lastMouseAngle) < abs(angle2 - lastMouseAngle) ? angle1 : angle2; double angle = round(lastMouseAngle / snapAngle) * snapAngle; @@ -368,10 +369,10 @@ bool SnapManager::snapToArcMiddle(Base::Vector3d& pointToOverride, const Part::G double u, v; arc->getRange(u, v, true); if (v < u) { - v += 2 * M_PI; + v += 2 * std::numbers::pi; } double angle = v - u; - int revert = angle < M_PI ? 1 : -1; + int revert = angle < std::numbers::pi ? 1 : -1; /*To know if we are close to the middle of the arc, we are going to compare the angle of the * (mouse cursor - center) to the angle of the middle of the arc. If it's less than 10% of the diff --git a/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp b/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp index c1981f7a68..e42a545aff 100644 --- a/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp +++ b/src/Mod/Sketcher/Gui/SoZoomTranslation.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp index 5a6a4237e7..397d501703 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstraints.cpp @@ -720,8 +720,9 @@ ConstraintFilterList::ConstraintFilterList(QWidget* parent) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - int filterState = hGrp->GetInt("ConstraintFilterState", - INT_MAX);// INT_MAX = 1111111111111111111111111111111 in binary. + int filterState = hGrp->GetInt( + "ConstraintFilterState", + std::numeric_limits::max()); // INT_MAX = 01111111111111111111111111111111 in binary. normalFilterCount = filterItems.size() - 2;// All filter but selected and associated selectedFilterIndex = normalFilterCount; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp index e5df986f5d..551b9fa90f 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherElements.cpp @@ -1124,8 +1124,9 @@ ElementFilterList::ElementFilterList(QWidget* parent) { ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( "User parameter:BaseApp/Preferences/Mod/Sketcher/General"); - int filterState = hGrp->GetInt("ElementFilterState", - INT_MAX);// INT_MAX = 1111111111111111111111111111111 in binary. + int filterState = hGrp->GetInt( + "ElementFilterState", + std::numeric_limits::max());// INT_MAX = 01111111111111111111111111111111 in binary. for (auto const& filterItem : filterItems) { Q_UNUSED(filterItem); @@ -1320,7 +1321,7 @@ void TaskSketcherElements::onListMultiFilterItemChanged(QListWidgetItem* item) } // Save the state of the filter. - int filterState = INT_MIN;// INT_MIN = 000000000000000000000000000000 in binary. + int filterState = 0; // All bits are cleared. for (int i = filterList->count() - 1; i >= 0; i--) { bool isChecked = filterList->item(i)->checkState() == Qt::Checked; filterState = filterState << 1;// we shift left first, else the list is shifted at the end. diff --git a/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave new file mode 100644 index 0000000000..3b73e8be00 --- /dev/null +++ b/src/Mod/Sketcher/Gui/TaskSketcherGeneral.ui.autosave @@ -0,0 +1,77 @@ + + + TaskSketcherGeneral + + + + 0 + 0 + 253 + 61 + + + + + .AppleSystemUIFont + + + + Form + + + + + + + 0 + 0 + + + + Link + + + + + + + + 0 + 0 + + + + DOF + + + + + + + + 1 + 0 + + + + Auto Recompute + + + + + + + + Gui::StatefulLabel + QLabel +
Gui/Widgets.h
+
+ + Gui::UrlLabel + QLabel +
Gui/Widgets.h
+
+
+ + +
diff --git a/src/Mod/Sketcher/Gui/Utils.cpp b/src/Mod/Sketcher/Gui/Utils.cpp index 9a6f1ee223..6fc5562cf7 100644 --- a/src/Mod/Sketcher/Gui/Utils.cpp +++ b/src/Mod/Sketcher/Gui/Utils.cpp @@ -22,7 +22,6 @@ #include "PreCompiled.h" #ifndef _PreComp_ -#include #include #include @@ -432,7 +431,7 @@ double SketcherGui::GetPointAngle(const Base::Vector2d& p1, const Base::Vector2d { double dX = p2.x - p1.x; double dY = p2.y - p1.y; - return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * M_PI; + return dY >= 0 ? atan2(dY, dX) : atan2(dY, dX) + 2 * std::numbers::pi; } // Set the two points on circles at minimal distance diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 1bde48de8d..3c27a517df 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -861,7 +861,7 @@ void ViewProviderSketch::getCoordsOnSketchPlane(const SbVec3f& point, const SbVe // line Base::Vector3d R1(point[0], point[1], point[2]), RA(normal[0], normal[1], normal[2]); - if (fabs(RN * RA) < FLT_EPSILON) + if (fabs(RN * RA) < std::numeric_limits::epsilon()) throw Base::ZeroDivisionError("View direction is parallel to sketch plane"); // intersection point on plane Base::Vector3d S = R1 + ((RN * (R0 - R1)) / (RN * RA)) * RA; @@ -1930,9 +1930,9 @@ void ViewProviderSketch::moveConstraint(Sketcher::Constraint* Constr, int constN || Constr->Type == Weight) dir = (p2 - p1).Normalize(); else if (Constr->Type == DistanceX) - dir = Base::Vector3d((p2.x - p1.x >= FLT_EPSILON) ? 1 : -1, 0, 0); + dir = Base::Vector3d((p2.x - p1.x >= std::numeric_limits::epsilon()) ? 1 : -1, 0, 0); else if (Constr->Type == DistanceY) - dir = Base::Vector3d(0, (p2.y - p1.y >= FLT_EPSILON) ? 1 : -1, 0); + dir = Base::Vector3d(0, (p2.y - p1.y >= std::numeric_limits::epsilon()) ? 1 : -1, 0); if (Constr->Type == Radius || Constr->Type == Diameter || Constr->Type == Weight) { Constr->LabelDistance = vec.x * dir.x + vec.y * dir.y; @@ -2029,9 +2029,9 @@ void ViewProviderSketch::moveAngleConstraint(Sketcher::Constraint* constr, int c Base::Vector3d p = getSolvedSketch().getPoint(constr->Third, constr->ThirdPos); p0 = Base::Vector3d(p.x, p.y, 0); Base::Vector3d dir1 = getSolvedSketch().calculateNormalAtPoint(constr->First, p.x, p.y); - dir1.RotateZ(-M_PI / 2);// convert to vector of tangency by rotating + dir1.RotateZ(-std::numbers::pi / 2);// convert to vector of tangency by rotating Base::Vector3d dir2 = getSolvedSketch().calculateNormalAtPoint(constr->Second, p.x, p.y); - dir2.RotateZ(-M_PI / 2); + dir2.RotateZ(-std::numbers::pi / 2); Base::Vector3d vec = Base::Vector3d(toPos.x, toPos.y, 0) - p0; factor = factor * Base::sgn((dir1 + dir2) * vec); @@ -3996,7 +3996,7 @@ double ViewProviderSketch::getRotation(SbVec3f pos0, SbVec3f pos1) const getCoordsOnSketchPlane(pos0, vol.getProjectionDirection(), x0, y0); getCoordsOnSketchPlane(pos1, vol.getProjectionDirection(), x1, y1); - return -atan2((y1 - y0), (x1 - x0)) * 180 / M_PI; + return -atan2((y1 - y0), (x1 - x0)) * 180 / std::numbers::pi; } catch (const Base::ZeroDivisionError&) { return 0; diff --git a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp index f8a35e3287..10013b96b5 100644 --- a/src/Mod/Spreadsheet/Gui/SheetTableView.cpp +++ b/src/Mod/Spreadsheet/Gui/SheetTableView.cpp @@ -698,9 +698,9 @@ void SheetTableView::copySelection() void SheetTableView::_copySelection(const std::vector& ranges, bool copy) { - int minRow = INT_MAX; + int minRow = std::numeric_limits::max(); int maxRow = 0; - int minCol = INT_MAX; + int minCol = std::numeric_limits::max(); int maxCol = 0; for (auto& range : ranges) { minRow = std::min(minRow, range.from().row()); diff --git a/src/Mod/Surface/App/FeatureExtend.cpp b/src/Mod/Surface/App/FeatureExtend.cpp index 83701ba824..518a300d18 100644 --- a/src/Mod/Surface/App/FeatureExtend.cpp +++ b/src/Mod/Surface/App/FeatureExtend.cpp @@ -42,7 +42,9 @@ using namespace Surface; -const App::PropertyIntegerConstraint::Constraints SampleRange = {2, INT_MAX, 1}; +const App::PropertyIntegerConstraint::Constraints SampleRange = {2, + std::numeric_limits::max(), + 1}; const App::PropertyFloatConstraint::Constraints ToleranceRange = {0.0, 10.0, 0.01}; const App::PropertyFloatConstraint::Constraints ExtendRange = {-0.5, 10.0, 0.01}; PROPERTY_SOURCE(Surface::Extend, Part::Spline) diff --git a/src/Mod/TechDraw/App/CenterLine.cpp b/src/Mod/TechDraw/App/CenterLine.cpp index a61d4ad12a..3ca87f7832 100644 --- a/src/Mod/TechDraw/App/CenterLine.cpp +++ b/src/Mod/TechDraw/App/CenterLine.cpp @@ -392,7 +392,7 @@ std::pair CenterLine::rotatePointsAroundMid(cons const double angleDeg) { std::pair result; - double angleRad = angleDeg * M_PI / 180.0; + double angleRad = angleDeg * std::numbers::pi / 180.0; result.first.x = ((p1.x - mid.x) * cos(angleRad)) - ((p1.y - mid.y) * sin(angleRad)) + mid.x; result.first.y = ((p1.x - mid.x) * sin(angleRad)) + ((p1.y - mid.y) * cos(angleRad)) + mid.y; diff --git a/src/Mod/TechDraw/App/CosmeticVertex.cpp b/src/Mod/TechDraw/App/CosmeticVertex.cpp index a33e6c2dd8..35275c0546 100644 --- a/src/Mod/TechDraw/App/CosmeticVertex.cpp +++ b/src/Mod/TechDraw/App/CosmeticVertex.cpp @@ -166,7 +166,7 @@ Base::Vector3d CosmeticVertex::rotatedAndScaled(const double scale, const double // invert the Y coordinate so the rotation math works out // the stored point is inverted scaledPoint = DU::invertY(scaledPoint); - scaledPoint.RotateZ(rotDegrees * M_PI / DegreesHalfCircle); + scaledPoint.RotateZ(rotDegrees * std::numbers::pi / DegreesHalfCircle); scaledPoint = DU::invertY(scaledPoint); } return scaledPoint; @@ -182,7 +182,7 @@ Base::Vector3d CosmeticVertex::makeCanonicalPoint(DrawViewPart* dvp, Base::Vecto Base::Vector3d result = point; if (rotDeg != 0.0) { // unrotate the point - double rotRad = rotDeg * M_PI / DegreesHalfCircle; + double rotRad = rotDeg * std::numbers::pi / DegreesHalfCircle; // we always rotate around the origin. result.RotateZ(-rotRad); } diff --git a/src/Mod/TechDraw/App/DrawBrokenView.cpp b/src/Mod/TechDraw/App/DrawBrokenView.cpp index 4dd3a15a02..af7c91fc54 100644 --- a/src/Mod/TechDraw/App/DrawBrokenView.cpp +++ b/src/Mod/TechDraw/App/DrawBrokenView.cpp @@ -1113,7 +1113,7 @@ Base::Vector3d DrawBrokenView::makePerpendicular(Base::Vector3d inDir) const gp_Pnt origin(0.0, 0.0, 0.0); auto dir = getProjectionCS().Direction(); gp_Ax1 axis(origin, dir); - auto gRotated = gDir.Rotated(axis, M_PI_2); + auto gRotated = gDir.Rotated(axis, std::numbers::pi/2); return Base::convertTo(gRotated); } diff --git a/src/Mod/TechDraw/App/DrawComplexSection.cpp b/src/Mod/TechDraw/App/DrawComplexSection.cpp index eda78c83e3..198d5da1ec 100644 --- a/src/Mod/TechDraw/App/DrawComplexSection.cpp +++ b/src/Mod/TechDraw/App/DrawComplexSection.cpp @@ -100,7 +100,6 @@ #include #endif -#define _USE_MATH_DEFINES #include #include @@ -387,7 +386,7 @@ void DrawComplexSection::makeAlignedPieces(const TopoDS_Shape& rawShape) } //we only want to reverse the segment normal if it is not perpendicular to section normal if (segmentNormal.Dot(gProjectionUnit) != 0.0 - && segmentNormal.Angle(gProjectionUnit) <= M_PI_2) { + && segmentNormal.Angle(gProjectionUnit) <= std::numbers::pi/2) { segmentNormal.Reverse(); } @@ -957,7 +956,7 @@ gp_Vec DrawComplexSection::projectVector(const gp_Vec& vec) const // being slightly wrong. see https://forum.freecad.org/viewtopic.php?t=79017&sid=612a62a60f5db955ee071a7aaa362dbb bool DrawComplexSection::validateOffsetProfile(TopoDS_Wire profile, Base::Vector3d direction, double angleThresholdDeg) const { - double angleThresholdRad = angleThresholdDeg * M_PI / 180.0; // 5 degrees + double angleThresholdRad = angleThresholdDeg * std::numbers::pi / 180.0; // 5 degrees TopExp_Explorer explEdges(profile, TopAbs_EDGE); for (; explEdges.More(); explEdges.Next()) { std::pair segmentEnds = getSegmentEnds(TopoDS::Edge(explEdges.Current())); diff --git a/src/Mod/TechDraw/App/DrawGeomHatch.cpp b/src/Mod/TechDraw/App/DrawGeomHatch.cpp index 66366a000e..72412cf557 100644 --- a/src/Mod/TechDraw/App/DrawGeomHatch.cpp +++ b/src/Mod/TechDraw/App/DrawGeomHatch.cpp @@ -385,6 +385,8 @@ std::vector DrawGeomHatch::getTrimmedLines(DrawViewPart* source, /* static */ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hatchLine, Bnd_Box bBox, double scale, double rotation) { + using std::numbers::pi; + const size_t MaxNumberOfEdges = Preferences::getPreferenceGroup("PAT")->GetInt("MaxSeg", 10000l); std::vector result; @@ -399,12 +401,12 @@ std::vector DrawGeomHatch::makeEdgeOverlay(PATLineSpec hatchLine, B double interval = hatchLine.getInterval() * scale; double offset = hatchLine.getOffset() * scale; double angle = hatchLine.getAngle() + rotation; - origin.RotateZ(rotation * M_PI / 180.); + origin.RotateZ(rotation * pi / 180.); if (scale == 0. || interval == 0.) return {}; - Base::Vector3d hatchDirection(cos(angle * M_PI / 180.), sin(angle * M_PI / 180.), 0.); + Base::Vector3d hatchDirection(cos(angle * pi / 180.), sin(angle * pi / 180.), 0.); Base::Vector3d hatchPerpendicular(-hatchDirection.y, hatchDirection.x, 0.); Base::Vector3d hatchIntervalAndOffset = offset * hatchDirection + interval * hatchPerpendicular; diff --git a/src/Mod/TechDraw/App/DrawLeaderLine.cpp b/src/Mod/TechDraw/App/DrawLeaderLine.cpp index 124b5164b2..bca5eea111 100644 --- a/src/Mod/TechDraw/App/DrawLeaderLine.cpp +++ b/src/Mod/TechDraw/App/DrawLeaderLine.cpp @@ -375,7 +375,7 @@ std::vector DrawLeaderLine::getScaledAndRotatedPoints(bool doSc double rotationRad{0.0}; if (doRotate) { - rotationRad = dvp->Rotation.getValue() * M_PI / DegreesHalfCircle; + rotationRad = dvp->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; } std::vector pointsAll = WayPoints.getValues(); @@ -409,7 +409,7 @@ DrawLeaderLine::makeCanonicalPoints(const std::vector& inPoints, double rotationRad{0.0}; if (doRotate) { - rotationRad = - dvp->Rotation.getValue() * M_PI / DegreesHalfCircle; + rotationRad = - dvp->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; } std::vector result; diff --git a/src/Mod/TechDraw/App/DrawPage.cpp b/src/Mod/TechDraw/App/DrawPage.cpp index 2ad8f2c926..bd5c908e68 100644 --- a/src/Mod/TechDraw/App/DrawPage.cpp +++ b/src/Mod/TechDraw/App/DrawPage.cpp @@ -118,7 +118,7 @@ void DrawPage::onChanged(const App::Property* prop) for (auto* obj : getViews()) { auto* view = dynamic_cast(obj); if (view && view->ScaleType.isValue("Page")) { - if (std::abs(view->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { + if (std::abs(view->Scale.getValue() - Scale.getValue()) > std::numeric_limits::epsilon()) { view->Scale.setValue(Scale.getValue()); } } diff --git a/src/Mod/TechDraw/App/DrawProjGroup.cpp b/src/Mod/TechDraw/App/DrawProjGroup.cpp index 2b491aff97..2b05d8ab60 100644 --- a/src/Mod/TechDraw/App/DrawProjGroup.cpp +++ b/src/Mod/TechDraw/App/DrawProjGroup.cpp @@ -142,7 +142,7 @@ void DrawProjGroup::onChanged(const App::Property* prop) if (prop == &ScaleType) { if (ScaleType.isValue("Page")) { double newScale = page->Scale.getValue(); - if (std::abs(getScale() - newScale) > FLT_EPSILON) { + if (std::abs(getScale() - newScale) > std::numeric_limits::epsilon()) { Scale.setValue(newScale); updateChildrenScale(); } @@ -1146,9 +1146,9 @@ void DrawProjGroup::spin(const SpinDirection& spindirection) { double angle; if (spindirection == SpinDirection::CW) - angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top + angle = std::numbers::pi / 2.0;// Top -> Right -> Bottom -> Left -> Top if (spindirection == SpinDirection::CCW) - angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top + angle = -std::numbers::pi / 2.0;// Top -> Left -> Bottom -> Right -> Top spin(angle); } diff --git a/src/Mod/TechDraw/App/DrawProjectSplit.cpp b/src/Mod/TechDraw/App/DrawProjectSplit.cpp index dd4b1825a0..7853e729b6 100644 --- a/src/Mod/TechDraw/App/DrawProjectSplit.cpp +++ b/src/Mod/TechDraw/App/DrawProjectSplit.cpp @@ -345,10 +345,12 @@ std::vector DrawProjectSplit::sortEdges(std::vector& //************************* std::string edgeSortItem::dump() { + using std::numbers::pi; + std::string result; std::stringstream builder; builder << "edgeSortItem - s: " << DrawUtil::formatVector(start) << " e: " << DrawUtil::formatVector(end) << - " sa: " << startAngle * 180.0/M_PI << " ea: " << endAngle* 180.0/M_PI << " idx: " << idx; + " sa: " << startAngle * 180.0/pi << " ea: " << endAngle* 180.0/pi << " idx: " << idx; return builder.str(); } diff --git a/src/Mod/TechDraw/App/DrawUtil.cpp b/src/Mod/TechDraw/App/DrawUtil.cpp index bbe2edda84..5e0dfc7a1c 100644 --- a/src/Mod/TechDraw/App/DrawUtil.cpp +++ b/src/Mod/TechDraw/App/DrawUtil.cpp @@ -203,7 +203,7 @@ double DrawUtil::angleWithX(Base::Vector3d inVec) { double result = atan2(inVec.y, inVec.x); if (result < 0) { - result += 2.0 * M_PI; + result += 2.0 * std::numbers::pi; } return result; @@ -225,7 +225,7 @@ double DrawUtil::angleWithX(TopoDS_Edge e, bool reverse) } double result = atan2(u.y, u.x); if (result < 0) { - result += 2.0 * M_PI; + result += 2.0 * std::numbers::pi; } return result; @@ -251,7 +251,7 @@ double DrawUtil::angleWithX(TopoDS_Edge e, TopoDS_Vertex v, double tolerance) c->D1(param, paramPoint, derivative); double angle = atan2(derivative.Y(), derivative.X()); if (angle < 0) {//map from [-PI:PI] to [0:2PI] - angle += 2.0 * M_PI; + angle += 2.0 * std::numbers::pi; } return angle; } @@ -289,7 +289,7 @@ double DrawUtil::incidenceAngleAtVertex(TopoDS_Edge e, TopoDS_Vertex v, double t //map to [0:2PI] if (incidenceAngle < 0.0) { - incidenceAngle = M_2PI + incidenceAngle; + incidenceAngle = 2*std::numbers::pi + incidenceAngle; } return incidenceAngle; @@ -1059,7 +1059,7 @@ Base::Vector3d DrawUtil::toAppSpace(const DrawViewPart& dvp, const Base::Vector // remove the effect of the Rotation property double rotDeg = dvp.Rotation.getValue(); - double rotRad = rotDeg * M_PI / 180.0; + double rotRad = rotDeg * std::numbers::pi / 180.0; if (rotDeg != 0.0) { // we always rotate around the origin. appPoint.RotateZ(-rotRad); @@ -1396,11 +1396,13 @@ double DrawUtil::sqr(double x) void DrawUtil::angleNormalize(double& fi) { - while (fi <= -M_PI) { - fi += M_2PI; + using std::numbers::pi; + + while (fi <= -pi) { + fi += 2*pi; } - while (fi > M_PI) { - fi -= M_2PI; + while (fi > pi) { + fi -= 2*pi; } } @@ -1414,13 +1416,14 @@ double DrawUtil::angleComposition(double fi, double delta) double DrawUtil::angleDifference(double fi1, double fi2, bool reflex) { + using std::numbers::pi; angleNormalize(fi1); angleNormalize(fi2); fi1 -= fi2; - if ((fi1 > +M_PI || fi1 <= -M_PI) != reflex) { - fi1 += fi1 > 0.0 ? -M_2PI : +M_2PI; + if ((fi1 > +pi || fi1 <= -pi) != reflex) { + fi1 += fi1 > 0.0 ? -2*pi : +2*pi; } return fi1; @@ -1559,6 +1562,7 @@ void DrawUtil::intervalMarkLinear(std::vector>& marking, void DrawUtil::intervalMarkCircular(std::vector>& marking, double start, double length, bool value) { + using std::numbers::pi; if (length == 0.0) { return; } @@ -1566,15 +1570,15 @@ void DrawUtil::intervalMarkCircular(std::vector>& markin length = -length; start -= length; } - if (length > M_2PI) { - length = M_2PI; + if (length > 2*pi) { + length = 2*pi; } angleNormalize(start); double end = start + length; - if (end > M_PI) { - end -= M_2PI; + if (end > pi) { + end -= 2*pi; } // Just make sure the point is stored, its index is read last @@ -1785,13 +1789,15 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circl const Base::BoundBox2d& rectangle, std::vector& intersections) { + using std::numbers::pi; + findCircleRectangleIntersections(circleCenter, circleRadius, rectangle, intersections); if (arcRotation < 0.0) { arcRotation = -arcRotation; arcBaseAngle -= arcRotation; - if (arcBaseAngle <= -M_PI) { - arcBaseAngle += M_2PI; + if (arcBaseAngle <= -pi) { + arcBaseAngle += 2*pi; } } @@ -1799,7 +1805,7 @@ void DrawUtil::findCircularArcRectangleIntersections(const Base::Vector2d& circl for (unsigned int i = 0; i < intersections.size();) { double pointAngle = (intersections[i] - circleCenter).Angle(); if (pointAngle < arcBaseAngle - Precision::Confusion()) { - pointAngle += M_2PI; + pointAngle += 2*pi; } if (pointAngle > arcBaseAngle + arcRotation + Precision::Confusion()) { diff --git a/src/Mod/TechDraw/App/DrawUtil.h b/src/Mod/TechDraw/App/DrawUtil.h index 5a4e10d9b8..7490e58622 100644 --- a/src/Mod/TechDraw/App/DrawUtil.h +++ b/src/Mod/TechDraw/App/DrawUtil.h @@ -50,10 +50,6 @@ #include -#ifndef M_2PI -#define M_2PI ((M_PI)*2.0) -#endif - constexpr double DegreesHalfCircle{180.0}; #define VERTEXTOLERANCE (2.0 * Precision::Confusion()) @@ -108,7 +104,8 @@ public: static bool isFirstVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); static bool isLastVert(TopoDS_Edge e, TopoDS_Vertex v, double tolerance = VERTEXTOLERANCE); - static bool fpCompare(const double& d1, const double& d2, double tolerance = FLT_EPSILON); + static bool fpCompare(const double& d1, const double& d2, + double tolerance = std::numeric_limits::epsilon()); static std::pair boxIntersect2d(Base::Vector3d point, Base::Vector3d dir, double xRange, double yRange); static bool apparentIntersection(const Handle(Geom_Curve) curve1, @@ -147,7 +144,7 @@ public: static Base::Vector3d toR3(const gp_Ax2& fromSystem, const Base::Vector3d& fromPoint); static bool checkParallel(const Base::Vector3d v1, const Base::Vector3d v2, - double tolerance = FLT_EPSILON); + double tolerance = std::numeric_limits::epsilon()); //! rotate vector by angle radians around axis through org static Base::Vector3d vecRotate(Base::Vector3d vec, double angle, Base::Vector3d axis, Base::Vector3d org = Base::Vector3d(0.0, 0.0, 0.0)); diff --git a/src/Mod/TechDraw/App/DrawView.cpp b/src/Mod/TechDraw/App/DrawView.cpp index d3b52a6e4b..4b01917bf6 100644 --- a/src/Mod/TechDraw/App/DrawView.cpp +++ b/src/Mod/TechDraw/App/DrawView.cpp @@ -130,7 +130,7 @@ void DrawView::checkScale() TechDraw::DrawPage *page = findParentPage(); if(page) { if (ScaleType.isValue("Page")) { - if(std::abs(page->Scale.getValue() - Scale.getValue()) > FLT_EPSILON) { + if(std::abs(page->Scale.getValue() - Scale.getValue()) > std::numeric_limits::epsilon()) { Scale.setValue(page->Scale.getValue()); Scale.purgeTouched(); } @@ -190,7 +190,7 @@ void DrawView::onChanged(const App::Property* prop) } if (ScaleType.isValue("Page")) { Scale.setStatus(App::Property::ReadOnly, true); - if(std::abs(page->Scale.getValue() - getScale()) > FLT_EPSILON) { + if(std::abs(page->Scale.getValue() - getScale()) > std::numeric_limits::epsilon()) { Scale.setValue(page->Scale.getValue()); } } else if ( ScaleType.isValue("Custom") ) { @@ -200,7 +200,7 @@ void DrawView::onChanged(const App::Property* prop) Scale.setStatus(App::Property::ReadOnly, true); if (!checkFit(page)) { double newScale = autoScale(page->getPageWidth(), page->getPageHeight()); - if(std::abs(newScale - getScale()) > FLT_EPSILON) { + if(std::abs(newScale - getScale()) > std::numeric_limits::epsilon()) { Scale.setValue(newScale); } } diff --git a/src/Mod/TechDraw/App/DrawViewDimension.cpp b/src/Mod/TechDraw/App/DrawViewDimension.cpp index 72a7af43a0..a16883c267 100644 --- a/src/Mod/TechDraw/App/DrawViewDimension.cpp +++ b/src/Mod/TechDraw/App/DrawViewDimension.cpp @@ -105,11 +105,11 @@ const char* DrawViewDimension::TypeEnums[] = {"Distance", const char* DrawViewDimension::MeasureTypeEnums[] = {"True", "Projected", nullptr}; // constraint to set the step size to 0.1 -static const App::PropertyQuantityConstraint::Constraints ToleranceConstraint = {-DBL_MAX, - DBL_MAX, - 0.1}; +static const App::PropertyQuantityConstraint::Constraints ToleranceConstraint = { + -std::numeric_limits::max(), std::numeric_limits::max(), 0.1}; // constraint to force positive values -static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = {0.0, DBL_MAX, 0.1}; +static const App::PropertyQuantityConstraint::Constraints PositiveConstraint = { + 0.0, std::numeric_limits::max(), 0.1}; DrawViewDimension::DrawViewDimension() { diff --git a/src/Mod/TechDraw/App/DrawViewPart.cpp b/src/Mod/TechDraw/App/DrawViewPart.cpp index d0359df991..117001a094 100644 --- a/src/Mod/TechDraw/App/DrawViewPart.cpp +++ b/src/Mod/TechDraw/App/DrawViewPart.cpp @@ -986,7 +986,7 @@ double DrawViewPart::getSizeAlongVector(Base::Vector3d alignmentVector) if (getEdgeCompound().IsNull()) { return 1.0; } - TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / M_PI); + TopoDS_Shape rotatedShape = ShapeUtils::rotateShape(getEdgeCompound(), OXYZ, alignmentAngle * 180.0 / std::numbers::pi); Bnd_Box shapeBox; shapeBox.SetGap(0.0); BRepBndLib::AddOptimal(rotatedShape, shapeBox); @@ -1105,7 +1105,7 @@ gp_Ax2 DrawViewPart::getRotatedCS(const Base::Vector3d basePoint) const // Base::Console().Message("DVP::getRotatedCS() - %s - %s\n", getNameInDocument(), Label.getValue()); gp_Ax2 unrotated = getProjectionCS(basePoint); gp_Ax1 rotationAxis(Base::convertTo(basePoint), unrotated.Direction()); - double angleRad = Rotation.getValue() * M_PI / 180.0; + double angleRad = Rotation.getValue() * std::numbers::pi / 180.0; gp_Ax2 rotated = unrotated.Rotated(rotationAxis, -angleRad); return rotated; } @@ -1302,9 +1302,9 @@ void DrawViewPart::spin(const SpinDirection& spindirection) { double angle; if (spindirection == SpinDirection::CW) - angle = M_PI / 2.0;// Top -> Right -> Bottom -> Left -> Top + angle = std::numbers::pi / 2.0;// Top -> Right -> Bottom -> Left -> Top if (spindirection == SpinDirection::CCW) - angle = -M_PI / 2.0;// Top -> Left -> Bottom -> Right -> Top + angle = -std::numbers::pi / 2.0;// Top -> Left -> Bottom -> Right -> Top spin(angle); } @@ -1338,7 +1338,7 @@ std::pair DrawViewPart::getDirsFromFront(ProjDir gp_Dir gNewDir; gp_Dir gNewXDir; - double angle = M_PI / 2.0;//90* + double angle = std::numbers::pi / 2.0;//90* if (viewType == ProjDirection::Right) { newCS = anchorCS.Rotated(gUpAxis, angle); diff --git a/src/Mod/TechDraw/App/EdgeWalker.cpp b/src/Mod/TechDraw/App/EdgeWalker.cpp index ae3d5b0af7..d30f1d9607 100644 --- a/src/Mod/TechDraw/App/EdgeWalker.cpp +++ b/src/Mod/TechDraw/App/EdgeWalker.cpp @@ -307,11 +307,11 @@ std::vector EdgeWalker::makeWalkerEdges(std::vector edg TopoDS_Vertex edgeVertex1 = TopExp::FirstVertex(e); TopoDS_Vertex edgeVertex2 = TopExp::LastVertex(e); std::size_t vertex1Index = findUniqueVert(edgeVertex1, verts); - if (vertex1Index == SIZE_MAX) { + if (vertex1Index == std::numeric_limits::max()) { continue; } std::size_t vertex2Index = findUniqueVert(edgeVertex2, verts); - if (vertex2Index == SIZE_MAX) { + if (vertex2Index == std::numeric_limits::max()) { continue; } @@ -338,7 +338,7 @@ size_t EdgeWalker::findUniqueVert(TopoDS_Vertex vx, std::vector & } idx++; } - return SIZE_MAX; + return std::numeric_limits::max(); } std::vector EdgeWalker::sortStrip(std::vector fw, bool includeBiggest) @@ -556,7 +556,7 @@ std::string embedItem::dump() std::stringstream builder; builder << "embedItem - vertex: " << iVertex << " incidenceList: "; for (auto& ii : incidenceList) { - builder << " e:" << ii.iEdge << "/a:" << (ii.angle * (180.0/M_PI)) << "/ed:" << ii.eDesc; + builder << " e:" << ii.iEdge << "/a:" << (ii.angle * (180.0/std::numbers::pi)) << "/ed:" << ii.eDesc; } return builder.str(); } diff --git a/src/Mod/TechDraw/App/Geometry.cpp b/src/Mod/TechDraw/App/Geometry.cpp index 0cb09d530b..6011cbea15 100644 --- a/src/Mod/TechDraw/App/Geometry.cpp +++ b/src/Mod/TechDraw/App/Geometry.cpp @@ -657,7 +657,7 @@ Ellipse::Ellipse(Base::Vector3d c, double mnr, double mjr) Base::Console().Message("G:Ellipse - failed to make Ellipse\n"); } const Handle(Geom_Ellipse) gEllipse = me.Value(); - BRepBuilderAPI_MakeEdge mkEdge(gEllipse, 0.0, 2 * M_PI); + BRepBuilderAPI_MakeEdge mkEdge(gEllipse, 0.0, 2 * std::numbers::pi); if (mkEdge.IsDone()) { occEdge = mkEdge.Edge(); } @@ -686,10 +686,10 @@ AOE::AOE(const TopoDS_Edge &e) : Ellipse(e) e.GetMessageString()); } - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (l-f > M_PI) ? true : false; + largeArc = (l-f > std::numbers::pi) ? true : false; startPnt = Base::Vector3d(s.X(), s.Y(), s.Z()); endPnt = Base::Vector3d(ePt.X(), ePt.Y(), ePt.Z()); @@ -709,6 +709,8 @@ Circle::Circle() Circle::Circle(Base::Vector3d c, double r) { + using std::numbers::pi; + geomType = GeomType::CIRCLE; radius = r; center = c; @@ -722,7 +724,7 @@ Circle::Circle(Base::Vector3d c, double r) double angle2 = 360.0; Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(M_PI/180), angle2*(M_PI/180)); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, angle1*(pi/180), angle2*(pi/180)); TopoDS_Edge edge = aMakeEdge.Edge(); occEdge = edge; } @@ -794,12 +796,12 @@ AOC::AOC(const TopoDS_Edge &e) : Circle(e) // this is the wrong determination of cw/ccw. needs to be determined by edge. double a = v3.DotCross(v1, v2); //error if v1 = v2? - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (fabs(l-f) > M_PI) ? true : false; + largeArc = (fabs(l-f) > std::numbers::pi) ? true : false; startPnt = Base::convertTo(s); endPnt = Base::convertTo(ePt); @@ -823,7 +825,7 @@ AOC::AOC(Base::Vector3d c, double r, double sAng, double eAng) : Circle() circle.SetRadius(r); Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, sAng*(M_PI/180), eAng*(M_PI/180)); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, sAng*(std::numbers::pi/180), eAng*(std::numbers::pi/180)); TopoDS_Edge edge = aMakeEdge.Edge(); occEdge = edge; @@ -844,10 +846,10 @@ AOC::AOC(Base::Vector3d c, double r, double sAng, double eAng) : Circle() // this cw flag is a problem. we should just declare that arcs are always ccw and flip the start and end angles. double a = v3.DotCross(v1, v2); //error if v1 = v2? - startAngle = fmod(f, 2.0*M_PI); - endAngle = fmod(l, 2.0*M_PI); + startAngle = fmod(f, 2.0*std::numbers::pi); + endAngle = fmod(l, 2.0*std::numbers::pi); cw = (a < 0) ? true: false; - largeArc = (fabs(l-f) > M_PI) ? true : false; + largeArc = (fabs(l-f) > std::numbers::pi) ? true : false; startPnt = Base::convertTo(s); endPnt = Base::convertTo(ePt); @@ -866,7 +868,7 @@ AOC::AOC() : Circle() endPnt = Base::Vector3d(0.0, 0.0, 0.0); midPnt = Base::Vector3d(0.0, 0.0, 0.0); startAngle = 0.0; - endAngle = 2.0 * M_PI; + endAngle = 2.0 * std::numbers::pi; cw = false; largeArc = false; @@ -1095,7 +1097,7 @@ double Generic::slope() { Base::Vector3d v = asVector(); if (v.x == 0.0) { - return DOUBLE_MAX; + return std::numeric_limits::max(); } else { return v.y/v.x; } @@ -1146,11 +1148,11 @@ BSpline::BSpline(const TopoDS_Edge &e) startAngle = atan2(startPnt.y, startPnt.x); if (startAngle < 0) { - startAngle += 2.0 * M_PI; + startAngle += 2.0 * std::numbers::pi; } endAngle = atan2(endPnt.y, endPnt.x); if (endAngle < 0) { - endAngle += 2.0 * M_PI; + endAngle += 2.0 * std::numbers::pi; } Standard_Real tol3D = 0.001; //1/1000 of a mm? screen can't resolve this @@ -1473,7 +1475,7 @@ TopoDS_Edge GeometryUtils::edgeFromCircle(TechDraw::CirclePtr c) circle.SetAxis(axis); circle.SetRadius(c->radius); Handle(Geom_Circle) hCircle = new Geom_Circle (circle); - BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, 0.0, 2.0 * M_PI); + BRepBuilderAPI_MakeEdge aMakeEdge(hCircle, 0.0, 2.0 * std::numbers::pi); return aMakeEdge.Edge(); } diff --git a/src/Mod/TechDraw/App/GeometryObject.cpp b/src/Mod/TechDraw/App/GeometryObject.cpp index b56e54943f..021cb13534 100644 --- a/src/Mod/TechDraw/App/GeometryObject.cpp +++ b/src/Mod/TechDraw/App/GeometryObject.cpp @@ -759,24 +759,26 @@ TechDraw::DrawViewDetail* GeometryObject::isParentDetail() bool GeometryObject::isWithinArc(double theta, double first, double last, bool cw) const { - if (fabs(last - first) >= 2 * M_PI) { + using std::numbers::pi; + + if (fabs(last - first) >= 2 * pi) { return true; } // Put params within [0, 2*pi) - not totally sure this is necessary - theta = fmod(theta, 2 * M_PI); + theta = fmod(theta, 2 * pi); if (theta < 0) { - theta += 2 * M_PI; + theta += 2 * pi; } - first = fmod(first, 2 * M_PI); + first = fmod(first, 2 * pi); if (first < 0) { - first += 2 * M_PI; + first += 2 * pi; } - last = fmod(last, 2 * M_PI); + last = fmod(last, 2 * pi); if (last < 0) { - last += 2 * M_PI; + last += 2 * pi; } if (cw) { diff --git a/src/Mod/TechDraw/App/HatchLine.cpp b/src/Mod/TechDraw/App/HatchLine.cpp index 2c2814cac1..e37626a2d1 100644 --- a/src/Mod/TechDraw/App/HatchLine.cpp +++ b/src/Mod/TechDraw/App/HatchLine.cpp @@ -396,7 +396,7 @@ double PATLineSpec::getSlope() } else if (angle < -90.0) { angle = (180 + angle); } - return tan(angle * M_PI/180.0); + return tan(angle * std::numbers::pi/180.0); } bool PATLineSpec::isDashed() @@ -413,7 +413,7 @@ double PATLineSpec::getIntervalX() return getInterval(); } else { double perpAngle = fabs(getAngle() - 90.0); - return fabs(getInterval() / cos(perpAngle * M_PI/180.0)); + return fabs(getInterval() / cos(perpAngle * std::numbers::pi/180.0)); } } @@ -426,7 +426,7 @@ double PATLineSpec::getIntervalY() return 0.0; } else { double perpAngle = fabs(getAngle() - 90.0); - return fabs(getInterval() * tan(perpAngle * M_PI/180.0)); + return fabs(getInterval() * tan(perpAngle * std::numbers::pi/180.0)); } } diff --git a/src/Mod/TechDraw/App/ShapeUtils.cpp b/src/Mod/TechDraw/App/ShapeUtils.cpp index 88db95abc8..6e5c070fe5 100644 --- a/src/Mod/TechDraw/App/ShapeUtils.cpp +++ b/src/Mod/TechDraw/App/ShapeUtils.cpp @@ -96,7 +96,7 @@ gp_Ax2 ShapeUtils::getViewAxis(const Base::Vector3d origin, const Base::Vector3d cross = cross.Cross(stdZ); } - if (cross.IsEqual(stdOrg, FLT_EPSILON)) { + if (cross.IsEqual(stdOrg, std::numeric_limits::epsilon())) { viewAxis = gp_Ax2(inputCenter, gp_Dir(direction.x, direction.y, direction.z)); return viewAxis; } @@ -142,7 +142,7 @@ gp_Ax2 ShapeUtils::legacyViewAxis1(const Base::Vector3d origin, const Base::Vect cross = cross.Cross(stdZ); } - if (cross.IsEqual(stdOrg, FLT_EPSILON)) { + if (cross.IsEqual(stdOrg, std::numeric_limits::epsilon())) { return gp_Ax2(inputCenter, gp_Dir(flipDirection.x, flipDirection.y, flipDirection.z)); } @@ -273,7 +273,7 @@ TopoDS_Shape ShapeUtils::rotateShape(const TopoDS_Shape& input, const gp_Ax2& vi } gp_Ax1 rotAxis = viewAxis.Axis(); - double rotation = rotAngle * M_PI / 180.0; + double rotation = rotAngle * std::numbers::pi / 180.0; try { gp_Trsf tempTransform; diff --git a/src/Mod/TechDraw/App/TechDrawExport.cpp b/src/Mod/TechDraw/App/TechDrawExport.cpp index dd7391eac6..eb97f04a0e 100644 --- a/src/Mod/TechDraw/App/TechDrawExport.cpp +++ b/src/Mod/TechDraw/App/TechDrawExport.cpp @@ -220,7 +220,7 @@ void SVGOutput::printCircle(const BRepAdaptor_Curve& c, std::ostream& out) else { // See also https://developer.mozilla.org/en/SVG/Tutorial/Paths char xar = '0'; // x-axis-rotation - char las = (l-f > M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " M_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << " 0) { double temp = start_angle; @@ -583,7 +583,7 @@ void DXFOutput::printEllipse(const BRepAdaptor_Curve& c, int /*id*/, std::ostrea gp_Dir xaxis = ellp.XAxis().Direction(); Standard_Real angle = xaxis.Angle(gp_Dir(1, 0,0)); angle = Base::toDegrees(angle); - char las = (l-f > D_PI) ? '1' : '0'; // large-arc-flag + char las = (l-f > std::numbers::pi) ? '1' : '0'; // large-arc-flag char swp = (a < 0) ? '1' : '0'; // sweep-flag, i.e. clockwise (0) or counter-clockwise (1) out << "::max(); + double minY = std::numeric_limits::max(); + double maxX = -std::numeric_limits::max(); + double maxY = -std::numeric_limits::max(); for (auto dim : dims) { TechDraw::pointPair pp = dim->getLinearPoints(); Base::Vector3d pnt1 = Rez::guiX(pp.first()); diff --git a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp index 64d16ae320..7da9433ff9 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionDims.cpp @@ -2050,7 +2050,7 @@ void execCreateHorizChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; + const auto Pi180 = 180.0 / std::numbers::pi; TechDraw::DrawViewDimension* dim; dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceX"); float yMax = std::max(abs(allVertexes[0].point.y), abs(allVertexes[1].point.y)) + 7.0; @@ -2119,7 +2119,7 @@ void execCreateVertChamferDimension(Gui::Command* cmd) { std::vector allVertexes; allVertexes = _getVertexInfo(objFeat, subNames); if (!allVertexes.empty() && allVertexes.size() > 1) { - const auto Pi180 = 180.0 / M_PI; + const auto Pi180 = 180.0 / std::numbers::pi; TechDraw::DrawViewDimension* dim; dim = _createLinDimension(objFeat, allVertexes[0].name, allVertexes[1].name, "DistanceY"); float xMax = std::max(abs(allVertexes[0].point.x), abs(allVertexes[1].point.x)) + 7.0; diff --git a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp index e37c3a7795..582bcfdd22 100644 --- a/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp +++ b/src/Mod/TechDraw/Gui/CommandExtensionPack.cpp @@ -2099,7 +2099,7 @@ double _getAngle(Base::Vector3d center, Base::Vector3d point) { constexpr double DegreesHalfCircle{180.0}; Base::Vector3d vecCP = point - center; - double angle = DU::angleWithX(vecCP) * DegreesHalfCircle / M_PI; + double angle = DU::angleWithX(vecCP) * DegreesHalfCircle / std::numbers::pi; return angle; } diff --git a/src/Mod/TechDraw/Gui/DimensionValidators.cpp b/src/Mod/TechDraw/Gui/DimensionValidators.cpp index 2142161701..9f24fdf162 100644 --- a/src/Mod/TechDraw/Gui/DimensionValidators.cpp +++ b/src/Mod/TechDraw/Gui/DimensionValidators.cpp @@ -386,10 +386,10 @@ DimensionGeometry TechDraw::isValidSingleEdge(const ReferenceEntry& ref) return DimensionGeometry::isInvalid; } Base::Vector3d line = gen1->points.at(1) - gen1->points.at(0); - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } return DimensionGeometry::isDiagonal; @@ -430,13 +430,13 @@ DimensionGeometry TechDraw::isValidSingleEdge3d(DrawViewPart* dvp, const Referen Base::Vector3d point1 = Base::convertTo(BRep_Tool::Pnt(TopExp::LastVertex(occEdge))); point1 = dvp->projectPoint(point1); Base::Vector3d line = point1 - point0; - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } - // else if (fabs(line.z) < FLT_EPSILON) { + // else if (fabs(line.z) < std::numeric_limits::epsilon()) { // return TechDraw::isZLimited; // } else { @@ -632,9 +632,9 @@ DimensionGeometry TechDraw::isValidVertexes(const ReferenceVector& refs) TechDraw::VertexPtr v0 = dvp->getVertex(refs.at(0).getSubName()); TechDraw::VertexPtr v1 = dvp->getVertex(refs.at(1).getSubName()); Base::Vector3d line = v1->point() - v0->point(); - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; - } else if (fabs(line.x) < FLT_EPSILON) { + } else if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; } else { return DimensionGeometry::isDiagonal; @@ -670,12 +670,12 @@ DimensionGeometry TechDraw::isValidVertexes3d(DrawViewPart* dvp, const Reference Base::Vector3d point1 = Base::convertTo(BRep_Tool::Pnt(TopoDS::Vertex(geometry1))); point1 = dvp->projectPoint(point1); Base::Vector3d line = point1 - point0; - if (fabs(line.y) < FLT_EPSILON) { + if (fabs(line.y) < std::numeric_limits::epsilon()) { return DimensionGeometry::isVertical; } - if (fabs(line.x) < FLT_EPSILON) { + if (fabs(line.x) < std::numeric_limits::epsilon()) { return DimensionGeometry::isHorizontal; - // } else if(fabs(line.z) < FLT_EPSILON) { + // } else if(fabs(line.z) < std::numeric_limits::epsilon()) { // return isZLimited; } else { return DimensionGeometry::isDiagonal; diff --git a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp index 3954090e30..a6e9dce171 100644 --- a/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp +++ b/src/Mod/TechDraw/Gui/DrawGuiUtil.cpp @@ -832,7 +832,7 @@ void DrawGuiUtil::rotateToAlign(DrawViewPart* view, const Base::Vector2d& oldDir double toRotate = newDirection.GetAngle(oldDirection); // Radians to degrees - toRotate = toRotate * 180 / M_PI; + toRotate = toRotate * 180 / std::numbers::pi; // Rotate least amount possible if(toRotate > 90) { diff --git a/src/Mod/TechDraw/Gui/PathBuilder.cpp b/src/Mod/TechDraw/Gui/PathBuilder.cpp index 2d5240baab..11e26758b3 100644 --- a/src/Mod/TechDraw/Gui/PathBuilder.cpp +++ b/src/Mod/TechDraw/Gui/PathBuilder.cpp @@ -327,11 +327,11 @@ void PathBuilder::pathArc(QPainterPath& path, double rx, double ry, double x_axi th_arc = th1 - th0; if (th_arc < 0 && sweep_flag) - th_arc += 2 * M_PI; + th_arc += 2 * std::numbers::pi; else if (th_arc > 0 && !sweep_flag) - th_arc -= 2 * M_PI; + th_arc -= 2 * std::numbers::pi; - n_segs = qCeil(qAbs(th_arc / (M_PI * 0.5 + 0.001))); + n_segs = qCeil(qAbs(th_arc / (std::numbers::pi * 0.5 + 0.001))); path.moveTo(curx, cury); diff --git a/src/Mod/TechDraw/Gui/QGIHighlight.cpp b/src/Mod/TechDraw/Gui/QGIHighlight.cpp index 165a9156e6..85d58d9ffc 100644 --- a/src/Mod/TechDraw/Gui/QGIHighlight.cpp +++ b/src/Mod/TechDraw/Gui/QGIHighlight.cpp @@ -125,7 +125,7 @@ void QGIHighlight::makeReference() QRectF r(m_start, m_end); double radius = r.width() / 2.0; QPointF center = r.center(); - double angleRad = m_referenceAngle * M_PI / 180.0; + double angleRad = m_referenceAngle * std::numbers::pi / 180.0; double posX = center.x() + cos(angleRad) * radius + horizOffset; double posY = center.y() - sin(angleRad) * radius - vertOffset; m_reference->setPos(posX, posY); diff --git a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp index 40c1e15ecd..b8e23aac6c 100644 --- a/src/Mod/TechDraw/Gui/QGILeaderLine.cpp +++ b/src/Mod/TechDraw/Gui/QGILeaderLine.cpp @@ -589,7 +589,7 @@ Base::Vector3d QGILeaderLine::getAttachPoint() double yPos = Rez::guiX(featLeader->Y.getValue()); Base::Vector3d vAttachPoint{xPos, yPos}; vAttachPoint = vAttachPoint * baseScale; - double rotationRad = parent->Rotation.getValue() * M_PI / DegreesHalfCircle; + double rotationRad = parent->Rotation.getValue() * std::numbers::pi / DegreesHalfCircle; if (rotationRad != 0.0) { vAttachPoint.RotateZ(rotationRad); } diff --git a/src/Mod/TechDraw/Gui/QGISectionLine.cpp b/src/Mod/TechDraw/Gui/QGISectionLine.cpp index 37415d4df5..c5546e85ec 100644 --- a/src/Mod/TechDraw/Gui/QGISectionLine.cpp +++ b/src/Mod/TechDraw/Gui/QGISectionLine.cpp @@ -402,9 +402,9 @@ double QGISectionLine::getArrowRotation(Base::Vector3d arrowDir) arrowDir.Normalize(); double angle = atan2f(arrowDir.y, arrowDir.x); if (angle < 0.0) { - angle = 2 * M_PI + angle; + angle = 2 * std::numbers::pi + angle; } - double arrowRotation = 360.0 - angle * (180.0/M_PI); //convert to Qt rotation (clockwise degrees) + double arrowRotation = 360.0 - angle * (180.0/std::numbers::pi); //convert to Qt rotation (clockwise degrees) return arrowRotation; } diff --git a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp index c63e7c5cdc..b1d4258814 100644 --- a/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewBalloon.cpp @@ -606,6 +606,8 @@ void QGIViewBalloon::draw() void QGIViewBalloon::drawBalloon(bool originDrag) { + using std::numbers::pi; + if ((!originDrag) && m_dragInProgress) { // TODO there are 2 drag status variables. m_draggingInProgress appears to be the one to use? // dragged shows false while drag is still in progress. @@ -696,14 +698,14 @@ void QGIViewBalloon::drawBalloon(bool originDrag) double radius = sqrt(pow((textHeight / 2.0), 2) + pow((textWidth / 2.0), 2)); radius = radius * scale; radius += Rez::guiX(3.0); - offsetLR = (tan(30 * M_PI / 180) * radius); + offsetLR = (tan(30 * pi / 180) * radius); QPolygonF triangle; - double startAngle = -M_PI / 2; + double startAngle = -pi / 2; double angle = startAngle; for (int i = 0; i < 4; i++) { triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); - angle += (2 * M_PI / 3); + angle += (2 * pi / 3); } balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); @@ -737,12 +739,12 @@ void QGIViewBalloon::drawBalloon(bool originDrag) radius += Rez::guiX(1.0); offsetLR = radius; QPolygonF triangle; - double startAngle = -2 * M_PI / 3; + double startAngle = -2 * pi / 3; double angle = startAngle; for (int i = 0; i < 7; i++) { triangle += QPointF(lblCenter.x + (radius * cos(angle)), lblCenter.y + (radius * sin(angle))); - angle += (2 * M_PI / 6); + angle += (2 * pi / 6); } balloonPath.moveTo(lblCenter.x + (radius * cos(startAngle)), lblCenter.y + (radius * sin(startAngle))); @@ -805,7 +807,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag) dirballoonLinesLine = (arrowTipPosInParent - dLineStart).Normalize(); } - float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / M_PI; + float arAngle = atan2(dirballoonLinesLine.y, dirballoonLinesLine.x) * 180 / pi; if ((endType == ArrowType::FILLED_TRIANGLE) && (prefOrthoPyramid())) { if (arAngle < 0.0) { @@ -824,7 +826,7 @@ void QGIViewBalloon::drawBalloon(bool originDrag) else { arAngle = 0; } - double radAngle = arAngle * M_PI / 180.0; + double radAngle = arAngle * pi / 180.0; double sinAngle = sin(radAngle); double cosAngle = cos(radAngle); xAdj = Rez::guiX(arrowAdj * cosAngle); diff --git a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp index 60040fbbba..27fdc744ed 100644 --- a/src/Mod/TechDraw/Gui/QGIViewDimension.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewDimension.cpp @@ -22,10 +22,6 @@ #include "PreCompiled.h" -#ifdef FC_OS_WIN32 -# define _USE_MATH_DEFINES //resolves Windows & M_PI issues -#endif - #ifndef _PreComp_ # include @@ -440,25 +436,27 @@ void QGIViewDimension::draw() double QGIViewDimension::getAnglePlacementFactor(double testAngle, double endAngle, double startRotation) { + using std::numbers::pi; + if (startRotation > 0.0) { startRotation = -startRotation; endAngle -= startRotation; - if (endAngle > M_PI) { - endAngle -= M_2PI; + if (endAngle > pi) { + endAngle -= 2 * pi; } } if (testAngle > endAngle) { - testAngle -= M_2PI; + testAngle -= 2 * pi; } if (testAngle >= endAngle + startRotation) { return +1.0; } - testAngle += M_PI; + testAngle += pi; if (testAngle > endAngle) { - testAngle -= M_2PI; + testAngle -= 2 * pi; } if (testAngle >= endAngle + startRotation) { @@ -472,7 +470,7 @@ int QGIViewDimension::compareAngleStraightness(double straightAngle, double left double rightAngle, double leftStrikeFactor, double rightStrikeFactor) { - double leftDelta = DrawUtil::angleComposition(M_PI, straightAngle - leftAngle); + double leftDelta = DrawUtil::angleComposition(std::numbers::pi, straightAngle - leftAngle); double rightDelta = DrawUtil::angleComposition(rightAngle, -straightAngle); if (fabs(leftDelta - rightDelta) <= Precision::Confusion()) { @@ -492,7 +490,7 @@ int QGIViewDimension::compareAngleStraightness(double straightAngle, double left double QGIViewDimension::getIsoStandardLinePlacement(double labelAngle) { // According to ISO 129-1 Standard Figure 23, the bordering angle is 1/2 PI, resp. -1/2 PI - return labelAngle < -M_PI / 2.0 || labelAngle > +M_PI / 2.0 ? +1.0 : -1.0; + return labelAngle < -std::numbers::pi / 2.0 || labelAngle > +std::numbers::pi / 2.0 ? +1.0 : -1.0; } Base::Vector2d QGIViewDimension::getIsoRefOutsetPoint(const Base::BoundBox2d& labelRectangle, @@ -599,7 +597,7 @@ double QGIViewDimension::computeLineAndLabelAngles(const Base::Vector2d& rotatio double devAngle = getIsoStandardLinePlacement(rawAngle) * asin(lineLabelDistance / rawDistance); lineAngle = DrawUtil::angleComposition(lineAngle, devAngle); - labelAngle = devAngle < 0.0 ? lineAngle : DrawUtil::angleComposition(lineAngle, M_PI); + labelAngle = devAngle < 0.0 ? lineAngle : DrawUtil::angleComposition(lineAngle, std::numbers::pi); return devAngle; } @@ -669,7 +667,7 @@ QGIViewDimension::computeArcStrikeFactor(const Base::BoundBox2d& labelRectangle, double arcAngle = drawMarking[startIndex].first; double arcRotation = drawMarking[currentIndex].first - arcAngle; if (arcRotation < 0.0) { - arcRotation += M_2PI; + arcRotation += 2 * std::numbers::pi; } DrawUtil::findCircularArcRectangleIntersections(arcCenter, arcRadius, arcAngle, @@ -689,7 +687,7 @@ double QGIViewDimension::normalizeStartPosition(double& startPosition, double& l { if (startPosition > 0.0) { startPosition = -startPosition; - lineAngle += M_PI; + lineAngle += std::numbers::pi; return -1.0; } @@ -872,7 +870,7 @@ bool QGIViewDimension::constructDimensionArc( // Add the arrow tails - these are drawn always double tailDelta = - arcRadius >= Precision::Confusion() ? getDefaultArrowTailLength() / arcRadius : M_PI_4; + arcRadius >= Precision::Confusion() ? getDefaultArrowTailLength() / arcRadius : std::numbers::pi / 4.0; double placementFactor = flipArrows ? +1.0 : -1.0; DrawUtil::intervalMarkCircular(outputMarking, endAngle, @@ -993,7 +991,7 @@ void QGIViewDimension::drawSingleArc(QPainterPath& painterPath, const Base::Vect return; } if (endAngle < startAngle) { - endAngle += M_2PI; + endAngle += 2 * std::numbers::pi; } QRectF qtArcRectangle( @@ -1019,7 +1017,7 @@ void QGIViewDimension::drawMultiArc(QPainterPath& painterPath, const Base::Vecto } if (entryIndex >= drawMarking.size()) { - drawSingleArc(painterPath, arcCenter, arcRadius, 0, M_2PI); + drawSingleArc(painterPath, arcCenter, arcRadius, 0, 2 * std::numbers::pi); return; } @@ -1067,7 +1065,7 @@ void QGIViewDimension::drawDimensionLine(QPainterPath& painterPath, double arrowAngles[2]; arrowAngles[0] = lineAngle; - arrowAngles[1] = lineAngle + M_PI; + arrowAngles[1] = lineAngle + std::numbers::pi; drawArrows(arrowCount, arrowPositions, arrowAngles, flipArrows, forcePointStyle); } @@ -1077,13 +1075,15 @@ void QGIViewDimension::drawDimensionArc(QPainterPath& painterPath, const Base::V double jointAngle, const Base::BoundBox2d& labelRectangle, int arrowCount, int standardStyle, bool flipArrows) const { + using std::numbers::pi; + // Keep the convention start rotation <= 0 double handednessFactor = normalizeStartRotation(startRotation); // Split the rest of 2PI minus the angle and assign joint offset so > 0 is closer to end arc side double jointRotation = handednessFactor * (jointAngle - endAngle); - if (fabs(jointRotation - startRotation * 0.5) > M_PI) { - jointRotation += jointRotation < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotation - startRotation * 0.5) > pi) { + jointRotation += jointRotation < 0.0 ? +2*pi : -2*pi; } std::vector> drawMarks; @@ -1099,8 +1099,8 @@ void QGIViewDimension::drawDimensionArc(QPainterPath& painterPath, const Base::V + Base::Vector2d::FromPolar(arcRadius, endAngle + handednessFactor * startRotation); double arrowAngles[2]; - arrowAngles[0] = endAngle + handednessFactor * M_PI_2; - arrowAngles[1] = endAngle + handednessFactor * (startRotation - M_PI_2); + arrowAngles[0] = endAngle + handednessFactor * std::numbers::pi/2; + arrowAngles[1] = endAngle + handednessFactor * (startRotation - std::numbers::pi/2); drawArrows(arrowCount, arrowPositions, arrowAngles, flipArrows); } @@ -1119,6 +1119,8 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, int standardStyle, int renderExtent, bool flipArrows) const { + using std::numbers::pi; + QPainterPath distancePath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1170,9 +1172,9 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, // Orient the leader line angle correctly towards the target point double angles[2]; angles[0] = - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; angles[1] = - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Select the placement, where the label is not obscured by the leader line // or (if both behave the same) the one that bends the reference line less @@ -1226,7 +1228,7 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, // We may rotate the label so no leader and reference lines are needed double placementFactor = getIsoStandardLinePlacement(lineAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Find out the projection of label center on the line with given angle Base::Vector2d labelProjection( @@ -1234,7 +1236,7 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, + Base::Vector2d::FromPolar( placementFactor * (labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing()), - lineAngle + M_PI_2)); + lineAngle + pi/2)); // Compute the dimensional line start and end crossings with (virtual) extension lines //check for isometric direction and if iso compute non-perpendicular intersection of dim line and ext lines @@ -1288,14 +1290,14 @@ void QGIViewDimension::drawDistanceExecutive(const Base::Vector2d& startPoint, Base::Vector2d extensionOrigin; Base::Vector2d extensionTarget(computeExtensionLinePoints( - endPoint, endCross, lineAngle + M_PI_2, getDefaultExtensionLineOverhang(), gapSize, + endPoint, endCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin)); //draw 1st extension line distancePath.moveTo(toQtGui(extensionOrigin)); distancePath.lineTo(toQtGui(extensionTarget)); if (arrowCount > 1) { - extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + M_PI_2, + extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin); //draw second extension line @@ -1320,6 +1322,8 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, int standardStyle, int renderExtent, bool flipArrows, double extensionAngle) const { + using std::numbers::pi; + QPainterPath distancePath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1377,9 +1381,9 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, // Orient the leader line angle correctly towards the target point double angles[2]; angles[0] = - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; angles[1] = - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Select the placement, where the label is not obscured by the leader line // or (if both behave the same) the one that bends the reference line less @@ -1436,7 +1440,7 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, // We may rotate the label so no leader and reference lines are needed double placementFactor = getIsoStandardLinePlacement(lineAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, M_PI) : lineAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(lineAngle, pi) : lineAngle; // Find out the projection of label center on the line with given angle Base::Vector2d labelProjection( @@ -1444,7 +1448,7 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, + Base::Vector2d::FromPolar( placementFactor * (labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing()), - lineAngle + M_PI_2)); + lineAngle + std::numbers::pi/2)); // Compute the dimensional line start and end crossings with (virtual) extension lines startCross = @@ -1499,14 +1503,14 @@ void QGIViewDimension::drawDistanceOverride(const Base::Vector2d& startPoint, Base::Vector2d extensionOrigin; Base::Vector2d extensionTarget(computeExtensionLinePoints( - endPoint, endCross, lineAngle + M_PI_2, getDefaultExtensionLineOverhang(), gapSize, + endPoint, endCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin)); //draw 1st extension line distancePath.moveTo(toQtGui(extensionOrigin)); distancePath.lineTo(toQtGui(extensionTarget)); if (arrowCount > 1) { - extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + M_PI_2, + extensionTarget = computeExtensionLinePoints(startPoint, startCross, lineAngle + std::numbers::pi/2, getDefaultExtensionLineOverhang(), gapSize, extensionOrigin); //draw second extension line @@ -1528,6 +1532,8 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, double centerOverhang, int standardStyle, int renderExtent, bool flipArrow) const { + using std::numbers::pi; + QPainterPath radiusPath; Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1558,10 +1564,10 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Orient the leader line angle correctly towards the point on arc if (angleFactors[0] < 0.0) { - lineAngles[0] = DrawUtil::angleComposition(lineAngles[0], M_PI); + lineAngles[0] = DrawUtil::angleComposition(lineAngles[0], pi); } if (angleFactors[1] < 0.0) { - lineAngles[1] = DrawUtil::angleComposition(lineAngles[1], M_PI); + lineAngles[1] = DrawUtil::angleComposition(lineAngles[1], pi); } // Find the positions where the reference line attaches to the dimension line @@ -1600,9 +1606,9 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, if (compareAngleStraightness( 0.0, - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], M_PI) + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], pi) : lineAngles[0], - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], M_PI) + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], pi) : lineAngles[1], strikeFactors[0], strikeFactors[1]) > 0) { @@ -1653,7 +1659,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Is there point on the arc, where line from center intersects it perpendicularly? double angleFactor = getAnglePlacementFactor(lineAngle, endAngle, startRotation); if (angleFactor < 0.0) { - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); } Base::Vector2d arcPoint; @@ -1673,7 +1679,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing(), lineAngle, labelAngle); - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); labelPosition = -cos(devAngle) * ((labelCenter - arcPoint).Length()); } @@ -1693,7 +1699,7 @@ void QGIViewDimension::drawRadiusExecutive(const Base::Vector2d& centerPoint, // Is there point on the arc, where line from center intersects it perpendicularly? double angleFactor = getAnglePlacementFactor(lineAngle, endAngle, startRotation); if (angleFactor < 0) { - lineAngle = DrawUtil::angleComposition(lineAngle, M_PI); + lineAngle = DrawUtil::angleComposition(lineAngle, pi); } Base::Vector2d arcPoint; @@ -1779,7 +1785,7 @@ void QGIViewDimension::drawAreaExecutive(const Base::Vector2d& centerPoint, doub labelRectangle.Height() * 0.5 + getIsoDimensionLineSpacing(), lineAngle, labelAngle); - lineAngle = lineAngle - M_PI; + lineAngle = lineAngle - std::numbers::pi; double labelPosition = -cos(devAngle) * ((labelCenter - centerPoint).Length()); drawDimensionLine(areaPath, centerPoint, lineAngle, 0.0, labelPosition, labelRectangle, 1, standardStyle, flipArrow, forcePointStyle); @@ -1818,7 +1824,7 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, lineAngle = 0.0; } else if (strcmp(dimensionType, "DistanceY") == 0) { - lineAngle = M_PI_2; + lineAngle = std::numbers::pi/2; } else { lineAngle = (fromQtApp(linePoints.second()) - fromQtApp(linePoints.first())).Angle(); @@ -1831,9 +1837,9 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, if (dimension->AngleOverride.getValue()) { drawDistanceOverride(fromQtApp(linePoints.first()), fromQtApp(linePoints.second()), - dimension->LineAngle.getValue() * M_PI / 180.0, labelRectangle, + dimension->LineAngle.getValue() * std::numbers::pi / 180.0, labelRectangle, standardStyle, renderExtent, flipArrows, - dimension->ExtensionAngle.getValue() * M_PI / 180.0); + dimension->ExtensionAngle.getValue() * std::numbers::pi / 180.0); } else { drawDistanceExecutive(fromQtApp(linePoints.extensionLineFirst()), fromQtApp(linePoints.extensionLineSecond()), @@ -1844,6 +1850,8 @@ void QGIViewDimension::drawDistance(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + Base::BoundBox2d labelRectangle( fromQtGui(mapRectFromItem(datumLabel, datumLabel->tightBoundingRect()))); arcPoints curvePoints = dimension->getArcPoints(); @@ -1858,12 +1866,12 @@ void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, - endAngle; if (startRotation != 0.0 && ((startRotation > 0.0) != curvePoints.arcCW)) { - startRotation += curvePoints.arcCW ? +M_2PI : -M_2PI; + startRotation += curvePoints.arcCW ? +2*pi : -2*pi; } } else {// A circle arc covers the whole plane - endAngle = M_PI; - startRotation = -M_2PI; + endAngle = pi; + startRotation = -2*pi; } drawRadiusExecutive( @@ -1875,6 +1883,8 @@ void QGIViewDimension::drawRadius(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + Base::BoundBox2d labelRectangle( fromQtGui(mapRectFromItem(datumLabel, datumLabel->tightBoundingRect()))); Base::Vector2d labelCenter(labelRectangle.GetCenter()); @@ -1941,9 +1951,9 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, int selected = 0; if (compareAngleStraightness( 0.0, - jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], M_PI) + jointPositions[0] > 0.0 ? DrawUtil::angleComposition(lineAngles[0], pi) : lineAngles[0], - jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], M_PI) + jointPositions[1] > 0.0 ? DrawUtil::angleComposition(lineAngles[1], pi) : lineAngles[1], strikeFactors[0], strikeFactors[1]) > 0) { @@ -2006,8 +2016,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, Base::Vector2d startPoint(curveCenter); Base::Vector2d endPoint(curveCenter); - if ((lineAngle >= M_PI_4 && lineAngle <= 3.0 * M_PI_4) - || (lineAngle <= -M_PI_4 && lineAngle >= -3.0 * M_PI_4)) { + if ((lineAngle >= pi/4 && lineAngle <= 3.0 * pi/4) + || (lineAngle <= -pi/4 && lineAngle >= -3.0 * pi/4)) { // Horizontal dimension line startPoint.x -= curveRadius; endPoint.x += curveRadius; @@ -2016,10 +2026,10 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, else {// Vertical dimension line startPoint.y -= curveRadius; endPoint.y += curveRadius; - lineAngle = M_PI_2; + lineAngle = pi/2; } - // lineAngle = DrawUtil::angleComposition((labelCenter - curveCenter).Angle(), +M_PI_2); + // lineAngle = DrawUtil::angleComposition((labelCenter - curveCenter).Angle(), +pi/2); // startPoint = curveCenter - Base::Vector2d::FromPolar(curveRadius, lineAngle); // endPoint = curveCenter + Base::Vector2d::FromPolar(curveRadius, lineAngle); @@ -2031,8 +2041,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, ? ViewProviderDimension::REND_EXTENT_REDUCED : ViewProviderDimension::REND_EXTENT_NORMAL; - drawRadiusExecutive(curveCenter, Rez::guiX(curvePoints.midArc, true), curveRadius, M_PI, - -M_2PI, labelRectangle, getDefaultExtensionLineOverhang(), + drawRadiusExecutive(curveCenter, Rez::guiX(curvePoints.midArc, true), curveRadius, pi, + -2*pi, labelRectangle, getDefaultExtensionLineOverhang(), standardStyle, renderExtent, flipArrows); } } @@ -2040,6 +2050,8 @@ void QGIViewDimension::drawDiameter(TechDraw::DrawViewDimension* dimension, void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, ViewProviderDimension* viewProvider) const { + using std::numbers::pi; + QPainterPath anglePath; Base::BoundBox2d labelRectangle( @@ -2105,11 +2117,11 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, jointRotations[1] = handednessFactor * (jointAngles[1] - endAngle); // Compare the offset with half of the rest of 2PI minus the angle and eventually fix the values - if (fabs(jointRotations[0] - startRotation * 0.5) > M_PI) { - jointRotations[0] += jointRotations[0] < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotations[0] - startRotation * 0.5) > pi) { + jointRotations[0] += jointRotations[0] < 0.0 ? +2*pi : -2*pi; } - if (fabs(jointRotations[1] - startRotation * 0.5) > M_PI) { - jointRotations[1] += jointRotations[1] < 0.0 ? +M_2PI : -M_2PI; + if (fabs(jointRotations[1] - startRotation * 0.5) > pi) { + jointRotations[1] += jointRotations[1] < 0.0 ? +2*pi : -2*pi; } // Compute the strike factors so we can choose the placement where value is not obscured by dimensional arc @@ -2133,9 +2145,9 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, if (compareAngleStraightness( 0.0, DrawUtil::angleComposition( - jointAngles[0], handednessFactor * jointRotations[0] > 0.0 ? -M_PI_2 : +M_PI_2), + jointAngles[0], handednessFactor * jointRotations[0] > 0.0 ? -pi/2 : +pi/2), DrawUtil::angleComposition( - jointAngles[1], handednessFactor * jointRotations[1] > 0.0 ? -M_PI_2 : +M_PI_2), + jointAngles[1], handednessFactor * jointRotations[1] > 0.0 ? -pi/2 : +pi/2), strikeFactors[0], strikeFactors[1]) > 0) { selected = 1; @@ -2160,10 +2172,10 @@ void QGIViewDimension::drawAngle(TechDraw::DrawViewDimension* dimension, Base::Vector2d labelDirection(labelCenter - angleVertex); double radiusAngle = labelDirection.Angle(); - labelAngle = DrawUtil::angleComposition(radiusAngle, M_PI_2); + labelAngle = DrawUtil::angleComposition(radiusAngle, pi/2); double placementFactor = getIsoStandardLinePlacement(labelAngle); labelAngle = - placementFactor > 0.0 ? DrawUtil::angleComposition(labelAngle, M_PI) : labelAngle; + placementFactor > 0.0 ? DrawUtil::angleComposition(labelAngle, pi) : labelAngle; arcRadius = labelDirection.Length() - placementFactor @@ -2290,22 +2302,23 @@ Base::Vector3d QGIViewDimension::findIsoExt(Base::Vector3d dir) const Base::Vector3d isoYr(0.866, -0.5, 0.0); //iso +Y? Base::Vector3d isoZ(0.0, 1.0, 0.0); //iso Z Base::Vector3d isoZr(0.0, -1.0, 0.0); //iso -Z - if (dir.IsEqual(isoX, FLT_EPSILON)) { + constexpr float floatEpsilon = std::numeric_limits::epsilon(); + if (dir.IsEqual(isoX, floatEpsilon)) { return isoY; } - else if (dir.IsEqual(-isoX, FLT_EPSILON)) { + else if (dir.IsEqual(-isoX, floatEpsilon)) { return -isoY; } - else if (dir.IsEqual(isoY, FLT_EPSILON)) { + else if (dir.IsEqual(isoY, floatEpsilon)) { return isoZ; } - else if (dir.IsEqual(-isoY, FLT_EPSILON)) { + else if (dir.IsEqual(-isoY, floatEpsilon)) { return -isoZ; } - else if (dir.IsEqual(isoZ, FLT_EPSILON)) { + else if (dir.IsEqual(isoZ, floatEpsilon)) { return isoX; } - else if (dir.IsEqual(-isoZ, FLT_EPSILON)) { + else if (dir.IsEqual(-isoZ, floatEpsilon)) { return -isoX; } @@ -2454,11 +2467,11 @@ void QGIViewDimension::setPens() aHead2->setWidth(m_lineWidth); } -double QGIViewDimension::toDeg(double angle) { return angle * 180 / M_PI; } +double QGIViewDimension::toDeg(double angle) { return angle * 180 / std::numbers::pi; } double QGIViewDimension::toQtRad(double angle) { return -angle; } -double QGIViewDimension::toQtDeg(double angle) { return -angle * 180.0 / M_PI; } +double QGIViewDimension::toQtDeg(double angle) { return -angle * 180.0 / std::numbers::pi; } void QGIViewDimension::makeMarkC(double xPos, double yPos, QColor color) const { diff --git a/src/Mod/TechDraw/Gui/QGIViewPart.cpp b/src/Mod/TechDraw/Gui/QGIViewPart.cpp index d0259a66bb..30d395be52 100644 --- a/src/Mod/TechDraw/Gui/QGIViewPart.cpp +++ b/src/Mod/TechDraw/Gui/QGIViewPart.cpp @@ -964,7 +964,7 @@ void QGIViewPart::drawHighlight(TechDraw::DrawViewDetail* viewDetail, bool b) highlight->setPos(0.0, 0.0);//sb setPos(center.x, center.y)? Base::Vector3d center = viewDetail->AnchorPoint.getValue() * viewPart->getScale(); - double rotationRad = viewPart->Rotation.getValue() * M_PI / 180.0; + double rotationRad = viewPart->Rotation.getValue() * std::numbers::pi / 180.0; center.RotateZ(rotationRad); double radius = viewDetail->Radius.getValue() * viewPart->getScale(); diff --git a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp index 436fcfac3e..51e785053c 100644 --- a/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp +++ b/src/Mod/TechDraw/Gui/QGIWeldSymbol.cpp @@ -549,7 +549,7 @@ std::pair QGIWeldSymbol::getLocalAxes() { auto localX = getLeader()->lastSegmentDirection(); auto localY = DU::invertY(localX); - localY.RotateZ(M_PI_2); + localY.RotateZ(std::numbers::pi/2); localY.Normalize(); localY = DU::invertY(localY); return {localX, localY}; diff --git a/src/Mod/TechDraw/Gui/QGTracker.cpp b/src/Mod/TechDraw/Gui/QGTracker.cpp index 8f796a33c9..c1313ded2b 100644 --- a/src/Mod/TechDraw/Gui/QGTracker.cpp +++ b/src/Mod/TechDraw/Gui/QGTracker.cpp @@ -54,7 +54,8 @@ using namespace TechDrawGui; QGTracker::QGTracker(QGSPage* inScene, TrackerMode m): m_sleep(false), m_qgParent(nullptr), - m_lastClick(QPointF(FLT_MAX, FLT_MAX)) + m_lastClick(QPointF(std::numeric_limits::max(), + std::numeric_limits::max())) { setTrackerMode(m); if (inScene) { @@ -183,7 +184,7 @@ QPointF QGTracker::snapToAngle(QPointF dumbPt) return dumbPt; QPointF result(dumbPt); - double angleIncr = M_PI / 8.0; //15* + double angleIncr = std::numbers::pi / 8.0; //15* //mirror last clicked point and event point to get sensible coords QPointF last(m_points.back().x(), -m_points.back().y()); QPointF pt(dumbPt.x(), -dumbPt.y()); @@ -192,7 +193,7 @@ QPointF QGTracker::snapToAngle(QPointF dumbPt) QPointF qVec = last - pt; //vec from end of track to end of tail double actual = atan2(-qVec.y(), qVec.x()); if (actual < 0.0) { - actual = (2 * M_PI) + actual; //map to +ve angle + actual = (2 * std::numbers::pi) + actual; //map to +ve angle } double intPart; diff --git a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp index 30eab5653a..c19a4a500d 100644 --- a/src/Mod/TechDraw/Gui/TaskComplexSection.cpp +++ b/src/Mod/TechDraw/Gui/TaskComplexSection.cpp @@ -24,6 +24,7 @@ #ifndef _PreComp_ #include #include +#include #endif// #ifndef _PreComp_ #include @@ -193,7 +194,7 @@ void TaskComplexSection::setUiEdit() ui->leBaseView->setText(QString::fromStdString(m_baseView->getNameInDocument())); Base::Vector3d projectedViewDirection = m_baseView->projectPoint(sectionNormalVec, false); double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); m_viewDirectionWidget->setValueNoNotify(projectedViewDirection * -1.0); } else { @@ -308,7 +309,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) } projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); checkAll(false); applyAligned(); } @@ -318,7 +319,7 @@ void TaskComplexSection::slotViewDirectionChanged(Base::Vector3d newDirection) void TaskComplexSection::slotChangeAngle(double newAngle) { // Base::Console().Message("TCS::slotAngleChanged(%.3f)\n", newAngle); - double angleRadians = newAngle * M_PI / 180.0; + double angleRadians = newAngle * std::numbers::pi / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); Base::Vector3d localUnit(unitX, unitY, 0.0); diff --git a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp index 5b83340515..11cea7d77a 100644 --- a/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp +++ b/src/Mod/TechDraw/Gui/TaskCosmeticLine.cpp @@ -113,7 +113,7 @@ void TaskCosmeticLine::setUiPrimary() setWindowTitle(QObject::tr("Create Cosmetic Line")); // double rotDeg = m_partFeat->Rotation.getValue(); - // double rotRad = rotDeg * M_PI / 180.0; + // double rotRad = rotDeg * std::numbers::pi / 180.0; Base::Vector3d centroid = m_partFeat->getCurrentCentroid(); Base::Vector3d p1, p2; if (m_is3d.front()) { diff --git a/src/Mod/TechDraw/Gui/TaskDimension.cpp b/src/Mod/TechDraw/Gui/TaskDimension.cpp index 4da35c5c67..f3794c9c9c 100644 --- a/src/Mod/TechDraw/Gui/TaskDimension.cpp +++ b/src/Mod/TechDraw/Gui/TaskDimension.cpp @@ -227,7 +227,7 @@ void TaskDimension::onEqualToleranceChanged() ui->leFormatSpecifierUnderTolerance->setDisabled(true); } else { - ui->qsbOvertolerance->setMinimum(-DBL_MAX); + ui->qsbOvertolerance->setMinimum(-std::numeric_limits::max()); if (!ui->cbTheoreticallyExact->isChecked()) { ui->qsbUndertolerance->setDisabled(false); ui->leFormatSpecifierUnderTolerance->setDisabled(false); @@ -372,14 +372,14 @@ void TaskDimension::onDimUseDefaultClicked() Base::Vector2d first2(points.first().x, -points.first().y); Base::Vector2d second2(points.second().x, -points.second().y); double lineAngle = (second2 - first2).Angle(); - ui->dsbDimAngle->setValue(lineAngle * 180.0 / M_PI); + ui->dsbDimAngle->setValue(lineAngle * 180.0 / std::numbers::pi); } void TaskDimension::onDimUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbDimAngle->setValue(result.first * 180.0 / M_PI); + ui->dsbDimAngle->setValue(result.first * 180.0 / std::numbers::pi); } } @@ -392,13 +392,13 @@ void TaskDimension::onExtUseDefaultClicked() Base::Vector2d lineDirection = second2 - first2; Base::Vector2d extensionDirection(-lineDirection.y, lineDirection.x); double extensionAngle = extensionDirection.Angle(); - ui->dsbExtAngle->setValue(extensionAngle * 180.0 / M_PI); + ui->dsbExtAngle->setValue(extensionAngle * 180.0 / std::numbers::pi); } void TaskDimension::onExtUseSelectionClicked() { std::pair result = getAngleFromSelection(); if (result.second) { - ui->dsbExtAngle->setValue(result.first * 180.0 / M_PI); + ui->dsbExtAngle->setValue(result.first * 180.0 / std::numbers::pi); } } diff --git a/src/Mod/TechDraw/Gui/TaskSectionView.cpp b/src/Mod/TechDraw/Gui/TaskSectionView.cpp index 8cceb4eea7..3169ff543e 100644 --- a/src/Mod/TechDraw/Gui/TaskSectionView.cpp +++ b/src/Mod/TechDraw/Gui/TaskSectionView.cpp @@ -180,7 +180,7 @@ void TaskSectionView::setUiEdit() Base::Vector3d projectedViewDirection = m_base->projectPoint(sectionNormalVec, false); projectedViewDirection.Normalize(); double viewAngle = atan2(-projectedViewDirection.y, -projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); m_viewDirectionWidget->setValueNoNotify(sectionNormalVec * -1.0); } @@ -272,7 +272,7 @@ void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) Base::Vector3d projectedViewDirection = m_base->projectPoint(newDirection, false); projectedViewDirection.Normalize(); double viewAngle = atan2(projectedViewDirection.y, projectedViewDirection.x); - m_compass->setDialAngle(viewAngle * 180.0 / M_PI); + m_compass->setDialAngle(viewAngle * 180.0 / std::numbers::pi); checkAll(false); directionChanged(true); applyAligned(); @@ -281,7 +281,7 @@ void TaskSectionView::slotViewDirectionChanged(Base::Vector3d newDirection) //the CompassWidget reports that the view direction angle has changed void TaskSectionView::slotChangeAngle(double newAngle) { - double angleRadians = newAngle * M_PI / 180.0; + double angleRadians = newAngle * std::numbers::pi / 180.0; double unitX = cos(angleRadians); double unitY = sin(angleRadians); Base::Vector3d localUnit(unitX, unitY, 0.0); diff --git a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp index 8359f8a490..6a18181eb5 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderCosmeticExtension.cpp @@ -24,10 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ -# ifdef _MSC_VER -# define _USE_MATH_DEFINES -# include -# endif //_MSC_VER +# include #endif #include diff --git a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp index c186079a6c..311e885f5d 100644 --- a/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp +++ b/src/Mod/TechDraw/Gui/ViewProviderDrawingView.cpp @@ -28,7 +28,6 @@ #include #endif -#include #include #include @@ -404,7 +403,7 @@ void ViewProviderDrawingView::stackTop() //no view, nothing to stack return; } - int maxZ = INT_MIN; + int maxZ = std::numeric_limits::min(); auto parent = qView->parentItem(); if (parent) { //if we have a parentItem, we have to stack within the parentItem, not within the page @@ -439,7 +438,7 @@ void ViewProviderDrawingView::stackBottom() //no view, nothing to stack return; } - int minZ = INT_MAX; + int minZ = std::numeric_limits::max(); auto parent = qView->parentItem(); if (parent) { //if we have a parentItem, we have to stack within the parentItem, not within the page diff --git a/src/Mod/Web/App/AppWeb.cpp b/src/Mod/Web/App/AppWeb.cpp index d89e3ef568..54b2a9ebbc 100644 --- a/src/Mod/Web/App/AppWeb.cpp +++ b/src/Mod/Web/App/AppWeb.cpp @@ -89,7 +89,7 @@ private: if (!PyArg_ParseTuple(args.ptr(), "|si", &addr, &port)) { throw Py::Exception(); } - if (port > USHRT_MAX) { + if (port > std::numeric_limits::max()) { throw Py::OverflowError("port number is greater than maximum"); } else if (port < 0) { @@ -121,7 +121,7 @@ private: if (!PyArg_ParseTuple(args.ptr(), "|sii", &addr, &port, &timeout)) { throw Py::Exception(); } - if (port > USHRT_MAX) { + if (port > std::numeric_limits::max()) { throw Py::OverflowError("port number is greater than maximum"); } else if (port < 0) { diff --git a/src/Tools/plugins/widget/customwidgets.cpp b/src/Tools/plugins/widget/customwidgets.cpp index 0f9107619a..b5e5dec404 100644 --- a/src/Tools/plugins/widget/customwidgets.cpp +++ b/src/Tools/plugins/widget/customwidgets.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include "customwidgets.h" @@ -449,8 +448,8 @@ ActionSelector::~ActionSelector() InputField::InputField(QWidget* parent) : QLineEdit(parent) , Value(0) - , Maximum(INT_MAX) - , Minimum(-INT_MAX) + , Maximum(std::numeric_limits::max()) + , Minimum(-std::numeric_limits::max()) , StepSize(1.0) , HistorySize(5) {} @@ -671,8 +670,8 @@ public: : validInput(true) , pendingEmit(false) , unitValue(0) - , maximum(INT_MAX) - , minimum(-INT_MAX) + , maximum(std::numeric_limits::max()) + , minimum(-std::numeric_limits::max()) , singleStep(1.0) {} ~QuantitySpinBoxPrivate() @@ -1459,7 +1458,7 @@ UnsignedValidator::UnsignedValidator(QObject* parent) : QValidator(parent) { b = 0; - t = UINT_MAX; + t = std::numeric_limits::max(); } UnsignedValidator::UnsignedValidator(uint minimum, uint maximum, QObject* parent) @@ -1522,39 +1521,41 @@ public: {} uint mapToUInt(int v) const { + using limits = std::numeric_limits; uint ui; - if (v == INT_MIN) { + if (v == limits::min()) { ui = 0; } - else if (v == INT_MAX) { - ui = UINT_MAX; + else if (v == limits::max()) { + ui = limits::max(); } else if (v < 0) { - v -= INT_MIN; - ui = (uint)v; + v -= limits::min(); + ui = static_cast(v); } else { - ui = (uint)v; - ui -= INT_MIN; + ui = static_cast(v); + ui -= limits::min(); } return ui; } int mapToInt(uint v) const { + using limits = std::numeric_limits; int in; - if (v == UINT_MAX) { - in = INT_MAX; + if (v == limits::max()) { + in = limits::max(); } else if (v == 0) { - in = INT_MIN; + in = limits::min(); } - else if (v > INT_MAX) { - v += INT_MIN; - in = (int)v; + else if (v > limits::max()) { + v += limits::min(); + in = static_cast(v); } else { in = v; - in += INT_MIN; + in += limits::min(); } return in; } diff --git a/tests/src/Base/Tools.cpp b/tests/src/Base/Tools.cpp index 6bcb0b4c0b..39fc056fd9 100644 --- a/tests/src/Base/Tools.cpp +++ b/tests/src/Base/Tools.cpp @@ -39,16 +39,16 @@ TEST(Tools, TestSignum) TEST(Tools, TestRadian) { EXPECT_EQ(Base::toRadians(90), 1); - EXPECT_DOUBLE_EQ(Base::toRadians(180), M_PI); - EXPECT_DOUBLE_EQ(Base::toRadians(90.0), M_PI / 2.0); + EXPECT_DOUBLE_EQ(Base::toRadians(180), std::numbers::pi); + EXPECT_DOUBLE_EQ(Base::toRadians(90.0), std::numbers::pi / 2.0); EXPECT_DOUBLE_EQ(Base::toRadians(0.0), 0.0); } TEST(Tools, TestDegree) { EXPECT_EQ(Base::toDegrees(3), 171); - EXPECT_DOUBLE_EQ(Base::toDegrees(M_PI), 180.0); - EXPECT_DOUBLE_EQ(Base::toDegrees(M_PI / 2.0), 90.0); + EXPECT_DOUBLE_EQ(Base::toDegrees(std::numbers::pi), 180.0); + EXPECT_DOUBLE_EQ(Base::toDegrees(std::numbers::pi / 2.0), 90.0); EXPECT_DOUBLE_EQ(Base::toDegrees(0.0), 0.0); } diff --git a/tests/src/Mod/Part/App/FeatureExtrusion.cpp b/tests/src/Mod/Part/App/FeatureExtrusion.cpp index 4529d7def6..18c017f0a3 100644 --- a/tests/src/Mod/Part/App/FeatureExtrusion.cpp +++ b/tests/src/Mod/Part/App/FeatureExtrusion.cpp @@ -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("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); } diff --git a/tests/src/Mod/Part/App/FeatureRevolution.cpp b/tests/src/Mod/Part/App/FeatureRevolution.cpp index 38eeafa562..90247e11b3 100644 --- a/tests/src/Mod/Part/App/FeatureRevolution.cpp +++ b/tests/src/Mod/Part/App/FeatureRevolution.cpp @@ -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("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(); diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 81a2f4ee5a..ba6046852f 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -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 subShapes = cube1TS.getSubTopoShapes(TopAbs_FACE); std::vector 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 diff --git a/tests/src/Mod/Sketcher/App/SketchObject.cpp b/tests/src/Mod/Sketcher/App/SketchObject.cpp index 954308353c..36c1db0f26 100644 --- a/tests/src/Mod/Sketcher/App/SketchObject.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObject.cpp @@ -237,7 +237,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfCircle) { // Arrange Base::Vector3d coordsCenter(1.0, 2.0, 0.0); - double radius = 3.0, startParam = M_PI / 3, endParam = M_PI * 1.5; + double radius = 3.0, startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); @@ -267,7 +267,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfEllipse) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfEllipse arcOfEllipse; arcOfEllipse.setCenter(coordsCenter); arcOfEllipse.setMajorRadius(majorRadius); @@ -298,7 +298,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfHyperbola) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfHyperbola arcOfHyperbola; arcOfHyperbola.setCenter(coordsCenter); arcOfHyperbola.setMajorRadius(majorRadius); @@ -330,7 +330,7 @@ TEST_F(SketchObjectTest, testGetPointFromGeomArcOfParabola) // Arrange Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double focal = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; Part::GeomArcOfParabola arcOfParabola; arcOfParabola.setCenter(coordsCenter); arcOfParabola.setFocal(focal); diff --git a/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp b/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp index 2b0f69aa76..5d2519bea6 100644 --- a/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp +++ b/tests/src/Mod/Sketcher/App/SketchObjectChanges.cpp @@ -846,7 +846,7 @@ TEST_F(SketchObjectTest, testJoinCurves) // Arrange // Make two curves Base::Vector3d coordsCenter(0.0, 0.0, 0.0); - double radius = 3.0, startParam = M_PI / 2, endParam = M_PI; + double radius = 3.0, startParam = std::numbers::pi / 2, endParam = std::numbers::pi; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); @@ -877,7 +877,7 @@ TEST_F(SketchObjectTest, testJoinCurvesWhenTangent) // Arrange // Make two curves Base::Vector3d coordsCenter(0.0, 0.0, 0.0); - double radius = 3.0, startParam = M_PI / 2, endParam = M_PI; + double radius = 3.0, startParam = std::numbers::pi / 2, endParam = std::numbers::pi; Part::GeomArcOfCircle arcOfCircle; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); diff --git a/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp b/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp index ae4fb2414e..51aade677f 100644 --- a/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp +++ b/tests/src/Mod/Sketcher/App/SketcherTestHelpers.cpp @@ -56,7 +56,7 @@ void setupArcOfCircle(Part::GeomArcOfCircle& arcOfCircle) { Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double radius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; arcOfCircle.setCenter(coordsCenter); arcOfCircle.setRadius(radius); arcOfCircle.setRange(startParam, endParam, true); @@ -77,7 +77,7 @@ void setupArcOfHyperbola(Part::GeomArcOfHyperbola& arcOfHyperbola) Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double majorRadius = 4.0; double minorRadius = 3.0; - double startParam = M_PI / 3, endParam = M_PI * 1.5; + double startParam = std::numbers::pi / 3, endParam = std::numbers::pi * 1.5; arcOfHyperbola.setCenter(coordsCenter); arcOfHyperbola.setMajorRadius(majorRadius); arcOfHyperbola.setMinorRadius(minorRadius); @@ -88,7 +88,7 @@ void setupArcOfParabola(Part::GeomArcOfParabola& aop) { Base::Vector3d coordsCenter(1.0, 2.0, 0.0); double focal = 3.0; - double startParam = -M_PI * 1.5, endParam = M_PI * 1.5; + double startParam = -std::numbers::pi * 1.5, endParam = std::numbers::pi * 1.5; aop.setCenter(coordsCenter); aop.setFocal(focal); aop.setRange(startParam, endParam, true); diff --git a/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp b/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp index 4f0b90b997..89cb81dc12 100644 --- a/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp +++ b/tests/src/Mod/Sketcher/App/planegcs/Constraints.cpp @@ -1,6 +1,7 @@ // SPDX-License-Identifier: LGPL-2.1-or-later #include +#include #include @@ -54,8 +55,8 @@ TEST_F(ConstraintsTest, tangentBSplineAndArc) // NOLINT arcEnd.y = &arcEndY; arcCenter.x = &arcCenterX; arcCenter.y = &arcCenterY; - double arcRadius = 5.0, arcStartAngle = 0.0, arcEndAngle = M_PI / 2; - double desiredAngle = M_PI; + double arcRadius = 5.0, arcStartAngle = 0.0, arcEndAngle = std::numbers::pi / 2; + double desiredAngle = std::numbers::pi; double bSplineStartX = 0.0, bSplineEndX = 16.0; double bSplineStartY = 10.0, bSplineEndY = -10.0; GCS::Point bSplineStart, bSplineEnd;