/**
   * 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();
    }
  }