App: Use std::numeric_limits and std::numbers instead of defines
This commit is contained in:
@@ -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::SetupData>& LocalCoordinateSystem::getSetupData()
|
||||
{
|
||||
using std::numbers::pi;
|
||||
|
||||
static const std::vector<SetupData> 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
|
||||
};
|
||||
|
||||
@@ -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>
|
||||
@@ -62,19 +64,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)
|
||||
@@ -336,22 +325,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;
|
||||
}
|
||||
@@ -363,12 +352,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;
|
||||
}
|
||||
@@ -2150,6 +2139,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);
|
||||
|
||||
@@ -2186,7 +2177,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));
|
||||
@@ -2227,7 +2218,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);
|
||||
|
||||
@@ -2366,7 +2357,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:
|
||||
@@ -2425,7 +2416,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:
|
||||
@@ -2434,7 +2425,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:
|
||||
@@ -2466,7 +2457,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())
|
||||
|
||||
@@ -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<long long>::min)
|
||||
throw Base::UnderflowError("Integer underflow");
|
||||
else if (yylval.ivalue == LLONG_MAX)
|
||||
else if (yylval.ivalue == std::numeric_limits<long long>::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;
|
||||
|
||||
@@ -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<int>::max(), 1};
|
||||
ElementCount.setConstraints(&s_constraints);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<int>::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<int>::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<int>::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<int>::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<int>::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<int>::max()) {
|
||||
ss << begin;
|
||||
}
|
||||
ss << ':';
|
||||
if (end != INT_MAX) {
|
||||
if (end != std::numeric_limits<int>::max()) {
|
||||
ss << end;
|
||||
}
|
||||
if (step != 1) {
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
|
||||
#include <bitset>
|
||||
#include <map>
|
||||
#include <limits>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -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<int>::max(),
|
||||
int end = std::numeric_limits<int>::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<int>::max(),
|
||||
int end = std::numeric_limits<int>::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<int>::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<int>::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<int>::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<int>::max()); // explicit bombs
|
||||
|
||||
FC_DEFAULT_CTORS(ObjectIdentifier)
|
||||
{
|
||||
|
||||
@@ -50,7 +50,6 @@
|
||||
#include <csignal>
|
||||
#include <cstdio>
|
||||
#include <ctime>
|
||||
#include <cfloat>
|
||||
|
||||
#ifdef FC_OS_WIN32
|
||||
#include <crtdbg.h>
|
||||
@@ -74,6 +73,7 @@
|
||||
#include <exception>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
|
||||
@@ -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<double>::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<double>::max(), 0.001};
|
||||
|
||||
PropertyPrecision::PropertyPrecision()
|
||||
{
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#include <cfloat>
|
||||
#endif
|
||||
|
||||
#include <Base/QuantityPy.h>
|
||||
@@ -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<double>::max(), 1.0};
|
||||
const PropertyQuantityConstraint::Constraints AngleStandard = {-360, 360, 1.0};
|
||||
|
||||
//**************************************************************************
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user