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

📄 cubiccurve2d.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/* CubicCurve2D.java -- represents a parameterized cubic curve in 2-D space   Copyright (C) 2002, 2003, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 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 cubic * function. * * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180" * alt="A drawing of a CubicCurve2D" /> * * @author Eric Blake (ebb9@email.byu.edu) * @author Graydon Hoare (graydon@redhat.com) * @author Sascha Brawer (brawer@dandelis.ch) * @author Sven de Marothy (sven@physto.se) * * @since 1.2 */public abstract class CubicCurve2D implements Shape, Cloneable{  private static final double BIG_VALUE = java.lang.Double.MAX_VALUE / 10.0;  private static final double EPSILON = 1E-10;  /**   * Constructs a new CubicCurve2D. Typical users will want to   * construct instances of a subclass, such as {@link   * CubicCurve2D.Float} or {@link CubicCurve2D.Double}.   */  protected CubicCurve2D()  {  }  /**   * 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 first   * control point.   */  public abstract double getCtrlX1();  /**   * Returns the <i>y</i> coordinate of the curve&#x2019;s first   * control point.   */  public abstract double getCtrlY1();  /**   * Returns the curve&#x2019;s first control point.   */  public abstract Point2D getCtrlP1();  /**   * Returns the <i>x</i> coordinate of the curve&#x2019;s second   * control point.   */  public abstract double getCtrlX2();  /**   * Returns the <i>y</i> coordinate of the curve&#x2019;s second   * control point.   */  public abstract double getCtrlY2();  /**   * Returns the curve&#x2019;s second control point.   */  public abstract Point2D getCtrlP2();  /**   * 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.   *   * <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&#x2019;s new start   * point.   *   * @param y1 the <i>y</i> coordinate of the curve&#x2019;s new start   * point.   *   * @param cx1 the <i>x</i> coordinate of the curve&#x2019;s new   * first control point.   *   * @param cy1 the <i>y</i> coordinate of the curve&#x2019;s new   * first control point.   *   * @param cx2 the <i>x</i> coordinate of the curve&#x2019;s new   * second control point.   *   * @param cy2 the <i>y</i> coordinate of the curve&#x2019;s new   * second 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 cx1, double cy1,                                double cx2, double cy2, double x2, double y2);  /**   * Changes the curve geometry, specifying 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 first 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 second control   * point is located at <code>coords[offset + 4]</code>, its <i>y</i>   * coordinate at <code>coords[offset + 5]</code>.  The <i>x</i>   * coordinate of the new end point is located at <code>coords[offset   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +   * 7]</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++],             coords[offset++], coords[offset++]);  }  /**   * Changes the curve geometry, specifying coordinate values in   * separate Point objects.   *   * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"   * alt="A drawing of a CubicCurve2D" />   *   * <p>The curve does not keep any reference to the passed point   * objects. Therefore, a later change to <code>p1</code>,   * <code>c1</code>, <code>c2</code> or <code>p2</code> will not   * affect the curve geometry.   *   * @param p1 the new start point.   * @param c1 the new first control point.   * @param c2 the new second control point.   * @param p2 the new end point.   */  public void setCurve(Point2D p1, Point2D c1, Point2D c2, Point2D p2)  {    setCurve(p1.getX(), p1.getY(), c1.getX(), c1.getY(), c2.getX(), c2.getY(),             p2.getX(), p2.getY());  }  /**   * Changes the curve geometry, specifying coordinate values in an   * array of Point objects.   *   * <p><img src="doc-files/CubicCurve2D-1.png" width="350" height="180"   * alt="A drawing of a CubicCurve2D" />   *   * <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 first control   * point at <code>pts[offset + 1]</code>, the new second control   * point at <code>pts[offset + 2]</code>, and the new end point   * at <code>pts[offset + 3]</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].getX(),             pts[offset++].getY(), pts[offset].getX(), pts[offset++].getY(),             pts[offset].getX(), pts[offset++].getY());  }  /**   * Changes the curve geometry to that of another curve.   *   * @param c the curve whose coordinates will be copied.   */  public void setCurve(CubicCurve2D c)  {    setCurve(c.getX1(), c.getY1(), c.getCtrlX1(), c.getCtrlY1(),             c.getCtrlX2(), c.getCtrlY2(), c.getX2(), c.getY2());  }  /**   * Calculates the squared flatness of a cubic curve, directly   * specifying each coordinate value. The flatness is the maximal   * distance of a control point to the line between start and end   * point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the square of the distance between C2 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 cx1 the <i>x</i> coordinate of the first control point C1.   * @param cy1 the <i>y</i> coordinate of the first control point C1.   * @param cx2 the <i>x</i> coordinate of the second control point C2.   * @param cy2 the <i>y</i> coordinate of the second control point C2.   * @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 cx1,                                     double cy1, double cx2, double cy2,                                     double x2, double y2)  {    return Math.max(Line2D.ptSegDistSq(x1, y1, x2, y2, cx1, cy1),                    Line2D.ptSegDistSq(x1, y1, x2, y2, cx2, cy2));  }  /**   * Calculates the flatness of a cubic curve, directly specifying   * each coordinate value. The flatness is the maximal distance of a   * control point to the line between start and end point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the distance between C2 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 cx1 the <i>x</i> coordinate of the first control point C1.   * @param cy1 the <i>y</i> coordinate of the first control point C1.   * @param cx2 the <i>x</i> coordinate of the second control point C2.   * @param cy2 the <i>y</i> coordinate of the second control point C2.   * @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 cx1,                                   double cy1, double cx2, double cy2,                                   double x2, double y2)  {    return Math.sqrt(getFlatnessSq(x1, y1, cx1, cy1, cx2, cy2, x2, y2));  }  /**   * Calculates the squared flatness of a cubic curve, specifying the   * coordinate values in an array. The flatness is the maximal   * distance of a control point to the line between start and end   * point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the square of the distance between C2 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   * first control point C1 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 second control point C2   * is located at <code>coords[offset + 4]</code>, its <i>y</i>   * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>   * coordinate of the end point P2 is located at <code>coords[offset   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +   * 7]</code>.   *   * @param offset the offset of the first coordinate value in   * <code>coords</code>.   */  public static double getFlatnessSq(double[] coords, int offset)  {    return getFlatnessSq(coords[offset++], coords[offset++], coords[offset++],                         coords[offset++], coords[offset++], coords[offset++],                         coords[offset++], coords[offset++]);  }  /**   * Calculates the flatness of a cubic curve, specifying the   * coordinate values in an array. The flatness is the maximal   * distance of a control point to the line between start and end   * point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the distance between C2 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   * first control point C1 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 second control point C2   * is located at <code>coords[offset + 4]</code>, its <i>y</i>   * coordinate at <code>coords[offset + 5]</code>. The <i>x</i>   * coordinate of the end point P2 is located at <code>coords[offset   * + 6]</code>, its <i>y</i> coordinate at <code>coords[offset +   * 7]</code>.   *   * @param offset the offset of the first coordinate value in   * <code>coords</code>.   */  public static double getFlatness(double[] coords, int offset)  {    return Math.sqrt(getFlatnessSq(coords[offset++], coords[offset++],                                   coords[offset++], coords[offset++],                                   coords[offset++], coords[offset++],                                   coords[offset++], coords[offset++]));  }  /**   * Calculates the squared flatness of this curve.  The flatness is   * the maximal distance of a control point to the line between start   * and end point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the square of the distance between C2 and the   * gray line, i.e. the squared length of the red line.   */  public double getFlatnessSq()  {    return getFlatnessSq(getX1(), getY1(), getCtrlX1(), getCtrlY1(),                         getCtrlX2(), getCtrlY2(), getX2(), getY2());  }  /**   * Calculates the flatness of this curve.  The flatness is the   * maximal distance of a control point to the line between start and   * end point.   *   * <p><img src="doc-files/CubicCurve2D-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.  In comparison to C1,   * control point C2 is father away from the gray line. Therefore,   * the result will be the distance between C2 and the gray line,

⌨️ 快捷键说明

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