예제 #1
0
  private void doTextFieldActionPerformed(JTextField source) {
    if (isUpdating) return;
    try {
      String inputText = source.getText().trim();
      NumberValue nv;
      nv = app.getKernel().getAlgebraProcessor().evaluateToNumeric(inputText, false);
      double value = nv.getDouble();

      if (source == fldXMin) {
        settings.xMin = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldXMax) {
        settings.xMax = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYMax) {
        settings.yMax = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYMin) {
        settings.yMin = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldXInterval) {
        settings.xAxesInterval = value;
        firePropertyChange("settings", true, false);
      } else if (source == fldYInterval) {
        settings.yAxesInterval = value;
        firePropertyChange("settings", true, false);
      }

    } catch (NumberFormatException e) {
      e.printStackTrace();
    }
  }
	public AlgoIntegralFunctions(Construction cons, String label, 
							GeoFunction f, GeoFunction g,
							NumberValue a, NumberValue b) {
		super(cons);
		this.f = f;
		this.g = g;		
		this.a = a;
		this.b = b;
		ageo = a.toGeoElement();		
		bgeo = b.toGeoElement();
		
		// helper algorithms for integral f and g		
		AlgoIntegralDefinite algoInt = new AlgoIntegralDefinite(cons, f, a, b);
		cons.removeFromConstructionList(algoInt);
		intF = algoInt.getIntegral();
		
		algoInt = new AlgoIntegralDefinite(cons, g, a, b);
		cons.removeFromConstructionList(algoInt);
		intG = algoInt.getIntegral();
		
		// output: intF - intG
		n = new GeoNumeric(cons);				
				
		setInputOutput(); // for AlgoElement		
		compute();
		n.setLabel(label);
	}
예제 #3
0
  /**
   * Creates a new algorithm to create a sequence of objects that form a list.
   *
   * @param cons
   * @param expression
   * @param var
   * @param var_from
   * @param var_to
   * @param var_step
   */
  AlgoSequence(
      Construction cons,
      GeoElement expression,
      GeoNumeric var,
      NumberValue var_from,
      NumberValue var_to,
      NumberValue var_step) {
    super(cons);

    this.expression = expression;
    this.var = var;
    this.var_from = var_from;
    var_from_geo = var_from.toGeoElement();
    this.var_to = var_to;
    var_to_geo = var_to.toGeoElement();
    this.var_step = var_step;
    if (var_step != null) var_step_geo = var_step.toGeoElement();

    expressionParentAlgo = expression.getParentAlgorithm();
    expIsFunctionOrCurve = expression.isGeoFunction() || expression.isGeoCurveCartesian();

    //    	Application.debug("expression: " + expression);
    //   	Application.debug("  parent algo: " + expression.getParentAlgorithm());
    //    //	Application.debug("  parent algo input is var?: " +
    // (expression.getParentAlgorithm().getInput()[0] == var));
    //    	Application.debug("  variable: " + var);
    //    	Application.debug("  expIsGeoFunction: " + expIsGeoFunction);

    list = new GeoList(cons);
    setInputOutput(); // for AlgoElement

    compute();
  }
예제 #4
0
  private double evaluateExpression(String expr) {

    NumberValue nv;
    nv = kernel.getAlgebraProcessor().evaluateToNumeric(expr, false);

    return nv.getDouble();
  }
예제 #5
0
  protected final void compute() {

    // validate
    size = inputList.size();
    if (!inputList.isDefined() || size == 0) {
      outputList.setUndefined();
      return;
    }

    // convert geoList to sorted array of double
    sortedData = new double[size];
    for (int i = 0; i < size; i++) {
      GeoElement geo = inputList.get(i);
      if (geo.isNumberValue()) {
        NumberValue num = (NumberValue) geo;
        sortedData[i] = num.getDouble();

      } else {
        outputList.setUndefined();
        return;
      }
    }
    Arrays.sort(sortedData);

    // create the z values
    calculateZValues(size);

    // prepare output list. Pre-existing geos will be recycled,
    // but extra geos are removed when outputList is too long
    outputList.setDefined(true);
    for (int i = outputList.size() - 1; i >= size; i--) {
      GeoElement extraGeo = outputList.get(i);
      extraGeo.remove();
      outputList.remove(extraGeo);
    }
    int oldListSize = outputList.size();

    // iterate through the sorted data and create the normal quantile points

    boolean suppressLabelCreation = cons.isSuppressLabelsActive();
    cons.setSuppressLabelCreation(true);

    for (int i = 0; i < sortedData.length; i++) {
      if (i < oldListSize) ((GeoPoint) outputList.get(i)).setCoords(sortedData[i], zValues[i], 1.0);
      else outputList.add(new GeoPoint(cons, null, sortedData[i], zValues[i], 1.0));
    }

    // create qq line segment and add it to the list
    outputList.add(getQQLineSegment());

    cons.setSuppressLabelCreation(suppressLabelCreation);
  }
예제 #6
0
  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);
    }
  }
예제 #7
0
  // for AlgoElement
  protected void setInputOutput() {
    input = new GeoElement[2];
    input[0] = Ageo;
    input[1] = angle.toGeoElement();

    output = new GeoElement[1];
    output[0] = Bgeo;
    setDependencies(); // done by AlgoElement
  }
예제 #8
0
  /** 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);
  }
예제 #9
0
  protected final void compute() {
    if (updateRunning) return;
    updateRunning = true;
    for (int i = 1; i < input.length; i++) {
      if (!input[i].isDefined()) {
        list.setUndefined();
        updateRunning = false;
        return;
      }
    }
    list.setDefined(true);

    // create sequence for expression(var) by changing var according to the given range
    double from = var_from.getDouble();
    double to = var_to.getDouble();
    double step = var_step == null ? 1 : var_step.getDouble();

    isEmpty = !((to - from) * step > -Kernel.MIN_PRECISION);

    // an update may be necessary because another variable in expression
    // has changed. However, the range (from, to, step) may not have changed:
    // in this case it is much more efficient not to create all objects
    // for the list again, but just to set their new values
    boolean setValuesOnly = (from == last_from && to == last_to && step == last_step);

    // setValues does not work for functions
    setValuesOnly = setValuesOnly && !expIsFunctionOrCurve;

    // avoid label creation, might happen e.g. in
    boolean oldSuppressLabels = cons.isSuppressLabelsActive();
    cons.setSuppressLabelCreation(true);

    // update list
    if (setValuesOnly) updateListItems(from, to, step);
    else createNewList(from, to, step);

    // revert label creation setting
    cons.setSuppressLabelCreation(oldSuppressLabels);
    updateRunning = false;
  }
예제 #10
0
  AlgoRotate(Construction cons, Rotateable A, NumberValue angle) {
    super(cons);
    this.angle = angle;

    Ageo = A.toGeoElement();
    angleGeo = angle.toGeoElement();

    // create output object
    Bgeo = Ageo.copy();
    B = (Rotateable) Bgeo;
    setInputOutput();

    cons.registerEuclidianViewAlgo(this);

    compute();
  }
    public AlgoIntegralFunctions copy(){
    	return new AlgoIntegralFunctions(cons, null, (GeoFunction)f.copy(),(GeoFunction)g.copy(), 
    			new MyDouble(kernel,a.getDouble()), new MyDouble(kernel,b.getDouble()));

    }