Merge pull request #20496 from hyarion/refactor/cppify-constants

This commit is contained in:
Chris Hennes
2025-03-29 18:43:40 -05:00
committed by GitHub
322 changed files with 1791 additions and 1654 deletions

View File

@@ -34,6 +34,8 @@
#include <boost/math/special_functions/round.hpp>
#include <boost/math/special_functions/trunc.hpp>
#include <numbers>
#include <limits>
#include <sstream>
#include <stack>
#include <string>
@@ -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<int>::min()) {
i = static_cast<int>(intpart);
l = i;
return 1;
}
if (intpart >= LONG_MIN) {
if (intpart >= std::numeric_limits<long>::min()) {
l = static_cast<long>(intpart);
return 2;
}
}
else if (intpart <= INT_MAX) {
else if (intpart <= std::numeric_limits<int>::max()) {
i = static_cast<int>(intpart);
l = i;
return 1;
}
else if (intpart <= static_cast<double>(LONG_MAX)) {
else if (intpart <= static_cast<double>(std::numeric_limits<long>::max())) {
l = static_cast<int>(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<long>::min()) {
l = static_cast<long>(intpart);
return true;
}
}
else if (intpart <= static_cast<double>(LONG_MAX)) {
else if (intpart <= static_cast<double>(std::numeric_limits<long>::max())) {
l = static_cast<long>(intpart);
return true;
}
@@ -2145,6 +2134,8 @@ Base::Vector3d FunctionExpression::extractVectorArgument(
Py::Object FunctionExpression::evaluate(const Expression *expr, int f, const std::vector<Expression*> &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<Base::MatrixPy*>(pyobj.ptr())->value();
if (fabs(m.determinant()) <= DBL_EPSILON)
if (fabs(m.determinant()) <= std::numeric_limits<double>::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<double>(f == MROTATEX), static_cast<double>(f == MROTATEY), static_cast<double>(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())