/** * Appends a straight line segment from the current point to the point <CODE>(x, y)</CODE>. * @param x x-coordinate of the new point * @param y y-coordinate of the new point */ public void lineTo(float x, float y) { if (currentPoint == null) { throw new RuntimeException(START_PATH_ERR_MSG); } Point targetPoint = new Point(x, y); getLastSubpath().addSegment(new Line(currentPoint, targetPoint)); currentPoint = targetPoint; }
/** * Appends a cubic Bezier curve to the current path. The curve shall extend from * the current point to the point <CODE>(x3, y3)</CODE>. * @param x1 x-coordinate of the first control point * @param y1 y-coordinate of the first control point * @param x2 x-coordinate of the second control point * @param y2 y-coordinate of the second control point * @param x3 x-coordinate of the third control point * @param y3 y-coordinate of the third control point */ public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) { if (currentPoint == null) { throw new RuntimeException(START_PATH_ERR_MSG); } // Numbered in natural order Point secondPoint = new Point(x1, y1); Point thirdPoint = new Point(x2, y2); Point fourthPoint = new Point(x3, y3); List<Point> controlPoints = new ArrayList<>(Arrays.asList(currentPoint, secondPoint, thirdPoint, fourthPoint)); getLastSubpath().addSegment(new BezierCurve(controlPoints)); currentPoint = fourthPoint; }
/** * Closes the current subpath. */ public void closeSubpath() { if (!isEmpty()) { Subpath lastSubpath = getLastSubpath(); lastSubpath.setClosed(true); Point startPoint = lastSubpath.getStartPoint(); moveTo((float) startPoint.getX(), (float) startPoint.getY()); } }