Example #1
0
  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>
  }
	protected final void compute() {	
		if (!f.isDefined() || !g.isDefined() || !ageo.isDefined() || !bgeo.isDefined()) {
			n.setUndefined();
			return;
		}
		
		// Integral[f(x) - g(x), a, b] = Integral[f(x), a, b] - Integral[g(x), a, b]
		n.setValue(intF.getValue() - intG.getValue());		
	}
Example #3
0
  /**
   * Creates labeled function sum algo for truncated list (or whole list if truncate == null)
   *
   * @param cons
   * @param label
   * @param geoList
   * @param truncate
   */
  public AlgoSumFunctions(Construction cons, String label, GeoList geoList, GeoNumeric truncate) {
    super(cons);
    this.geoList = geoList;
    this.truncate = truncate;

    resultFun = new GeoFunction(cons);

    setInputOutput();
    compute();
    resultFun.setLabel(label);
  }
  /** Creates new AlgoDependentFunction */
  public AlgoFunctionInterval(
      Construction cons, String label, GeoFunction f, NumberValue a, NumberValue b) {
    super(cons);
    this.f = f;
    this.a = a;
    this.b = b;
    ageo = a.toGeoElement();
    bgeo = b.toGeoElement();

    // g = new GeoFunction(cons); // output
    // g = new GeoFunction(cons); // output

    g = (GeoFunction) f.copyInternal(cons);

    // buildFunction();
    // g = initHelperAlgorithm();

    setInputOutput(); // for AlgoElement
    compute();
    g.setLabel(label);
  }
  private boolean hasEqualExpressions(GeoFunction f, GeoFunction g) {
    boolean equal;

    if (f.isGeoFunctionConditional()) {
      GeoFunctionConditional geoFun = (GeoFunctionConditional) f;
      ExpressionNode en2 = null;
      ExpressionNode en = geoFun.getIfFunction().getFunctionExpression();
      equal = exp == en;
      exp = en;

      if (geoFun.getElseFunction() != null) {
        en2 = geoFun.getElseFunction().getFunctionExpression();
        equal = equal && exp2 == en2;
        exp2 = en2;
      }
    } else {
      ExpressionNode en = f.getFunctionExpression();
      equal = exp == en;
      exp = en;
    }

    return equal;
  }
  private GeoElement createNewListElement() {
    GeoElement listElement = expression.copyInternal(cons);
    listElement.setParentAlgorithm(this);
    listElement.setConstructionDefaults();
    listElement.setUseVisualDefaults(false);

    // functions and curves use the local variable var
    // so we have to replace var and all dependent objects of var
    // by their current values
    if (expIsFunctionOrCurve) {
      // GeoFunction
      if (listElement.isGeoFunction()) {
        GeoFunction f = (GeoFunction) listElement;
        f.replaceChildrenByValues(var);
      }
      // GeoCurve
      else if (listElement.isGeoCurveCartesian()) {
        GeoCurveCartesian curve = (GeoCurveCartesian) listElement;
        curve.replaceChildrenByValues(var);
      }
    }

    return listElement;
  }
  protected final void compute() {
    if (!(f.isDefined() && ageo.isDefined() && bgeo.isDefined())) g.setUndefined();

    // check if f has changed
    if (!hasEqualExpressions(f, g)) {
      g.set(f);
    }

    double ad = a.getDouble();
    double bd = b.getDouble();
    if (ad > bd) {
      g.setUndefined();
    } else {
      boolean defined = g.setInterval(ad, bd);
      g.setDefined(defined);
    }
  }
  // evaluate the current value of the arithmetic tree
  protected final void compute() {
    // get resulting list of ExpressionNodes
    ExpressionValue evlist = root.evaluate();
    MyList myList = (evlist instanceof MyList) ? (MyList) evlist : ((GeoList) evlist).getMyList();

    int evalListSize = myList.size();
    int cachedListSize = list.getCacheSize();

    list.clear();
    for (int i = 0; i < evalListSize; i++) {
      ExpressionValue element = myList.getListElement(i).evaluate();
      GeoElement geo = null;

      // number result
      if (element.isNumberValue()) {
        double val = ((NumberValue) element).getDouble();

        // try to use cached element of same type
        if (i < cachedListSize) {
          GeoElement cachedGeo = list.getCached(i);

          // the cached element is a number: set value
          if (cachedGeo.isGeoNumeric()) {
            ((GeoNumeric) cachedGeo).setValue(val);
            geo = cachedGeo;
          }
        }

        // no cached number: create new one
        if (geo == null) {
          geo = new GeoNumeric(cons, val);
        }

        // add number to list
        list.add(geo);
      }

      // point
      else if (element.isVectorValue()) {
        GeoVec2D vec = ((VectorValue) element).getVector();

        // try to use cached element of same type
        if (i < cachedListSize) {
          GeoElement cachedGeo = list.getCached(i);

          // the cached element is a point: set value
          if (cachedGeo.isGeoPoint()) {
            ((GeoPoint) cachedGeo).setCoords(vec);
            geo = cachedGeo;
          }
        }

        // no cached point: create new one
        if (geo == null) {
          GeoPoint point = new GeoPoint(cons);
          point.setCoords(vec);
          geo = point;
        }

        // add point to list
        list.add(geo);
      }

      // needed for matrix multiplication
      // eg {{1,3,5},{2,4,6}}*{{11,14},{12,15},{13,a}}
      else if (element instanceof MyList) {
        MyList myList2 = (MyList) element;
        GeoList list2 = new GeoList(cons);
        list2.clear();

        /* removed Michael Borcherds 20080602
         * bug: 9PointCubic.ggb (matrix multiplication)
        // try to use cached element of  type GeoList
        GeoList list2 = null;
        if (i < cachedListSize) {
        	GeoElement cachedGeo = list.getCached(i);

        	// the cached element is a number: set value
        	if (cachedGeo.isGeoList()) {
        		list2 = (GeoList) cachedGeo;
        	}
        }

        if (list2 == null) {
        	list2 = new GeoList(cons);
        } */

        for (int j = 0; j < myList2.size(); j++) {
          ExpressionValue en = myList2.getListElement(j);
          ExpressionValue ev = en.evaluate();

          if (ev instanceof MyDouble) {
            GeoNumeric geo2 = new GeoNumeric(cons);
            geo2.setValue(((NumberValue) ev).getDouble());
            list2.add(geo2);
          }
        }

        list.add(list2);
      } else if (element instanceof MyStringBuffer) {
        MyStringBuffer str = (MyStringBuffer) element;
        // try to use cached element of same type
        if (i < cachedListSize) {
          GeoElement cachedGeo = list.getCached(i);

          // the cached element is a point: set value
          if (cachedGeo.isGeoText()) {
            ((GeoText) cachedGeo).setTextString(str.toValueString());
            geo = cachedGeo;
          }
        }

        // no cached point: create new one
        if (geo == null) {
          GeoText text = new GeoText(cons);
          text.setTextString(str.toValueString());
          geo = text;
        }

        // add point to list
        list.add(geo);
      } else if (element instanceof MyBoolean) {
        MyBoolean bool = (MyBoolean) element;
        // try to use cached element of same type
        if (i < cachedListSize) {
          GeoElement cachedGeo = list.getCached(i);

          // the cached element is a point: set value
          if (cachedGeo.isGeoBoolean()) {
            ((GeoBoolean) cachedGeo).setValue(bool.getBoolean());
            geo = cachedGeo;
          }
        }

        // no cached point: create new one
        if (geo == null) {
          GeoBoolean geoBool = new GeoBoolean(cons);
          geoBool.setValue(bool.getBoolean());
          geo = geoBool;
        }

        // add point to list
        list.add(geo);
      } else if (element instanceof GeoFunction) {
        GeoFunction fun = (GeoFunction) element;
        if (i < cachedListSize) {
          GeoElement cachedGeo = list.getCached(i);

          // the cached element is a point: set value
          if (cachedGeo.isGeoFunction()) {
            ((GeoFunction) cachedGeo).set(fun);
            geo = cachedGeo;
          }
        }

        // no cached point: create new one
        if (geo == null) {
          GeoFunction geoFun = new GeoFunction(cons);
          geoFun.set(fun);
          geo = geoFun;
        }
        list.add(geo);

      } else {
        Application.debug("unsupported list addition: " + element.getClass() + "");
      }
    }
  }
 public final String toString() {
   // Michael Borcherds 2008-03-30
   // simplified to allow better Chinese translation
   return app.getPlain("FunctionAonIntervalBC", f.getLabel(), ageo.getLabel(), bgeo.getLabel());
 }
Example #10
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());
    }
  }
  /** Fills the list of default geos */
  protected void createDefaultGeoElements() {
    defaultGeoElements = new HashMap<Integer, GeoElement>();

    // free point
    GeoPoint freePoint = new GeoPoint(cons);
    //		freePoint.setLocalVariableLabel(app.getPlain("Point") + strFree);
    freePoint.setPointSize(EuclidianView.DEFAULT_POINT_SIZE);
    freePoint.setPointStyle(EuclidianView.POINT_STYLE_DOT);
    freePoint.setLocalVariableLabel("Point" + strFree);
    freePoint.setObjColor(colPoint);
    freePoint.setPointSize(pointSize);
    defaultGeoElements.put(DEFAULT_POINT_FREE, freePoint);

    // dependent point
    GeoPoint depPoint = new GeoPoint(cons);
    //		depPoint.setLocalVariableLabel(app.getPlain("Point") + strDependent);
    depPoint.setPointSize(EuclidianView.DEFAULT_POINT_SIZE);
    depPoint.setPointStyle(EuclidianView.POINT_STYLE_DOT);
    depPoint.setLocalVariableLabel("Point" + strDependent);
    depPoint.setObjColor(colDepPoint);
    depPoint.setPointSize(pointSize);
    defaultGeoElements.put(DEFAULT_POINT_DEPENDENT, depPoint);

    // point on path
    GeoPoint pathPoint = new GeoPoint(cons);
    //		pathPoint.setLocalVariableLabel(app.getPlain("PointOn"));
    pathPoint.setPointSize(EuclidianView.DEFAULT_POINT_SIZE);
    pathPoint.setPointStyle(EuclidianView.POINT_STYLE_DOT);
    pathPoint.setLocalVariableLabel("PointOn");
    pathPoint.setObjColor(colPathPoint);
    pathPoint.setPointSize(pointSize);
    defaultGeoElements.put(DEFAULT_POINT_ON_PATH, pathPoint);

    // point in region
    GeoPoint regionPoint = new GeoPoint(cons);
    //		regionPoint.setLocalVariableLabel(app.getPlain("PointOn"));
    regionPoint.setPointSize(EuclidianView.DEFAULT_POINT_SIZE);
    regionPoint.setPointStyle(EuclidianView.POINT_STYLE_DOT);
    regionPoint.setLocalVariableLabel("PointInRegion");
    regionPoint.setObjColor(colRegionPoint);
    defaultGeoElements.put(DEFAULT_POINT_IN_REGION, regionPoint);

    // complex number (handled like a point)
    GeoPoint complexPoint = new GeoPoint(cons);
    complexPoint.setPointSize(EuclidianView.DEFAULT_POINT_SIZE);
    complexPoint.setPointStyle(EuclidianView.POINT_STYLE_DOT);
    complexPoint.setLocalVariableLabel("PointOn");
    complexPoint.setObjColor(colComplexPoint);
    complexPoint.setPointSize(pointSize);
    defaultGeoElements.put(DEFAULT_POINT_COMPLEX, complexPoint);

    // line
    GeoLine line = new GeoLine(cons);
    //		line.setLocalVariableLabel(app.getPlain("Line"));
    line.setLocalVariableLabel("Line");
    line.setObjColor(colLine);
    defaultGeoElements.put(DEFAULT_LINE, line);

    GeoFunctionNVar inequality = new GeoFunctionNVar(cons, null);
    // inequality.setLocalVariableLabel("Inequality");
    inequality.setObjColor(colInequality);
    inequality.setAlphaValue(DEFAULT_INEQUALITY_ALPHA);
    defaultGeoElements.put(DEFAULT_INEQUALITY, inequality);

    GeoFunction inequality1var = new GeoFunction(cons);
    // inequality.setLocalVariableLabel("Inequality");
    inequality1var.setObjColor(colInequality);
    inequality1var.setAlphaValue(DEFAULT_INEQUALITY_ALPHA);
    defaultGeoElements.put(DEFAULT_INEQUALITY_1VAR, inequality1var);

    // vector
    GeoVector vector = new GeoVector(cons);
    vector.setLocalVariableLabel("Vector");
    vector.setObjColor(colLine);
    defaultGeoElements.put(DEFAULT_VECTOR, vector);

    // polygon
    GeoPolygon polygon = new GeoPolygon(cons, null);
    //		polygon.setLocalVariableLabel(app.getPlain("Polygon"));
    polygon.setLocalVariableLabel("Polygon");
    polygon.setObjColor(colPolygon);
    polygon.setAlphaValue(DEFAULT_POLYGON_ALPHA);
    defaultGeoElements.put(DEFAULT_POLYGON, polygon);

    // conic
    GeoConic conic = new GeoConic(cons);
    //		conic.setLocalVariableLabel(app.getPlain("Conic"));
    conic.setLocalVariableLabel("Conic");
    conic.setObjColor(colConic);
    defaultGeoElements.put(DEFAULT_CONIC, conic);

    // conic sector
    GeoConicPart conicSector = new GeoConicPart(cons, GeoConicPart.CONIC_PART_SECTOR);
    //		conicSector.setLocalVariableLabel(app.getPlain("Sector"));
    conicSector.setLocalVariableLabel("Sector");
    conicSector.setObjColor(colPolygon);
    conicSector.setAlphaValue(DEFAULT_POLYGON_ALPHA);
    defaultGeoElements.put(DEFAULT_CONIC_SECTOR, conicSector);

    // number
    GeoNumeric number = new GeoNumeric(cons);
    //		number.setLocalVariableLabel(app.getPlain("Numeric"));
    number.setLocalVariableLabel("Numeric");
    number.setSliderFixed(true);
    number.setLabelMode(GeoElement.LABEL_NAME_VALUE);
    /*we have to set min/max/increment/speed here because
    SetEuclideanVisible takes these from default geo*/
    number.setIntervalMax(GeoNumeric.DEFAULT_SLIDER_MAX);
    number.setIntervalMin(GeoNumeric.DEFAULT_SLIDER_MIN);
    number.setAnimationStep(GeoNumeric.DEFAULT_SLIDER_INCREMENT);
    number.setAnimationSpeed(GeoNumeric.DEFAULT_SLIDER_SPEED);
    defaultGeoElements.put(DEFAULT_NUMBER, number);

    // angle
    GeoAngle angle = new GeoAngle(cons);
    //		angle.setLocalVariableLabel(app.getPlain("Angle"));
    angle.setLocalVariableLabel("Angle");
    angle.setSliderFixed(true);
    angle.setObjColor(colAngle);
    angle.setAlphaValue(DEFAULT_ANGLE_ALPHA);
    angle.setArcSize(angleSize);
    /*we have to set min/max/increment/speed here because
    SetEuclideanVisible takes these from default geo*/
    angle.setIntervalMax(GeoAngle.DEFAULT_SLIDER_MAX);
    angle.setIntervalMin(GeoAngle.DEFAULT_SLIDER_MIN);
    angle.setAnimationStep(GeoAngle.DEFAULT_SLIDER_INCREMENT);
    angle.setAnimationSpeed(GeoAngle.DEFAULT_SLIDER_SPEED);
    defaultGeoElements.put(DEFAULT_ANGLE, angle);

    // function
    GeoFunction function = new GeoFunction(cons);
    //		function.setLocalVariableLabel(app.getPlain("Function"));
    function.setLocalVariableLabel("Function");
    function.setObjColor(colFunction);
    defaultGeoElements.put(DEFAULT_FUNCTION, function);

    // locus
    GeoLocus locus = new GeoLocus(cons);
    //		locus.setLocalVariableLabel(app.getPlain("Locus"));
    locus.setLocalVariableLabel("Locus");
    locus.setObjColor(colLocus);
    locus.setLabelVisible(false);
    defaultGeoElements.put(DEFAULT_LOCUS, locus);

    // text
    GeoText text = new GeoText(cons);
    //		text.setLocalVariableLabel(app.getPlain("Text"));
    text.setLocalVariableLabel("Text");
    defaultGeoElements.put(DEFAULT_TEXT, text);

    // image
    GeoImage img = new GeoImage(cons);
    //		img.setLocalVariableLabel(app.getPlain("Image"));
    img.setLocalVariableLabel("Image");
    defaultGeoElements.put(DEFAULT_IMAGE, img);

    // boolean
    GeoBoolean bool = new GeoBoolean(cons);
    //		bool.setLocalVariableLabel(app.getPlain("Boolean"));
    bool.setLocalVariableLabel("Boolean");
    defaultGeoElements.put(DEFAULT_BOOLEAN, bool);

    // list
    GeoList list = new GeoList(cons);
    //		list.setLocalVariableLabel(app.getPlain("List"));
    list.setShowAllProperties(true); // show all properties in the defaults dialog
    list.setLocalVariableLabel("List");
    list.setObjColor(colList);
    list.setAlphaValue(-1); // wait until we have an element in the list
    // then we will use the alphaValue of the first element in the list
    // see GeoList.setAlphaValue() and getAlphaValue()
    defaultGeoElements.put(DEFAULT_LIST, list);
  }
    public AlgoIntegralFunctions copy(){
    	return new AlgoIntegralFunctions(cons, null, (GeoFunction)f.copy(),(GeoFunction)g.copy(), 
    			new MyDouble(kernel,a.getDouble()), new MyDouble(kernel,b.getDouble()));

    }