コード例 #1
0
ファイル: AlgoKeepIf.java プロジェクト: kovzol/geogebra
  protected final void compute() {

    size = inputList.size();

    if (!inputList.isDefined()) {
      outputList.setUndefined();
      return;
    }

    outputList.setDefined(true);
    outputList.clear();

    if (size == 0) return;
    // <Zbynek Konecny 2010-05-13>
    /*
     * If val is not numeric, we use the underlying Expression of the function and
     * plug the list element as variable.
     * Deep copy is needed so that we can plug the value repeatedly.
     */
    FunctionVariable var = boolFun.getFunction().getFunctionVariable();
    for (int i = 0; i < size; i++) {
      GeoElement geo = inputList.get(i);
      if (geo.isGeoNumeric()) {
        if (boolFun.evaluateBoolean(((GeoNumeric) geo).getValue()))
          outputList.add(geo.copyInternal(cons));
        ;
      } else {
        ExpressionNode ex = (ExpressionNode) boolFun.getFunction().getExpression().deepCopy(kernel);
        ex.replaceAndWrap(var, geo.evaluate());
        if (((MyBoolean) ex.evaluate()).getBoolean()) outputList.add(geo.copyInternal(cons));
        ;
      }
    }
    // </Zbynek>
  }
コード例 #2
0
  protected final void compute() {
    // Sum[{x^2,x^3}]

    int n = truncate == null ? geoList.size() : (int) truncate.getDouble();

    if (n == 0 || n > geoList.size()) {
      resultFun.setUndefined();
      return;
    } else if (n == 1) {
      if (!geoList.get(0).isGeoFunctionable()) {
        resultFun.setUndefined();
        return;
      }

      GeoFunction fun1 = ((GeoFunctionable) geoList.get(0)).getGeoFunction();

      FunctionVariable x1 = fun1.getFunction().getFunctionVariable();
      FunctionVariable x = new FunctionVariable(kernel);

      ExpressionNode left = fun1.getFunctionExpression().getCopy(fun1.getKernel());

      Function f = new Function(left.replace(x1, x), x);

      resultFun.setFunction(f);
      resultFun.setDefined(true);
      return;
    }

    if (!geoList.get(0).isGeoFunctionable() || !geoList.get(1).isGeoFunctionable()) {
      resultFun.setUndefined();
      return;
    }

    // add first two:
    resultFun =
        GeoFunction.add(
            resultFun,
            ((GeoFunctionable) geoList.get(0)).getGeoFunction(),
            ((GeoFunctionable) geoList.get(1)).getGeoFunction());

    if (n == 2) return;

    for (int i = 2; i < n; i++) {

      if (!geoList.get(i).isGeoFunctionable()) {
        resultFun.setUndefined();
        return;
      }
      resultFun =
          GeoFunction.add(
              resultFun, resultFun, ((GeoFunctionable) geoList.get(i)).getGeoFunction());
    }
  }