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

📄 flatteningpathiterator.java

📁 gcc的JAVA模块的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* FlatteningPathIterator.java -- Approximates curves by straight lines   Copyright (C) 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.util.NoSuchElementException;/** * A PathIterator for approximating curved path segments by sequences * of straight lines. Instances of this class will only return * segments of type {@link PathIterator#SEG_MOVETO}, {@link * PathIterator#SEG_LINETO}, and {@link PathIterator#SEG_CLOSE}. * * <p>The accuracy of the approximation is determined by two * parameters: * * <ul><li>The <i>flatness</i> is a threshold value for deciding when * a curved segment is consided flat enough for being approximated by * a single straight line. Flatness is defined as the maximal distance * of a curve control point to the straight line that connects the * curve start and end. A lower flatness threshold means a closer * approximation.  See {@link QuadCurve2D#getFlatness()} and {@link * CubicCurve2D#getFlatness()} for drawings which illustrate the * meaning of flatness.</li> * * <li>The <i>recursion limit</i> imposes an upper bound for how often * a curved segment gets subdivided. A limit of <i>n</i> means that * for each individual quadratic and cubic B&#xe9;zier spline * segment, at most 2<sup><small><i>n</i></small></sup> {@link * PathIterator#SEG_LINETO} segments will be created.</li></ul> * * <p><b>Memory Efficiency:</b> The memory consumption grows linearly * with the recursion limit. Neither the <i>flatness</i> parameter nor * the number of segments in the flattened path will affect the memory * consumption. * * <p><b>Thread Safety:</b> Multiple threads can safely work on * separate instances of this class. However, multiple threads should * not concurrently access the same instance, as no synchronization is * performed. * * @see <a href="doc-files/FlatteningPathIterator-1.html" * >Implementation Note</a> * * @author Sascha Brawer (brawer@dandelis.ch) * * @since 1.2 */public class FlatteningPathIterator  implements PathIterator{  /**   * The PathIterator whose curved segments are being approximated.   */  private final PathIterator srcIter;  /**   * The square of the flatness threshold value, which determines when   * a curve segment is considered flat enough that no further   * subdivision is needed.   *   * <p>Calculating flatness actually produces the squared flatness   * value. To avoid the relatively expensive calculation of a square   * root for each curve segment, we perform all flatness comparisons   * on squared values.   *   * @see QuadCurve2D#getFlatnessSq()   * @see CubicCurve2D#getFlatnessSq()   */  private final double flatnessSq;  /**   * The maximal number of subdivions that are performed to   * approximate a quadratic or cubic curve segment.   */  private final int recursionLimit;  /**   * A stack for holding the coordinates of subdivided segments.   *   * @see <a href="doc-files/FlatteningPathIterator-1.html"   * >Implementation Note</a>   */  private double[] stack;  /**   * The current stack size.   *   * @see <a href="doc-files/FlatteningPathIterator-1.html"   * >Implementation Note</a>   */  private int stackSize;  /**   * The number of recursions that were performed to arrive at   * a segment on the stack.   *   * @see <a href="doc-files/FlatteningPathIterator-1.html"   * >Implementation Note</a>   */  private int[] recLevel;      private final double[] scratch = new double[6];  /**   * The segment type of the last segment that was returned by   * the source iterator.   */  private int srcSegType;  /**   * The current <i>x</i> position of the source iterator.   */  private double srcPosX;  /**   * The current <i>y</i> position of the source iterator.   */  private double srcPosY;  /**   * A flag that indicates when this path iterator has finished its   * iteration over path segments.   */  private boolean done;  /**   * Constructs a new PathIterator for approximating an input   * PathIterator with straight lines. The approximation works by   * recursive subdivisons, until the specified flatness threshold is   * not exceeded.   *   * <p>There will not be more than 10 nested recursion steps, which   * means that a single <code>SEG_QUADTO</code> or   * <code>SEG_CUBICTO</code> segment is approximated by at most   * 2<sup><small>10</small></sup> = 1024 straight lines.   */  public FlatteningPathIterator(PathIterator src, double flatness)  {    this(src, flatness, 10);  }  /**   * Constructs a new PathIterator for approximating an input   * PathIterator with straight lines. The approximation works by   * recursive subdivisons, until the specified flatness threshold is   * not exceeded.  Additionally, the number of recursions is also   * bound by the specified recursion limit.   */  public FlatteningPathIterator(PathIterator src, double flatness,                                int limit)  {    if (flatness < 0 || limit < 0)      throw new IllegalArgumentException();    srcIter = src;    flatnessSq = flatness * flatness;    recursionLimit = limit;    fetchSegment();  }  /**   * Returns the maximally acceptable flatness.   *   * @see QuadCurve2D#getFlatness()   * @see CubicCurve2D#getFlatness()   */  public double getFlatness()  {    return Math.sqrt(flatnessSq);  }  /**   * Returns the maximum number of recursive curve subdivisions.   */  public int getRecursionLimit()  {    return recursionLimit;  }  // Documentation will be copied from PathIterator.  public int getWindingRule()  {    return srcIter.getWindingRule();  }  // Documentation will be copied from PathIterator.  public boolean isDone()  {    return done;  }  // Documentation will be copied from PathIterator.  public void next()  {    if (stackSize > 0)    {      --stackSize;      if (stackSize > 0)      {        switch (srcSegType)        {        case PathIterator.SEG_QUADTO:          subdivideQuadratic();          return;        case PathIterator.SEG_CUBICTO:          subdivideCubic();          return;        default:          throw new IllegalStateException();        }      }    }    srcIter.next();    fetchSegment();  }  // Documentation will be copied from PathIterator.  public int currentSegment(double[] coords)  {    if (done)      throw new NoSuchElementException();    switch (srcSegType)    {    case PathIterator.SEG_CLOSE:      return srcSegType;    case PathIterator.SEG_MOVETO:    case PathIterator.SEG_LINETO:      coords[0] = srcPosX;      coords[1] = srcPosY;

⌨️ 快捷键说明

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