Ejemplo n.º 1
0
  /**
   * Clip all segments at screen to make sure we don't have to render huge coordinates. This is
   * especially important for fill the GeneralPath.
   */
  private void addClippedSegments() {
    geogebra.common.awt.GRectangle viewRect =
        AwtFactory.prototype.newRectangle(0, 0, view.getWidth(), view.getHeight());
    MyPoint curP = null, prevP;

    int size = pathPoints.size();
    for (int i = 0; i < size; i++) {
      prevP = curP;
      curP = pathPoints.get(i);
      if (!curP.getLineTo() || prevP == null) {
        // moveTo point, make sure it is only slightly outside screen
        geogebra.common.awt.GPoint2D p = getPointCloseToScreen(curP.getX(), curP.getY());
        addToGeneralPath(p, false);
      } else {
        // clip line at screen
        addClippedLine(prevP, curP, viewRect);
      }
    }

    if (needClosePath) {
      // line from last point to first point
      addClippedLine(curP, pathPoints.get(0), viewRect);
      gp.closePath();
    }
  }
Ejemplo n.º 2
0
  private void addToGeneralPath(geogebra.common.awt.GPoint2D q, boolean lineTo) {
    geogebra.common.awt.GPoint2D p = gp.getCurrentPoint();
    if (p != null && p.distance(q) < TOLERANCE) {
      return;
    }

    if (lineTo && p != null) {
      try {
        gp.lineTo((float) q.getX(), (float) q.getY());
      } catch (Exception e) {
        gp.moveTo((float) q.getX(), (float) q.getY());
      }
    } else {
      gp.moveTo((float) q.getX(), (float) q.getY());
    }
  }
Ejemplo n.º 3
0
 private void addSimpleSegments() {
   int size = pathPoints.size();
   for (int i = 0; i < size; i++) {
     MyPoint curP = pathPoints.get(i);
     addToGeneralPath(curP, curP.getLineTo());
   }
   if (needClosePath) gp.closePath();
 }
Ejemplo n.º 4
0
 /** Clears all points and resets internal variables */
 public final void reset() {
   pathPoints.clear();
   gp.reset();
   // bounds.setBounds(0,0,0,0);
   bounds = null;
   largestCoord = 0;
   needClosePath = false;
 }
Ejemplo n.º 5
0
  /** @return this as GeneralPath */
  public geogebra.common.awt.GGeneralPath getGeneralPath() {
    if (pathPoints.size() == 0) return gp;

    gp.reset();
    if (largestCoord < MAX_COORD_VALUE) {
      addSimpleSegments();
    } else {
      addClippedSegments();
    }

    // clear pathPoints to free up memory
    pathPoints.clear();

    return gp;
  }