⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quadcurve2d.java

📁 kaffe Java 解释器语言,源码,Java的子集系统,开放源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* QuadCurve2D.java -- represents a parameterized quadratic curve in 2-D space   Copyright (C) 2002, 2003 Free Software FoundationThis file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.awt.geom;import java.awt.Rectangle;import java.awt.Shape;import java.util.NoSuchElementException;/** * A two-dimensional curve that is parameterized with a quadratic * function. * * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180" * alt="A drawing of a QuadCurve2D" /> * * @author Eric Blake (ebb9@email.byu.edu) * @author Graydon Hoare (graydon@redhat.com) * @author Sascha Brawer (brawer@dandelis.ch) * * @since 1.2 */public abstract class QuadCurve2D  implements Shape, Cloneable{  /**   * Constructs a new QuadCurve2D. Typical users will want to   * construct instances of a subclass, such as {@link   * QuadCurve2D.Float} or {@link QuadCurve2D.Double}.   */  protected QuadCurve2D()  {  }  /**   * Returns the <i>x</i> coordinate of the curve&#x2019;s start   * point.   */  public abstract double getX1();  /**   * Returns the <i>y</i> coordinate of the curve&#x2019;s start   * point.   */  public abstract double getY1();  /**   * Returns the curve&#x2019;s start point.   */  public abstract Point2D getP1();  /**   * Returns the <i>x</i> coordinate of the curve&#x2019;s control   * point.   */  public abstract double getCtrlX();  /**   * Returns the <i>y</i> coordinate of the curve&#x2019;s control   * point.   */  public abstract double getCtrlY();  /**   * Returns the curve&#x2019;s control point.   */  public abstract Point2D getCtrlPt();  /**   * Returns the <i>x</i> coordinate of the curve&#x2019;s end   * point.   */  public abstract double getX2();  /**   * Returns the <i>y</i> coordinate of the curve&#x2019;s end   * point.   */  public abstract double getY2();  /**   * Returns the curve&#x2019;s end point.   */  public abstract Point2D getP2();  /**   * Changes the curve geometry, separately specifying each coordinate   * value.   *   * @param x1 the <i>x</i> coordinate of the curve&#x2019;s new start   * point.   *   * @param y1 the <i>y</i> coordinate of the curve&#x2019;s new start   * point.   *   * @param cx the <i>x</i> coordinate of the curve&#x2019;s new   * control point.   *   * @param cy the <i>y</i> coordinate of the curve&#x2019;s new   * control point.   *   * @param x2 the <i>x</i> coordinate of the curve&#x2019;s new end   * point.   *   * @param y2 the <i>y</i> coordinate of the curve&#x2019;s new end   * point.   */  public abstract void setCurve(double x1, double y1, double cx, double cy,                                double x2, double y2);  /**   * Changes the curve geometry, passing coordinate values in an   * array.   *   * @param coords an array containing the new coordinate values.  The   * <i>x</i> coordinate of the new start point is located at   * <code>coords[offset]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the   * new control point is located at <code>coords[offset + 2]</code>,   * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The   * <i>x</i> coordinate of the new end point is located at   * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 5]</code>.   *   * @param offset the offset of the first coordinate value in   * <code>coords</code>.   */  public void setCurve(double[] coords, int offset)  {    setCurve(coords[offset++], coords[offset++],             coords[offset++], coords[offset++],             coords[offset++], coords[offset++]);  }  /**   * Changes the curve geometry, specifying coordinate values in   * separate Point objects.   *   * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180"   * alt="A drawing of a QuadCurve2D" />   *   * <p>The curve does not keep any reference to the passed point   * objects. Therefore, a later change to <code>p1</code>,   * <code>c</code> <code>p2</code> will not affect the curve   * geometry.   *   * @param p1 the new start point.   * @param c the new control point.   * @param p2 the new end point.   */  public void setCurve(Point2D p1, Point2D c, Point2D p2)  {    setCurve(p1.getX(), p1.getY(), c.getX(), c.getY(),             p2.getX(), p2.getY());  }  /**   * Changes the curve geometry, specifying coordinate values in an   * array of Point objects.   *   * <p><img src="doc-files/QuadCurve2D-1.png" width="350" height="180"   * alt="A drawing of a QuadCurve2D" />   *   * <p>The curve does not keep references to the passed point   * objects. Therefore, a later change to the <code>pts</code> array   * or any of its elements will not affect the curve geometry.   *   * @param pts an array containing the points. The new start point   * is located at <code>pts[offset]</code>, the new control   * point at <code>pts[offset + 1]</code>, and the new end point   * at <code>pts[offset + 2]</code>.   *   * @param offset the offset of the start point in <code>pts</code>.   */  public void setCurve(Point2D[] pts, int offset)  {    setCurve(pts[offset].getX(), pts[offset].getY(),             pts[offset + 1].getX(), pts[offset + 1].getY(),             pts[offset + 2].getX(), pts[offset + 2].getY());  }  /**   * Changes the geometry of the curve to that of another curve.   *   * @param c the curve whose coordinates will be copied.   */  public void setCurve(QuadCurve2D c)  {    setCurve(c.getX1(), c.getY1(), c.getCtrlX(), c.getCtrlY(),             c.getX2(), c.getY2());  }  /**   * Calculates the squared flatness of a quadratic curve, directly   * specifying each coordinate value. The flatness is the distance of   * the control point to the line between start and end point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the square of the distance between C and the gray line, i.e.   * the squared length of the red line.   *   * @param x1 the <i>x</i> coordinate of the start point P1.   * @param y1 the <i>y</i> coordinate of the start point P1.   * @param cx the <i>x</i> coordinate of the control point C.   * @param cy the <i>y</i> coordinate of the control point C.   * @param x2 the <i>x</i> coordinate of the end point P2.   * @param y2 the <i>y</i> coordinate of the end point P2.   */  public static double getFlatnessSq(double x1, double y1, double cx,                                     double cy, double x2, double y2)  {    return Line2D.ptSegDistSq(x1, y1, x2, y2, cx, cy);  }  /**   * Calculates the flatness of a quadratic curve, directly specifying   * each coordinate value. The flatness is the distance of the   * control point to the line between start and end point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the distance between C and the gray line, i.e. the length of   * the red line.   *   * @param x1 the <i>x</i> coordinate of the start point P1.   * @param y1 the <i>y</i> coordinate of the start point P1.   * @param cx the <i>x</i> coordinate of the control point C.   * @param cy the <i>y</i> coordinate of the control point C.   * @param x2 the <i>x</i> coordinate of the end point P2.   * @param y2 the <i>y</i> coordinate of the end point P2.   */  public static double getFlatness(double x1, double y1, double cx, double cy,                                   double x2, double y2)  {    return Line2D.ptSegDist(x1, y1, x2, y2, cx, cy);  }  /**   * Calculates the squared flatness of a quadratic curve, specifying   * the coordinate values in an array. The flatness is the distance   * of the control point to the line between start and end point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the square of the distance between C and the gray line, i.e.   * the squared length of the red line.   *   * @param coords an array containing the coordinate values.  The   * <i>x</i> coordinate of the start point P1 is located at   * <code>coords[offset]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the   * control point C is located at <code>coords[offset + 2]</code>,   * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The   * <i>x</i> coordinate of the end point P2 is located at   * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 5]</code>.   *   * @param offset the offset of the first coordinate value in   * <code>coords</code>.   */  public static double getFlatnessSq(double[] coords, int offset)  {    return Line2D.ptSegDistSq(coords[offset], coords[offset + 1],                              coords[offset + 4], coords[offset + 5],                              coords[offset + 2], coords[offset + 3]);  }  /**   * Calculates the flatness of a quadratic curve, specifying the   * coordinate values in an array. The flatness is the distance of   * the control point to the line between start and end point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the the distance between C and the gray line, i.e.  the length of   * the red line.   *   * @param coords an array containing the coordinate values.  The   * <i>x</i> coordinate of the start point P1 is located at   * <code>coords[offset]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 1]</code>.  The <i>x</i> coordinate of the   * control point C is located at <code>coords[offset + 2]</code>,   * its <i>y</i> coordinate at <code>coords[offset + 3]</code>. The   * <i>x</i> coordinate of the end point P2 is located at   * <code>coords[offset + 4]</code>, its <i>y</i> coordinate at   * <code>coords[offset + 5]</code>.   *   * @param offset the offset of the first coordinate value in   * <code>coords</code>.   */  public static double getFlatness(double[] coords, int offset)  {    return Line2D.ptSegDist(coords[offset], coords[offset + 1],                            coords[offset + 4], coords[offset + 5],                            coords[offset + 2], coords[offset + 3]);  }  /**   * Calculates the squared flatness of this curve. The flatness is   * the distance of the control point to the line between start and   * end point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the square of the distance between C and the gray line, i.e. the   * squared length of the red line.   */  public double getFlatnessSq()  {    return Line2D.ptSegDistSq(getX1(), getY1(),                              getX2(), getY2(),                              getCtrlX(), getCtrlY());  }  /**   * Calculates the flatness of this curve. The flatness is the   * distance of the control point to the line between start and end   * point.   *   * <p><img src="doc-files/QuadCurve2D-4.png" width="350" height="180"   * alt="A drawing that illustrates the flatness" />   *   * <p>In the above drawing, the straight line connecting start point   * P1 and end point P2 is depicted in gray.  The result will be the   * the distance between C and the gray line, i.e.  the length of the   * red line.   */  public double getFlatness()  {    return Line2D.ptSegDist(getX1(), getY1(),                            getX2(), getY2(),                            getCtrlX(), getCtrlY());  }  /**   * Subdivides this curve into two halves.   *   * <p><img src="doc-files/QuadCurve2D-3.png" width="700"   * height="180" alt="A drawing that illustrates the effects of   * subdividing a QuadCurve2D" />   *   * @param left a curve whose geometry will be set to the left half   * of this curve, or <code>null</code> if the caller is not   * interested in the left half.   *   * @param right a curve whose geometry will be set to the right half   * of this curve, or <code>null</code> if the caller is not   * interested in the right half.   */  public void subdivide(QuadCurve2D left, QuadCurve2D right)  {    // Use empty slots at end to share single array.    double[] d = new double[] { getX1(), getY1(), getCtrlX(), getCtrlY(),                                getX2(), getY2(), 0, 0, 0, 0 };    subdivide(d, 0, d, 0, d, 4);    if (left != null)      left.setCurve(d, 0);    if (right != null)      right.setCurve(d, 4);  }  /**   * Subdivides a quadratic curve into two halves.   *   * <p><img src="doc-files/QuadCurve2D-3.png" width="700"   * height="180" alt="A drawing that illustrates the effects of   * subdividing a QuadCurve2D" />   *   * @param src the curve to be subdivided.   *   * @param left a curve whose geometry will be set to the left half   * of <code>src</code>, or <code>null</code> if the caller is not   * interested in the left half.   *   * @param right a curve whose geometry will be set to the right half   * of <code>src</code>, or <code>null</code> if the caller is not   * interested in the right half.   */  public static void subdivide(QuadCurve2D src, QuadCurve2D left,                               QuadCurve2D right)  {    src.subdivide(left, right);  }  /**   * Subdivides a quadratic curve into two halves, passing all   * coordinates in an array.   *   * <p><img src="doc-files/QuadCurve2D-3.png" width="700"   * height="180" alt="A drawing that illustrates the effects of   * subdividing a QuadCurve2D" />

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -