Пример #1
0
  @Override
  public final void update() {
    isVisible = geo.isEuclidianVisible();
    if (!isVisible) return;
    labelVisible = geo.isLabelVisible();
    updateStrokes(n);
    if (!geo.getDrawAlgorithm().equals(geo.getParentAlgorithm())) init();

    if (gp == null) gp = new GeneralPathClipped(view);
    else gp.reset();

    // init gp
    double aRW = a.getDouble();
    double bRW = b.getDouble();

    // for DrawParametricCurve.plotCurve to work with special values,
    // these changes are needed (also filter out out of screen integrals)
    // see #1234
    aRW = Math.max(aRW, view.getXmin() - EuclidianStatic.CLIP_DISTANCE);
    if (aRW > view.getXmax() + EuclidianStatic.CLIP_DISTANCE) return;

    bRW = Math.min(bRW, view.getXmax() + EuclidianStatic.CLIP_DISTANCE);
    if (bRW < view.getXmin() - EuclidianStatic.CLIP_DISTANCE) return;

    double ax = view.toScreenCoordXd(aRW);
    double bx = view.toScreenCoordXd(bRW);
    float y0 = (float) view.getyZero();

    // plot definite integral

    if (Kernel.isEqual(aRW, bRW)) {
      gp.moveTo(ax, y0);
      gp.lineTo(ax, view.toScreenCoordYd(f.evaluate(aRW)));
      gp.lineTo(ax, y0);
      return;
    }

    gp.moveTo(ax, y0);
    DrawParametricCurve.plotCurve(f, aRW, bRW, view, gp, false, DrawParametricCurve.GAP_LINE_TO);
    gp.lineTo(bx, y0);
    gp.lineTo(ax, y0);

    // gp on screen?
    if (!gp.intersects(0, 0, view.getWidth(), view.getHeight())) {
      isVisible = false;
      // don't return here to make sure that getBounds() works for
      // offscreen points too
    }

    if (labelVisible) {
      xLabel = (int) Math.round((ax + bx) / 2) - 6;
      yLabel = (int) view.getyZero() - view.getFontSize();
      labelDesc = geo.getLabelDescription();
      addLabelOffset();
    }
  }
Пример #2
0
 private void doActionPerformed() {
   NumberValue newVal = kernel.getAlgebraProcessor().evaluateToNumeric(tfAnimStep.getText(), true);
   if (newVal != null && !Double.isNaN(newVal.getDouble())) {
     for (int i = 0; i < geos.length; i++) {
       GeoElement geo = (GeoElement) geos[i];
       geo.setAnimationStep(newVal);
       geo.updateRepaint();
     }
   }
   update(geos);
 }
  @Override
  public 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);
  }
Пример #4
0
  @Override
  public final void compute() {

    double n = Math.round(num.getDouble());

    if (n == 1) {
      outputList.clear();
      outputList.setDefined(true);
      return;
    }

    if (n < 2 || n > LARGEST_INTEGER) {
      outputList.setUndefined();
      return;
    }

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

    int count = 0;

    for (int i = 2; i <= n / i; i++) {
      int exp = 0;
      while (n % i == 0) {
        exp++;
        n /= i;
      }
      if (exp > 0) {
        setListElement(count++, i, exp);
      }
    }
    if (n > 1) {
      setListElement(count++, n, 1);
    }
  }
Пример #5
0
  @Override
  protected void setInputOutput() {
    input = new GeoElement[1];
    input[0] = num.toGeoElement();

    setOutputLength(1);
    setOutput(0, outputList);
    setDependencies(); // done by AlgoElement
  }
Пример #6
0
 /**
  * Parses given String str and tries to evaluate it to a double. Returns Double.NaN if something
  * went wrong.
  */
 public double evaluateToDouble(String str, boolean suppressErrors) {
   try {
     ValidExpression ve = parser.parseExpression(str);
     ExpressionNode en = (ExpressionNode) ve;
     en.resolveVariables();
     NumberValue nv = (NumberValue) en.evaluate();
     return nv.getDouble();
   } catch (Exception e) {
     e.printStackTrace();
     if (!suppressErrors) app.showError("InvalidInput", str);
     return Double.NaN;
   } catch (MyError e) {
     e.printStackTrace();
     if (!suppressErrors) app.showError(e);
     return Double.NaN;
   } catch (Error e) {
     e.printStackTrace();
     if (!suppressErrors) app.showError("InvalidInput", str);
     return Double.NaN;
   }
 }
Пример #7
0
 // for AlgoElement
 @Override
 protected void setInputOutput() {
   if (param == null) {
     input = new GeoElement[1];
     input[0] = path.toGeoElement();
   } else {
     input = new GeoElement[2];
     input[0] = path.toGeoElement();
     input[1] = param.toGeoElement();
   }
   setOutputLength(1);
   setOutput(0, P);
   setDependencies(); // done by AlgoElement
 }
Пример #8
0
  @Override
  protected void setInputOutput() {

    // build array list of possible arguments
    ArrayList<GeoElement> inputList = new ArrayList<GeoElement>();
    inputList.add(a.toGeoElement());
    inputList.add(b.toGeoElement());
    if (c != null) {
      inputList.add(c.toGeoElement());
    }
    if (d != null) {
      inputList.add(d.toGeoElement());
    }
    if (isCumulative != null) {
      inputList.add(isCumulative.toGeoElement());
    }

    // convert to array
    input = new GeoElement[inputList.size()];
    inputList.toArray(input);

    setOnlyOutput(num);
    setDependencies(); // done by AlgoElement
  }
Пример #9
0
 @Override
 public final void compute() {
   if (param != null) {
     PathParameter pp = P.getPathParameter();
     // Application.debug(param.getDouble()+" "+path.getMinParameter()+" "+path.getMaxParameter());
     pp.setT(
         PathNormalizer.toParentPathParameter(
             param.getDouble(), path.getMinParameter(), path.getMaxParameter()));
     // Application.debug(pp.t);
   }
   if (input[0].isDefined()) {
     path.pathChanged(P);
     P.updateCoords();
   } else {
     P.setUndefined();
   }
 }
Пример #10
0
 @Override
 public void compute() {
   if (!factorList.isDefined() || !Kernel.isInteger(number.getDouble())) {
     result.setUndefined();
     return;
   }
   long res = 1;
   for (int i = 0; i < factorList.size(); i++) {
     GeoList pair = (GeoList) factorList.get(i);
     double exp = ((NumberValue) pair.get(1)).getDouble();
     if (sum) {
       double prime = ((NumberValue) pair.get(0)).getDouble();
       App.debug(prime);
       res = res * Math.round((Math.pow(prime, exp + 1) - 1) / (prime - 1.0));
     } else {
       res = res * Math.round(exp + 1);
     }
   }
   result.setValue(res);
 }
Пример #11
0
 @Override
 protected void setInputOutput() {
   setOnlyOutput(result);
   input = new GeoElement[] {number.toGeoElement()};
   setDependencies();
 }
Пример #12
0
 /**
  * @param e
  * @return numerical value of the expression
  */
 public static double getNumber(NumberValue e) {
   return e.getDouble();
 }