コード例 #1
0
  @Override
  public final GeoElement[] process(Command c) throws MyError {
    int n = c.getArgumentNumber();
    GeoElement[] arg;

    boolean ok;

    switch (n) {
      case 2:
        arg = resArgs(c);
        if ((ok = arg[0].isGeoNumeric()) && arg[1].isGeoText()) {

          GeoNumeric num = (GeoNumeric) arg[0];
          String str = ((GeoText) arg[1]).getTextString();

          try {
            num.setValue(kernelA.getAlgebraProcessor().evaluateToNumeric(str, true).getDouble());
            num.updateCascade();
          } catch (Exception e) {
            num.setUndefined();
            num.updateCascade();
          }

          GeoElement[] ret = {num};
          return ret;
        } else if (!ok) throw argErr(app, c.getName(), arg[0]);
        else throw argErr(app, c.getName(), arg[1]);

      default:
        throw argNumErr(app, c.getName(), n);
    }
  }
コード例 #2
0
ファイル: AlgoTakeString.java プロジェクト: geogebra/geogebra
  @Override
  public final void compute() {

    if (!m.isDefined() || (n != null && !n.isDefined()) || inputText == null) {
      outputText.setTextString("");
      return;
    }

    String str = inputText.getTextString();

    if (str == null) {
      outputText.setUndefined();
      return;
    }

    size = str.length();
    int start = (int) m.getDouble();
    double nVal = n == null ? size : n.getDouble();
    int end = (int) nVal;

    if (nVal == 0 && inputText.isDefined() && start > 0 && start <= size) {
      outputText.setTextString("");
      return;
    }

    if (!inputText.isDefined() || size == 0 || start <= 0 || end > size || start > end) {
      outputText.setUndefined();
      return;
    }

    outputText.setTextString(str.substring(start - 1, end));
  }
コード例 #3
0
  public GeoElement[] getTransformedOutput(Transform t) {

    GeoPointND p1 =
        (GeoPointND)
            t.transform((GeoElement) origin, Transform.transformedGeoLabel((GeoElement) origin))[0];
    GeoPointND p2 =
        (GeoPointND)
            t.transform(
                    (GeoElement) secondPoint,
                    Transform.transformedGeoLabel((GeoElement) secondPoint))[0];
    Transform.setVisualStyleForTransformations((GeoElement) origin, (GeoElement) p1);
    Transform.setVisualStyleForTransformations((GeoElement) secondPoint, (GeoElement) p2);

    GeoNumeric r = (new AlgoRadius(this.cons, null, getQuadric().getBottom())).getRadius();
    r.setAuxiliaryObject(true);

    GeoElement[] output = getOutput();
    String[] labels = new String[output.length];
    for (int i = 0; i < output.length; i++) {
      labels[i] = Transform.transformedGeoLabel(output[i]);
    }

    AlgoElement algo = getTransformedAlgo(labels, p1, p2, r);

    GeoElement[] ret = algo.getOutput();
    for (int i = 0; i < ret.length; i++) {
      Transform.setVisualStyleForTransformations(output[i], ret[i]);
    }

    algo.update();

    return ret;
  }
コード例 #4
0
  @Override
  public final void compute() {
    double a = t0.getValue();
    double b = t1.getValue();

    double lenVal = Math.abs(AlgoIntegralDefinite.numericIntegration(lengthCurve, a, b));
    length.setValue(lenVal);
  }
コード例 #5
0
  @Override
  public final void compute() {

    String testType;
    if (tail.getTextString().equals("<")) {
      testType = "left";
    } else if (tail.getTextString().equals(">")) {
      testType = "right";
    } else if (StringUtil.isNotEqual(tail.getTextString())) {
      testType = "two";
    } else {
      result.setUndefined();
      return;
    }

    double n1 = n.getDouble();
    double phat1 = proportion.getDouble();
    double n2 = n_2.getDouble();
    double phat2 = proportion2.getDouble();

    double x1 = phat1 * n1;
    double x2 = phat2 * n2;
    double phatTotal = (x1 + x2) / (n1 + n2);
    se = Math.sqrt(phatTotal * (1 - phatTotal) * (1 / n1 + 1 / n2));
    double testStatistic = (phat1 - phat2) / se;

    NormalDistributionImpl normalDist = new NormalDistributionImpl(0, 1);
    double P = 0;
    try {
      P = normalDist.cumulativeProbability(testStatistic);
    } catch (Exception e) {
      result.setUndefined();
      return;
    }

    if ("right".equals(testType)) {
      P = 1 - P;
    } else if ("two".equals(testType)) {
      if (testStatistic < 0) {
        P = 2 * P;
      } else {
        P = 2 * (1 - P);
      }
    }

    // put these results into the output list
    result.clear();
    result.addNumber(P, null);
    result.addNumber(testStatistic, null);
  }
コード例 #6
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
  @Override
  public final void draw(GGraphics2D g2) {
    if (isVisible) {
      fill(g2, gp, false); // fill using default/hatching/image as
      // appropriate

      if (geo.doHighlighting()) {
        g2.setPaint(geo.getSelColor());
        g2.setStroke(selStroke);
        g2.draw(gp);
      }

      if (geo.lineThickness > 0) {
        g2.setPaint(getObjectColor());
        g2.setStroke(objStroke);
        g2.draw(gp);
      }

      if (labelVisible) {
        g2.setPaint(slope.getLabelColor());
        g2.setFont(view.getFontLine());
        drawLabel(g2);
        g2.drawString(horLabel, xLabelHor, yLabelHor);
      }
    }
  }
コード例 #7
0
  public AlgoLengthSegment(Construction cons, String label, GeoSegmentND seg) {
    super(cons);
    this.seg = seg;
    num = new GeoNumeric(cons);
    setInputOutput(); // for AlgoElement

    // compute length
    compute();
    num.setLabel(label);
  }
コード例 #8
0
  public AlgoLengthVector(Construction cons, String label, GeoVec3D v) {
    super(cons);
    this.v = v;
    num = new GeoNumeric(cons);
    setInputOutput(); // for AlgoElement

    // compute length
    compute();
    num.setLabel(label);
  }
コード例 #9
0
ファイル: DrawBarGraph.java プロジェクト: rlangdon95/geogebra
  /**
   * ***********************************************
   *
   * @param view view
   * @param n number (bar chart)
   */
  public DrawBarGraph(EuclidianView view, GeoNumeric n) {
    this.view = view;
    sum = n;
    geo = n;

    n.setDrawable(true);

    init();
    update();
  }
コード例 #10
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
  /**
   * Creates new drawable for slope
   *
   * @param view view
   * @param slope slope number
   */
  public DrawSlope(EuclidianView view, GeoNumeric slope) {
    this.view = view;
    kernel = view.getKernel();
    this.slope = slope;
    geo = slope;

    slope.setDrawable(true);

    // get parent line
    init();
    update();
  }
コード例 #11
0
  /**
   * @param cons construction
   * @param label label for output
   * @param c curve
   * @param t0 start parameter
   * @param t1 end parameter
   */
  public AlgoLengthCurve(
      Construction cons, String label, GeoCurveCartesian c, GeoNumeric t0, GeoNumeric t1) {
    super(cons);
    this.t0 = t0;
    this.t1 = t1;
    this.c = c;
    length = new GeoNumeric(cons);

    refreshCASResults();

    setInputOutput();
    compute();
    length.setLabel(label);
  }
コード例 #12
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
  @Override
  public final void update() {
    isVisible = geo.isEuclidianVisible();
    if (isVisible) {
      if (!geo.getDrawAlgorithm().equals(geo.getParentAlgorithm())) init();
      int slopeTriangleSize = slope.getSlopeTriangleSize();
      double rwHeight = slope.getValue() * slopeTriangleSize;
      double height = view.getYscale() * rwHeight;
      if (Math.abs(height) > Float.MAX_VALUE) {
        isVisible = false;
        return;
      }

      // get point on line g
      g.getInhomPointOnLine(coords);
      if (g.getStartPoint() == null) {
        // get point on y-axis and line g
        coords[0] = 0.0d;
        coords[1] = -g.z / g.y;
      }
      view.toScreenCoords(coords);

      // draw slope triangle
      double x = coords[0];
      double y = coords[1];
      double xright = x + view.getXscale() * slopeTriangleSize;
      if (gp == null) gp = new GeneralPathClipped(view);
      gp.reset();
      gp.moveTo(x, y);
      gp.lineTo(xright, y);
      gp.lineTo(xright, y - height);
      // closePath important for clipping: #4048
      gp.closePath();
      // 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
      }

      // label position
      labelVisible = geo.isLabelVisible();
      StringTemplate tpl = StringTemplate.defaultTemplate;
      if (labelVisible) {
        if (slopeTriangleSize > 1) {
          StringBuilder sb = new StringBuilder();
          switch (slope.getLabelMode()) {
            case GeoElement.LABEL_NAME_VALUE:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel(tpl));
              sb.append(" = ");
              sb.append(kernel.format(rwHeight, tpl));
              break;

            case GeoElement.LABEL_VALUE:
              sb.append(kernel.format(rwHeight, tpl));
              break;

            default: // case GeoElement.LABEL_NAME:
              sb.append(slopeTriangleSize);
              sb.append(' ');
              sb.append(geo.getLabel(tpl));
              break;
          }
          labelDesc = sb.toString();
        } else {
          labelDesc = geo.getLabelDescription();
        }
        yLabel = (int) (y - height / 2.0f + 6);
        xLabel = (int) (xright) + 5;
        addLabelOffset();

        // position off horizontal label (i.e. slopeTriangleSize)
        xLabelHor = (int) ((x + xright) / 2.0);
        yLabelHor = (int) (y + view.getFontSize() + 2);
        StringBuilder sb = new StringBuilder();
        sb.append(slopeTriangleSize);
        horLabel = sb.toString();
      }
      updateStrokes(slope);
    }
  }
コード例 #13
0
ファイル: DrawSlope.java プロジェクト: hulstores/geogebra
 private void init() {
   g = ((AlgoSlope) slope.getDrawAlgorithm()).getg();
 }
コード例 #14
0
  // calc length of vector v
  @Override
  public final void compute() {

    num.setValue(seg.getLength());
  }
コード例 #15
0
 // calc length of vector v
 @Override
 public final void compute() {
   v.getInhomCoords(coords);
   num.setValue(MyMath.length(coords[0], coords[1]));
 }
コード例 #16
0
ファイル: DrawBarGraph.java プロジェクト: rlangdon95/geogebra
  @Override
  public void draw(org.geogebra.common.awt.GGraphics2D g2) {
    // Save fill, color and alfa of object
    GColor color = geo.getSelColor();
    FillType fillType = geo.getFillType();
    int hatchingDistance = geo.getHatchingDistance();
    String symbol = geo.getFillSymbol();
    double hatchingAngle = geo.getHatchingAngle();
    String fileName = geo.getImageFileName();
    float alpha = geo.getAlphaValue();
    AlgoBarChart algop = (AlgoBarChart) geo.getParentAlgorithm();
    int k;
    if (isVisible) {
      try {
        if (geo.doHighlighting()) {
          g2.setPaint(sum.getSelColor());
          g2.setStroke(selStroke);
          for (int i = 0; i < gp.length; i++) {
            k = i + 1;
            if (algop.getBarColor(k) != null) {
              GColor col = algop.getBarColor(k);
              g2.setPaint(
                  AwtFactory.prototype.newColor(
                      col.getRed(), col.getGreen(),
                      col.getBlue(), col.getAlpha()));
            }
            g2.draw(gp[i]);
          }
          g2.setPaint(color);
        }
      } catch (Exception e) {
        App.debug(e.getMessage());
      }

      try {
        if (algo.getDrawType() != DrawType.STEP_GRAPH_CONTINUOUS) {
          /*
           * Use tags for draw if there are
           */
          for (int i = 0; i < gp.length; i++) {
            k = i + 1;
            if (algop.getBarColor(k) != null) {
              GColor col = algop.getBarColor(k);
              geo.setObjColor(col);
              geo.setAlphaValue(col.getAlpha());
            }
            if (algop.getBarAlpha(k) != -1.0) {
              geo.setAlphaValue(algop.getBarAlpha(k));
            }

            geo.setFillType(algop.getBarFillType(k));

            if (algop.getBarSymbol(k) != null) {
              geo.setFillSymbol(algop.getBarSymbol(k));
            }
            if (algop.getBarImage(k) != null) {
              geo.setImageFileName(algop.getBarImage(k));
            }
            if (algop.getBarHatchDistance(k) != -1) {
              geo.setHatchingDistance(algop.getBarHatchDistance(k));
            }
            if (algop.getBarHatchAngle(k) != -1) {
              geo.setHatchingAngle(algop.getBarHatchAngle(k));
            }

            fill(g2, gp[i], false); // fill using
            // default/hatching/image as
            // appropriate
            // Restore values
            geo.setObjColor(color);
            geo.setFillType(fillType);
            geo.setHatchingAngle((int) hatchingAngle);
            geo.setHatchingDistance(hatchingDistance);
            geo.setFillSymbol(symbol);
            geo.setImageFileName(fileName);
            geo.setAlphaValue(alpha);
          }
        }

      } catch (Exception e) {
        e.printStackTrace();
      }

      try {
        if (geo.getLineThickness() > 0) {
          g2.setPaint(getObjectColor());
          g2.setStroke(objStroke);
          for (int i = 0; i < gp.length; i++) {
            k = i + 1;
            if (algop.getBarColor(k) != null) {
              GColor col = algop.getBarColor(k);
              g2.setPaint(
                  AwtFactory.prototype.newColor(
                      col.getRed(), col.getGreen(),
                      col.getBlue(), geo.getLineOpacity()));
            }
            g2.draw(gp[i]);
          }
          g2.setPaint(color);
        }
      } catch (Exception e) {
        App.debug(e.getMessage());
      }
      if (labelVisible) {
        g2.setFont(view.getFontConic());
        g2.setPaint(geo.getLabelColor());
        drawLabel(g2);
      }

      // point
      if (algo.hasPoints()) {
        for (int i = 0; i < drawPoints.size(); i++) {
          drawPoints.get(i).draw(g2);
        }
      }
    }
  }