[poincare/function] getVariables always gets the argument

When applied to a function f(x) = constant, the method getVariables
would not find any, as the search is performed on the function's
definition.
Thus, when using the "Fill with formula" tool in Statistics, if the
formula to fill V1 is "V1=f(V2)", the formula will be considered
constant and applied to all values in V1. However, if V1 is longer than
V2, the program will attempt to read undefined values of V2.
With this change, the formula will only be applied to lines in V1 for
which there is a corresponding line in V2.
This commit is contained in:
Gabriel Ozouf
2020-12-29 15:42:47 +01:00
committed by EmilieNumworks
parent d26ba0250b
commit 4209f0a26c

View File

@@ -38,6 +38,10 @@ int FunctionNode::getPolynomialCoefficients(Context * context, const char * symb
int FunctionNode::getVariables(Context * context, isVariableTest isVariable, char * variables, int maxSizeVariable, int nextVariableIndex) const {
Function f(this);
Expression e = SymbolAbstract::Expand(f, context, true);
/* Since templatedApproximate always evaluates the argument, some apps (such
* as Statistics and Regression) need to be aware of it even when it does not
* appear in the formula. */
nextVariableIndex = childAtIndex(0)->getVariables(context, isVariable, variables, maxSizeVariable, nextVariableIndex);
if (e.isUninitialized()) {
return nextVariableIndex;
}