Core: Fix func expression simplify

This commit is contained in:
Pieter Hijma
2025-07-28 13:51:49 +02:00
parent de17a4a820
commit 1ebcae0c0b

View File

@@ -2610,7 +2610,7 @@ Py::Object FunctionExpression::_getPyValue() const {
Expression *FunctionExpression::simplify() const
{
size_t numerics = 0;
std::vector<Expression*> a;
std::vector<Expression*> simplifiedArgs;
// Try to simplify each argument to function
for (auto it : args) {
@@ -2618,20 +2618,21 @@ Expression *FunctionExpression::simplify() const
if (freecad_cast<NumberExpression*>(v))
++numerics;
a.push_back(v);
simplifiedArgs.push_back(v);
}
if (numerics == args.size()) {
// All constants, then evaluation must also be constant
// Clean-up
for (auto it : args)
// Clean-up the simplified arguments
for (auto it : simplifiedArgs)
delete it;
return eval();
}
else
return new FunctionExpression(owner, f, std::string(fname), std::move(a));
return new FunctionExpression(owner, f, std::string(fname),
std::move(simplifiedArgs));
}
/**