private void addSimpleSegments() {
   int size = pathPoints.size();
   for (int i = 0; i < size; i++) {
     PathPoint curP = (PathPoint) pathPoints.get(i);
     addToGeneralPath(curP, curP.lineTo);
   }
   if (needClosePath) gp.closePath();
 }
  private void addClippedLine(PathPoint prevP, PathPoint curP, Rectangle viewRect) {
    // check if both points on screen
    if (viewRect.contains(prevP) && viewRect.contains(curP)) {
      // draw line to point
      addToGeneralPath(curP, true);
      return;
    }

    // at least one point is not on screen: clip line at screen
    Point2D.Double[] clippedPoints =
        ClipLine.getClipped(
            prevP.x, prevP.y, curP.x, curP.y, -10, view.width + 10, -10, view.height + 10);

    if (clippedPoints != null) {
      // we have two intersection points with the screen
      // get closest clip point to prevP
      int first = 0;
      int second = 1;
      if (clippedPoints[first].distance(prevP.x, prevP.y)
          > clippedPoints[second].distance(prevP.x, prevP.y)) {
        first = 1;
        second = 0;
      }

      // draw line to first clip point
      addToGeneralPath(clippedPoints[first], true);
      // draw line between clip points: this ensures high quality rendering
      // which Java2D doesn't deliver with the regular float GeneralPath and huge coords
      addToGeneralPath(clippedPoints[second], true);

      // draw line to end point if not already there
      addToGeneralPath(getPointCloseToScreen(curP.x, curP.y), true);
    } else {
      // line is off screen
      // draw line to off screen end point
      addToGeneralPath(getPointCloseToScreen(curP.x, curP.y), true);
    }
  }
  /**
   * 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() {
    Rectangle viewRect = new Rectangle(0, 0, view.width, view.height);
    PathPoint curP = null, prevP;

    int size = pathPoints.size();
    for (int i = 0; i < size; i++) {
      prevP = curP;
      curP = (PathPoint) pathPoints.get(i);
      if (!curP.lineTo || prevP == null) {
        // moveTo point, make sure it is only slightly outside screen
        Point2D p = getPointCloseToScreen(curP.x, curP.y);
        addToGeneralPath(p, false);
      } else {
        // clip line at screen
        addClippedLine(prevP, curP, viewRect);
      }
    }

    if (needClosePath) {
      // line from last point to first point
      addClippedLine(curP, (PathPoint) pathPoints.get(0), viewRect);
      gp.closePath();
    }
  }