Merge pull request #22788 from pieterhijma/fix-func-expr-simplify

Core: Fix expression function simplify
This commit is contained in:
Chris Hennes
2025-08-12 11:07:44 -05:00
committed by GitHub
2 changed files with 114 additions and 5 deletions

View File

@@ -2665,7 +2665,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) {
@@ -2673,20 +2673,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));
}
/**