@Override public BezierCurve create(JSONObject node, ValidationContext ctx) { return new BezierCurve(node); } }
/** * Gets this curve's control points. * * @return {@link Point2DArray} */ public Point2DArray getControlPoints() { return getAttributes().getControlPoints(); }
/** * Constructor. Creates an instance of a cubic bezier curve. * * @param x x value for the first anchor point * @param y y value for the first anchor point * @param controlX1 x value for the first control point * @param controlY1 y value for the first control point * @param controlX2 x value for the second control point * @param controlY2 y value for the second control point * @param endX x value for the second anchor point * @param endY y value for the second anchor point */ public BezierCurve(double x, double y, double controlX1, double controlY1, double controlX2, double controlY2, double endX, double endY) { super(ShapeType.BEZIER_CURVE); setControlPoints(new Point2DArray(new Point2D(x, y), new Point2D(controlX1, controlY1), new Point2D(controlX2, controlY2), new Point2D(endX, endY))); }
/** * Draws this Bezier Curve. * * @param context the {@link Context2D} used to draw this bezier curve. */ @Override public boolean prepare(Context2D context, Attributes attr, double alpha) { Point2DArray points = getControlPoints(); if ((points != null) && (points.getLength() == 4)) { context.beginPath(); Point2D p0 = points.getPoint(0); Point2D p1 = points.getPoint(1); Point2D p2 = points.getPoint(2); Point2D p3 = points.getPoint(3); context.moveTo(p0.getX(), p0.getY()); context.bezierCurveTo(p1.getX(), p1.getY(), p2.getX(), p2.getY(), p3.getX(), p3.getY()); return true; } return false; }
/** * Sets the control points for this curve. * * @param points * A {@link Point2DArray} containing the control points in the following order: * first anchor, first control point, second control point, second anchor * * @return this BezierCurve */ public BezierCurve setControlPoints(Point2DArray points) { getAttributes().setControlPoints(points); return this; }