📄 cubiccurve2d.java
字号:
return ctrlx2; } /** * Returns the <i>y</i> coordinate of the curve’s second * control point. */ public double getCtrlY2() { return ctrly2; } /** * Returns the curve’s second control point. */ public Point2D getCtrlP2() { return new Point2D.Double(ctrlx2, ctrly2); } /** * Returns the <i>x</i> coordinate of the curve’s end * point. */ public double getX2() { return x2; } /** * Returns the <i>y</i> coordinate of the curve’s end * point. */ public double getY2() { return y2; } /** * Returns the curve’s end point. */ public Point2D getP2() { return new Point2D.Double(x2, y2); } /** * Changes the curve geometry, separately specifying each coordinate * value. * * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" * alt="A drawing of a CubicCurve2D" /> * * @param x1 the <i>x</i> coordinate of the curve’s new start * point. * * @param y1 the <i>y</i> coordinate of the curve’s new start * point. * * @param cx1 the <i>x</i> coordinate of the curve’s new * first control point. * * @param cy1 the <i>y</i> coordinate of the curve’s new * first control point. * * @param cx2 the <i>x</i> coordinate of the curve’s new * second control point. * * @param cy2 the <i>y</i> coordinate of the curve’s new * second control point. * * @param x2 the <i>x</i> coordinate of the curve’s new end * point. * * @param y2 the <i>y</i> coordinate of the curve’s new end * point. */ public void setCurve(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2) { this.x1 = x1; this.y1 = y1; ctrlx1 = cx1; ctrly1 = cy1; ctrlx2 = cx2; ctrly2 = cy2; this.x2 = x2; this.y2 = y2; } /** * Determines the smallest rectangle that encloses the * curve’s start, end and control points. As the * illustration below shows, the invisible control points may cause * the bounds to be much larger than the area that is actually * covered by the curve. * * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" * alt="An illustration of the bounds of a CubicCurve2D" /> */ public Rectangle2D getBounds2D() { double nx1 = Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); double ny1 = Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2)); double nx2 = Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2)); double ny2 = Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); return new Rectangle2D.Double(nx1, ny1, nx2 - nx1, ny2 - ny1); } } /** * A two-dimensional curve that is parameterized with a cubic * function and stores coordinate values in single-precision * floating-point format. * * @see CubicCurve2D.Float * * @author Eric Blake (ebb9@email.byu.edu) * @author Sascha Brawer (brawer@dandelis.ch) */ public static class Float extends CubicCurve2D { /** * The <i>x</i> coordinate of the curve’s start point. */ public float x1; /** * The <i>y</i> coordinate of the curve’s start point. */ public float y1; /** * The <i>x</i> coordinate of the curve’s first control point. */ public float ctrlx1; /** * The <i>y</i> coordinate of the curve’s first control point. */ public float ctrly1; /** * The <i>x</i> coordinate of the curve’s second control point. */ public float ctrlx2; /** * The <i>y</i> coordinate of the curve’s second control point. */ public float ctrly2; /** * The <i>x</i> coordinate of the curve’s end point. */ public float x2; /** * The <i>y</i> coordinate of the curve’s end point. */ public float y2; /** * Constructs a new CubicCurve2D that stores its coordinate values * in single-precision floating-point format. All points are * initially at position (0, 0). */ public Float() { } /** * Constructs a new CubicCurve2D that stores its coordinate values * in single-precision floating-point format, specifying the * initial position of each point. * * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" * alt="A drawing of a CubicCurve2D" /> * * @param x1 the <i>x</i> coordinate of the curve’s start * point. * * @param y1 the <i>y</i> coordinate of the curve’s start * point. * * @param cx1 the <i>x</i> coordinate of the curve’s first * control point. * * @param cy1 the <i>y</i> coordinate of the curve’s first * control point. * * @param cx2 the <i>x</i> coordinate of the curve’s second * control point. * * @param cy2 the <i>y</i> coordinate of the curve’s second * control point. * * @param x2 the <i>x</i> coordinate of the curve’s end * point. * * @param y2 the <i>y</i> coordinate of the curve’s end * point. */ public Float(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2) { this.x1 = x1; this.y1 = y1; ctrlx1 = cx1; ctrly1 = cy1; ctrlx2 = cx2; ctrly2 = cy2; this.x2 = x2; this.y2 = y2; } /** * Returns the <i>x</i> coordinate of the curve’s start * point. */ public double getX1() { return x1; } /** * Returns the <i>y</i> coordinate of the curve’s start * point. */ public double getY1() { return y1; } /** * Returns the curve’s start point. */ public Point2D getP1() { return new Point2D.Float(x1, y1); } /** * Returns the <i>x</i> coordinate of the curve’s first * control point. */ public double getCtrlX1() { return ctrlx1; } /** * Returns the <i>y</i> coordinate of the curve’s first * control point. */ public double getCtrlY1() { return ctrly1; } /** * Returns the curve’s first control point. */ public Point2D getCtrlP1() { return new Point2D.Float(ctrlx1, ctrly1); } /** * Returns the <i>s</i> coordinate of the curve’s second * control point. */ public double getCtrlX2() { return ctrlx2; } /** * Returns the <i>y</i> coordinate of the curve’s second * control point. */ public double getCtrlY2() { return ctrly2; } /** * Returns the curve’s second control point. */ public Point2D getCtrlP2() { return new Point2D.Float(ctrlx2, ctrly2); } /** * Returns the <i>x</i> coordinate of the curve’s end * point. */ public double getX2() { return x2; } /** * Returns the <i>y</i> coordinate of the curve’s end * point. */ public double getY2() { return y2; } /** * Returns the curve’s end point. */ public Point2D getP2() { return new Point2D.Float(x2, y2); } /** * Changes the curve geometry, separately specifying each coordinate * value as a double-precision floating-point number. * * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" * alt="A drawing of a CubicCurve2D" /> * * @param x1 the <i>x</i> coordinate of the curve’s new start * point. * * @param y1 the <i>y</i> coordinate of the curve’s new start * point. * * @param cx1 the <i>x</i> coordinate of the curve’s new * first control point. * * @param cy1 the <i>y</i> coordinate of the curve’s new * first control point. * * @param cx2 the <i>x</i> coordinate of the curve’s new * second control point. * * @param cy2 the <i>y</i> coordinate of the curve’s new * second control point. * * @param x2 the <i>x</i> coordinate of the curve’s new end * point. * * @param y2 the <i>y</i> coordinate of the curve’s new end * point. */ public void setCurve(double x1, double y1, double cx1, double cy1, double cx2, double cy2, double x2, double y2) { this.x1 = (float) x1; this.y1 = (float) y1; ctrlx1 = (float) cx1; ctrly1 = (float) cy1; ctrlx2 = (float) cx2; ctrly2 = (float) cy2; this.x2 = (float) x2; this.y2 = (float) y2; } /** * Changes the curve geometry, separately specifying each coordinate * value as a single-precision floating-point number. * * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" * alt="A drawing of a CubicCurve2D" /> * * @param x1 the <i>x</i> coordinate of the curve’s new start * point. * * @param y1 the <i>y</i> coordinate of the curve’s new start * point. * * @param cx1 the <i>x</i> coordinate of the curve’s new * first control point. * * @param cy1 the <i>y</i> coordinate of the curve’s new * first control point. * * @param cx2 the <i>x</i> coordinate of the curve’s new * second control point. * * @param cy2 the <i>y</i> coordinate of the curve’s new * second control point. * * @param x2 the <i>x</i> coordinate of the curve’s new end * point. * * @param y2 the <i>y</i> coordinate of the curve’s new end * point. */ public void setCurve(float x1, float y1, float cx1, float cy1, float cx2, float cy2, float x2, float y2) { this.x1 = x1; this.y1 = y1; ctrlx1 = cx1; ctrly1 = cy1; ctrlx2 = cx2; ctrly2 = cy2; this.x2 = x2; this.y2 = y2; } /** * Determines the smallest rectangle that encloses the * curve’s start, end and control points. As the * illustration below shows, the invisible control points may cause * the bounds to be much larger than the area that is actually * covered by the curve. * * <p><img src="doc-files/CubicCurve2D-2.png" width="350" height="180" * alt="An illustration of the bounds of a CubicCurve2D" /> */ public Rectangle2D getBounds2D() { float nx1 = (float) Math.min(Math.min(x1, ctrlx1), Math.min(ctrlx2, x2)); float ny1 = (float) Math.min(Math.min(y1, ctrly1), Math.min(ctrly2, y2)); float nx2 = (float) Math.max(Math.max(x1, ctrlx1), Math.max(ctrlx2, x2)); float ny2 = (float) Math.max(Math.max(y1, ctrly1), Math.max(ctrly2, y2)); return new Rectangle2D.Float(nx1, ny1, nx2 - nx1, ny2 - ny1); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -