OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-dev/] [fsf-gcc-snapshot-1-mar-12/] [or1k-gcc/] [libjava/] [classpath/] [java/] [awt/] [geom/] [FlatteningPathIterator.java] - Diff between revs 771 and 783

Only display areas with differences | Details | Blame | View Log

Rev 771 Rev 783
/* FlatteningPathIterator.java -- Approximates curves by straight lines
/* FlatteningPathIterator.java -- Approximates curves by straight lines
   Copyright (C) 2003 Free Software Foundation
   Copyright (C) 2003 Free Software Foundation
 
 
This file is part of GNU Classpath.
This file is part of GNU Classpath.
 
 
GNU Classpath is free software; you can redistribute it and/or modify
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
the Free Software Foundation; either version 2, or (at your option)
any later version.
any later version.
 
 
GNU Classpath is distributed in the hope that it will be useful, but
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.
General Public License for more details.
 
 
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
02110-1301 USA.
 
 
Linking this library statically or dynamically with other modules is
Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
conditions of the GNU General Public License cover the whole
combination.
combination.
 
 
As a special exception, the copyright holders of this library give you
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version. */
exception statement from your version. */
 
 
 
 
package java.awt.geom;
package java.awt.geom;
 
 
import java.util.NoSuchElementException;
import java.util.NoSuchElementException;
 
 
 
 
/**
/**
 * A PathIterator for approximating curved path segments by sequences
 * A PathIterator for approximating curved path segments by sequences
 * of straight lines. Instances of this class will only return
 * of straight lines. Instances of this class will only return
 * segments of type {@link PathIterator#SEG_MOVETO}, {@link
 * segments of type {@link PathIterator#SEG_MOVETO}, {@link
 * PathIterator#SEG_LINETO}, and {@link PathIterator#SEG_CLOSE}.
 * PathIterator#SEG_LINETO}, and {@link PathIterator#SEG_CLOSE}.
 *
 *
 * <p>The accuracy of the approximation is determined by two
 * <p>The accuracy of the approximation is determined by two
 * parameters:
 * parameters:
 *
 *
 * <ul><li>The <i>flatness</i> is a threshold value for deciding when
 * <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 curved segment is consided flat enough for being approximated by
 * a single straight line. Flatness is defined as the maximal distance
 * a single straight line. Flatness is defined as the maximal distance
 * of a curve control point to the straight line that connects the
 * of a curve control point to the straight line that connects the
 * curve start and end. A lower flatness threshold means a closer
 * curve start and end. A lower flatness threshold means a closer
 * approximation.  See {@link QuadCurve2D#getFlatness()} and {@link
 * approximation.  See {@link QuadCurve2D#getFlatness()} and {@link
 * CubicCurve2D#getFlatness()} for drawings which illustrate the
 * CubicCurve2D#getFlatness()} for drawings which illustrate the
 * meaning of flatness.</li>
 * meaning of flatness.</li>
 *
 *
 * <li>The <i>recursion limit</i> imposes an upper bound for how often
 * <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
 * a curved segment gets subdivided. A limit of <i>n</i> means that
 * for each individual quadratic and cubic B&#xe9;zier spline
 * for each individual quadratic and cubic B&#xe9;zier spline
 * segment, at most 2<sup><small><i>n</i></small></sup> {@link
 * segment, at most 2<sup><small><i>n</i></small></sup> {@link
 * PathIterator#SEG_LINETO} segments will be created.</li></ul>
 * PathIterator#SEG_LINETO} segments will be created.</li></ul>
 *
 *
 * <p><b>Memory Efficiency:</b> The memory consumption grows linearly
 * <p><b>Memory Efficiency:</b> The memory consumption grows linearly
 * with the recursion limit. Neither the <i>flatness</i> parameter nor
 * with the recursion limit. Neither the <i>flatness</i> parameter nor
 * the number of segments in the flattened path will affect the memory
 * the number of segments in the flattened path will affect the memory
 * consumption.
 * consumption.
 *
 *
 * <p><b>Thread Safety:</b> Multiple threads can safely work on
 * <p><b>Thread Safety:</b> Multiple threads can safely work on
 * separate instances of this class. However, multiple threads should
 * separate instances of this class. However, multiple threads should
 * not concurrently access the same instance, as no synchronization is
 * not concurrently access the same instance, as no synchronization is
 * performed.
 * performed.
 *
 *
 * @see <a href="doc-files/FlatteningPathIterator-1.html"
 * @see <a href="doc-files/FlatteningPathIterator-1.html"
 * >Implementation Note</a>
 * >Implementation Note</a>
 *
 *
 * @author Sascha Brawer (brawer@dandelis.ch)
 * @author Sascha Brawer (brawer@dandelis.ch)
 *
 *
 * @since 1.2
 * @since 1.2
 */
 */
public class FlatteningPathIterator
public class FlatteningPathIterator
  implements PathIterator
  implements PathIterator
{
{
  /**
  /**
   * The PathIterator whose curved segments are being approximated.
   * The PathIterator whose curved segments are being approximated.
   */
   */
  private final PathIterator srcIter;
  private final PathIterator srcIter;
 
 
 
 
  /**
  /**
   * The square of the flatness threshold value, which determines when
   * The square of the flatness threshold value, which determines when
   * a curve segment is considered flat enough that no further
   * a curve segment is considered flat enough that no further
   * subdivision is needed.
   * subdivision is needed.
   *
   *
   * <p>Calculating flatness actually produces the squared flatness
   * <p>Calculating flatness actually produces the squared flatness
   * value. To avoid the relatively expensive calculation of a square
   * value. To avoid the relatively expensive calculation of a square
   * root for each curve segment, we perform all flatness comparisons
   * root for each curve segment, we perform all flatness comparisons
   * on squared values.
   * on squared values.
   *
   *
   * @see QuadCurve2D#getFlatnessSq()
   * @see QuadCurve2D#getFlatnessSq()
   * @see CubicCurve2D#getFlatnessSq()
   * @see CubicCurve2D#getFlatnessSq()
   */
   */
  private final double flatnessSq;
  private final double flatnessSq;
 
 
 
 
  /**
  /**
   * The maximal number of subdivions that are performed to
   * The maximal number of subdivions that are performed to
   * approximate a quadratic or cubic curve segment.
   * approximate a quadratic or cubic curve segment.
   */
   */
  private final int recursionLimit;
  private final int recursionLimit;
 
 
 
 
  /**
  /**
   * A stack for holding the coordinates of subdivided segments.
   * A stack for holding the coordinates of subdivided segments.
   *
   *
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * >Implementation Note</a>
   * >Implementation Note</a>
   */
   */
  private double[] stack;
  private double[] stack;
 
 
 
 
  /**
  /**
   * The current stack size.
   * The current stack size.
   *
   *
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * >Implementation Note</a>
   * >Implementation Note</a>
   */
   */
  private int stackSize;
  private int stackSize;
 
 
 
 
  /**
  /**
   * The number of recursions that were performed to arrive at
   * The number of recursions that were performed to arrive at
   * a segment on the stack.
   * a segment on the stack.
   *
   *
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * @see <a href="doc-files/FlatteningPathIterator-1.html"
   * >Implementation Note</a>
   * >Implementation Note</a>
   */
   */
  private int[] recLevel;
  private int[] recLevel;
 
 
 
 
 
 
  private final double[] scratch = new double[6];
  private final double[] scratch = new double[6];
 
 
 
 
  /**
  /**
   * The segment type of the last segment that was returned by
   * The segment type of the last segment that was returned by
   * the source iterator.
   * the source iterator.
   */
   */
  private int srcSegType;
  private int srcSegType;
 
 
 
 
  /**
  /**
   * The current <i>x</i> position of the source iterator.
   * The current <i>x</i> position of the source iterator.
   */
   */
  private double srcPosX;
  private double srcPosX;
 
 
 
 
  /**
  /**
   * The current <i>y</i> position of the source iterator.
   * The current <i>y</i> position of the source iterator.
   */
   */
  private double srcPosY;
  private double srcPosY;
 
 
 
 
  /**
  /**
   * A flag that indicates when this path iterator has finished its
   * A flag that indicates when this path iterator has finished its
   * iteration over path segments.
   * iteration over path segments.
   */
   */
  private boolean done;
  private boolean done;
 
 
 
 
  /**
  /**
   * Constructs a new PathIterator for approximating an input
   * Constructs a new PathIterator for approximating an input
   * PathIterator with straight lines. The approximation works by
   * PathIterator with straight lines. The approximation works by
   * recursive subdivisons, until the specified flatness threshold is
   * recursive subdivisons, until the specified flatness threshold is
   * not exceeded.
   * not exceeded.
   *
   *
   * <p>There will not be more than 10 nested recursion steps, which
   * <p>There will not be more than 10 nested recursion steps, which
   * means that a single <code>SEG_QUADTO</code> or
   * means that a single <code>SEG_QUADTO</code> or
   * <code>SEG_CUBICTO</code> segment is approximated by at most
   * <code>SEG_CUBICTO</code> segment is approximated by at most
   * 2<sup><small>10</small></sup> = 1024 straight lines.
   * 2<sup><small>10</small></sup> = 1024 straight lines.
   */
   */
  public FlatteningPathIterator(PathIterator src, double flatness)
  public FlatteningPathIterator(PathIterator src, double flatness)
  {
  {
    this(src, flatness, 10);
    this(src, flatness, 10);
  }
  }
 
 
 
 
  /**
  /**
   * Constructs a new PathIterator for approximating an input
   * Constructs a new PathIterator for approximating an input
   * PathIterator with straight lines. The approximation works by
   * PathIterator with straight lines. The approximation works by
   * recursive subdivisons, until the specified flatness threshold is
   * recursive subdivisons, until the specified flatness threshold is
   * not exceeded.  Additionally, the number of recursions is also
   * not exceeded.  Additionally, the number of recursions is also
   * bound by the specified recursion limit.
   * bound by the specified recursion limit.
   */
   */
  public FlatteningPathIterator(PathIterator src, double flatness,
  public FlatteningPathIterator(PathIterator src, double flatness,
                                int limit)
                                int limit)
  {
  {
    if (flatness < 0 || limit < 0)
    if (flatness < 0 || limit < 0)
      throw new IllegalArgumentException();
      throw new IllegalArgumentException();
 
 
    srcIter = src;
    srcIter = src;
    flatnessSq = flatness * flatness;
    flatnessSq = flatness * flatness;
    recursionLimit = limit;
    recursionLimit = limit;
    fetchSegment();
    fetchSegment();
  }
  }
 
 
 
 
  /**
  /**
   * Returns the maximally acceptable flatness.
   * Returns the maximally acceptable flatness.
   *
   *
   * @see QuadCurve2D#getFlatness()
   * @see QuadCurve2D#getFlatness()
   * @see CubicCurve2D#getFlatness()
   * @see CubicCurve2D#getFlatness()
   */
   */
  public double getFlatness()
  public double getFlatness()
  {
  {
    return Math.sqrt(flatnessSq);
    return Math.sqrt(flatnessSq);
  }
  }
 
 
 
 
  /**
  /**
   * Returns the maximum number of recursive curve subdivisions.
   * Returns the maximum number of recursive curve subdivisions.
   */
   */
  public int getRecursionLimit()
  public int getRecursionLimit()
  {
  {
    return recursionLimit;
    return recursionLimit;
  }
  }
 
 
 
 
  // Documentation will be copied from PathIterator.
  // Documentation will be copied from PathIterator.
  public int getWindingRule()
  public int getWindingRule()
  {
  {
    return srcIter.getWindingRule();
    return srcIter.getWindingRule();
  }
  }
 
 
 
 
  // Documentation will be copied from PathIterator.
  // Documentation will be copied from PathIterator.
  public boolean isDone()
  public boolean isDone()
  {
  {
    return done;
    return done;
  }
  }
 
 
 
 
  // Documentation will be copied from PathIterator.
  // Documentation will be copied from PathIterator.
  public void next()
  public void next()
  {
  {
    if (stackSize > 0)
    if (stackSize > 0)
    {
    {
      --stackSize;
      --stackSize;
      if (stackSize > 0)
      if (stackSize > 0)
      {
      {
        switch (srcSegType)
        switch (srcSegType)
        {
        {
        case PathIterator.SEG_QUADTO:
        case PathIterator.SEG_QUADTO:
          subdivideQuadratic();
          subdivideQuadratic();
          return;
          return;
 
 
        case PathIterator.SEG_CUBICTO:
        case PathIterator.SEG_CUBICTO:
          subdivideCubic();
          subdivideCubic();
          return;
          return;
 
 
        default:
        default:
          throw new IllegalStateException();
          throw new IllegalStateException();
        }
        }
      }
      }
    }
    }
 
 
    srcIter.next();
    srcIter.next();
    fetchSegment();
    fetchSegment();
  }
  }
 
 
 
 
  // Documentation will be copied from PathIterator.
  // Documentation will be copied from PathIterator.
  public int currentSegment(double[] coords)
  public int currentSegment(double[] coords)
  {
  {
    if (done)
    if (done)
      throw new NoSuchElementException();
      throw new NoSuchElementException();
 
 
    switch (srcSegType)
    switch (srcSegType)
    {
    {
    case PathIterator.SEG_CLOSE:
    case PathIterator.SEG_CLOSE:
      return srcSegType;
      return srcSegType;
 
 
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_LINETO:
      coords[0] = srcPosX;
      coords[0] = srcPosX;
      coords[1] = srcPosY;
      coords[1] = srcPosY;
      return srcSegType;
      return srcSegType;
 
 
    case PathIterator.SEG_QUADTO:
    case PathIterator.SEG_QUADTO:
      if (stackSize == 0)
      if (stackSize == 0)
      {
      {
        coords[0] = srcPosX;
        coords[0] = srcPosX;
        coords[1] = srcPosY;
        coords[1] = srcPosY;
      }
      }
      else
      else
      {
      {
        int sp = stack.length - 4 * stackSize;
        int sp = stack.length - 4 * stackSize;
        coords[0] = stack[sp + 2];
        coords[0] = stack[sp + 2];
        coords[1] = stack[sp + 3];
        coords[1] = stack[sp + 3];
      }
      }
      return PathIterator.SEG_LINETO;
      return PathIterator.SEG_LINETO;
 
 
    case PathIterator.SEG_CUBICTO:
    case PathIterator.SEG_CUBICTO:
      if (stackSize == 0)
      if (stackSize == 0)
      {
      {
        coords[0] = srcPosX;
        coords[0] = srcPosX;
        coords[1] = srcPosY;
        coords[1] = srcPosY;
      }
      }
      else
      else
      {
      {
        int sp = stack.length - 6 * stackSize;
        int sp = stack.length - 6 * stackSize;
        coords[0] = stack[sp + 4];
        coords[0] = stack[sp + 4];
        coords[1] = stack[sp + 5];
        coords[1] = stack[sp + 5];
      }
      }
      return PathIterator.SEG_LINETO;
      return PathIterator.SEG_LINETO;
    }
    }
 
 
    throw new IllegalStateException();
    throw new IllegalStateException();
  }
  }
 
 
 
 
  // Documentation will be copied from PathIterator.
  // Documentation will be copied from PathIterator.
  public int currentSegment(float[] coords)
  public int currentSegment(float[] coords)
  {
  {
    if (done)
    if (done)
      throw new NoSuchElementException();
      throw new NoSuchElementException();
 
 
    switch (srcSegType)
    switch (srcSegType)
    {
    {
    case PathIterator.SEG_CLOSE:
    case PathIterator.SEG_CLOSE:
      return srcSegType;
      return srcSegType;
 
 
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_LINETO:
      coords[0] = (float) srcPosX;
      coords[0] = (float) srcPosX;
      coords[1] = (float) srcPosY;
      coords[1] = (float) srcPosY;
      return srcSegType;
      return srcSegType;
 
 
    case PathIterator.SEG_QUADTO:
    case PathIterator.SEG_QUADTO:
      if (stackSize == 0)
      if (stackSize == 0)
      {
      {
        coords[0] = (float) srcPosX;
        coords[0] = (float) srcPosX;
        coords[1] = (float) srcPosY;
        coords[1] = (float) srcPosY;
      }
      }
      else
      else
      {
      {
        int sp = stack.length - 4 * stackSize;
        int sp = stack.length - 4 * stackSize;
        coords[0] = (float) stack[sp + 2];
        coords[0] = (float) stack[sp + 2];
        coords[1] = (float) stack[sp + 3];
        coords[1] = (float) stack[sp + 3];
      }
      }
      return PathIterator.SEG_LINETO;
      return PathIterator.SEG_LINETO;
 
 
    case PathIterator.SEG_CUBICTO:
    case PathIterator.SEG_CUBICTO:
      if (stackSize == 0)
      if (stackSize == 0)
      {
      {
        coords[0] = (float) srcPosX;
        coords[0] = (float) srcPosX;
        coords[1] = (float) srcPosY;
        coords[1] = (float) srcPosY;
      }
      }
      else
      else
      {
      {
        int sp = stack.length - 6 * stackSize;
        int sp = stack.length - 6 * stackSize;
        coords[0] = (float) stack[sp + 4];
        coords[0] = (float) stack[sp + 4];
        coords[1] = (float) stack[sp + 5];
        coords[1] = (float) stack[sp + 5];
      }
      }
      return PathIterator.SEG_LINETO;
      return PathIterator.SEG_LINETO;
    }
    }
 
 
    throw new IllegalStateException();
    throw new IllegalStateException();
  }
  }
 
 
 
 
  /**
  /**
   * Fetches the next segment from the source iterator.
   * Fetches the next segment from the source iterator.
   */
   */
  private void fetchSegment()
  private void fetchSegment()
  {
  {
    int sp;
    int sp;
 
 
    if (srcIter.isDone())
    if (srcIter.isDone())
    {
    {
      done = true;
      done = true;
      return;
      return;
    }
    }
 
 
    srcSegType = srcIter.currentSegment(scratch);
    srcSegType = srcIter.currentSegment(scratch);
 
 
    switch (srcSegType)
    switch (srcSegType)
    {
    {
    case PathIterator.SEG_CLOSE:
    case PathIterator.SEG_CLOSE:
      return;
      return;
 
 
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_LINETO:
      srcPosX = scratch[0];
      srcPosX = scratch[0];
      srcPosY = scratch[1];
      srcPosY = scratch[1];
      return;
      return;
 
 
    case PathIterator.SEG_QUADTO:
    case PathIterator.SEG_QUADTO:
      if (recursionLimit == 0)
      if (recursionLimit == 0)
      {
      {
        srcPosX = scratch[2];
        srcPosX = scratch[2];
        srcPosY = scratch[3];
        srcPosY = scratch[3];
        stackSize = 0;
        stackSize = 0;
        return;
        return;
      }
      }
      sp = 4 * recursionLimit;
      sp = 4 * recursionLimit;
      stackSize = 1;
      stackSize = 1;
      if (stack == null)
      if (stack == null)
      {
      {
        stack = new double[sp + /* 4 + 2 */ 6];
        stack = new double[sp + /* 4 + 2 */ 6];
        recLevel = new int[recursionLimit + 1];
        recLevel = new int[recursionLimit + 1];
      }
      }
      recLevel[0] = 0;
      recLevel[0] = 0;
      stack[sp] = srcPosX;                  // P1.x
      stack[sp] = srcPosX;                  // P1.x
      stack[sp + 1] = srcPosY;              // P1.y
      stack[sp + 1] = srcPosY;              // P1.y
      stack[sp + 2] = scratch[0];           // C.x
      stack[sp + 2] = scratch[0];           // C.x
      stack[sp + 3] = scratch[1];           // C.y
      stack[sp + 3] = scratch[1];           // C.y
      srcPosX = stack[sp + 4] = scratch[2]; // P2.x
      srcPosX = stack[sp + 4] = scratch[2]; // P2.x
      srcPosY = stack[sp + 5] = scratch[3]; // P2.y
      srcPosY = stack[sp + 5] = scratch[3]; // P2.y
      subdivideQuadratic();
      subdivideQuadratic();
      break;
      break;
 
 
    case PathIterator.SEG_CUBICTO:
    case PathIterator.SEG_CUBICTO:
      if (recursionLimit == 0)
      if (recursionLimit == 0)
      {
      {
        srcPosX = scratch[4];
        srcPosX = scratch[4];
        srcPosY = scratch[5];
        srcPosY = scratch[5];
        stackSize = 0;
        stackSize = 0;
        return;
        return;
      }
      }
      sp = 6 * recursionLimit;
      sp = 6 * recursionLimit;
      stackSize = 1;
      stackSize = 1;
      if ((stack == null) || (stack.length < sp + 8))
      if ((stack == null) || (stack.length < sp + 8))
      {
      {
        stack = new double[sp + /* 6 + 2 */ 8];
        stack = new double[sp + /* 6 + 2 */ 8];
        recLevel = new int[recursionLimit + 1];
        recLevel = new int[recursionLimit + 1];
      }
      }
      recLevel[0] = 0;
      recLevel[0] = 0;
      stack[sp] = srcPosX;                  // P1.x
      stack[sp] = srcPosX;                  // P1.x
      stack[sp + 1] = srcPosY;              // P1.y
      stack[sp + 1] = srcPosY;              // P1.y
      stack[sp + 2] = scratch[0];           // C1.x
      stack[sp + 2] = scratch[0];           // C1.x
      stack[sp + 3] = scratch[1];           // C1.y
      stack[sp + 3] = scratch[1];           // C1.y
      stack[sp + 4] = scratch[2];           // C2.x
      stack[sp + 4] = scratch[2];           // C2.x
      stack[sp + 5] = scratch[3];           // C2.y
      stack[sp + 5] = scratch[3];           // C2.y
      srcPosX = stack[sp + 6] = scratch[4]; // P2.x
      srcPosX = stack[sp + 6] = scratch[4]; // P2.x
      srcPosY = stack[sp + 7] = scratch[5]; // P2.y
      srcPosY = stack[sp + 7] = scratch[5]; // P2.y
      subdivideCubic();
      subdivideCubic();
      return;
      return;
    }
    }
  }
  }
 
 
 
 
  /**
  /**
   * Repeatedly subdivides the quadratic curve segment that is on top
   * Repeatedly subdivides the quadratic curve segment that is on top
   * of the stack. The iteration terminates when the recursion limit
   * of the stack. The iteration terminates when the recursion limit
   * has been reached, or when the resulting segment is flat enough.
   * has been reached, or when the resulting segment is flat enough.
   */
   */
  private void subdivideQuadratic()
  private void subdivideQuadratic()
  {
  {
    int sp;
    int sp;
    int level;
    int level;
 
 
    sp = stack.length - 4 * stackSize - 2;
    sp = stack.length - 4 * stackSize - 2;
    level = recLevel[stackSize - 1];
    level = recLevel[stackSize - 1];
    while ((level < recursionLimit)
    while ((level < recursionLimit)
           && (QuadCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
           && (QuadCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
    {
    {
      recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
      recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
      QuadCurve2D.subdivide(stack, sp, stack, sp - 4, stack, sp);
      QuadCurve2D.subdivide(stack, sp, stack, sp - 4, stack, sp);
      ++stackSize;
      ++stackSize;
      sp -= 4;
      sp -= 4;
    }
    }
  }
  }
 
 
 
 
  /**
  /**
   * Repeatedly subdivides the cubic curve segment that is on top
   * Repeatedly subdivides the cubic curve segment that is on top
   * of the stack. The iteration terminates when the recursion limit
   * of the stack. The iteration terminates when the recursion limit
   * has been reached, or when the resulting segment is flat enough.
   * has been reached, or when the resulting segment is flat enough.
   */
   */
  private void subdivideCubic()
  private void subdivideCubic()
  {
  {
    int sp;
    int sp;
    int level;
    int level;
 
 
    sp = stack.length - 6 * stackSize - 2;
    sp = stack.length - 6 * stackSize - 2;
    level = recLevel[stackSize - 1];
    level = recLevel[stackSize - 1];
    while ((level < recursionLimit)
    while ((level < recursionLimit)
           && (CubicCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
           && (CubicCurve2D.getFlatnessSq(stack, sp) >= flatnessSq))
    {
    {
      recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
      recLevel[stackSize] = recLevel[stackSize - 1] = ++level;
 
 
      CubicCurve2D.subdivide(stack, sp, stack, sp - 6, stack, sp);
      CubicCurve2D.subdivide(stack, sp, stack, sp - 6, stack, sp);
      ++stackSize;
      ++stackSize;
      sp -= 6;
      sp -= 6;
    }
    }
  }
  }
 
 
 
 
  /* These routines were useful for debugging. Since they would
  /* These routines were useful for debugging. Since they would
   * just bloat the implementation, they are commented out.
   * just bloat the implementation, they are commented out.
   *
   *
   *
   *
 
 
  private static String segToString(int segType, double[] d, int offset)
  private static String segToString(int segType, double[] d, int offset)
  {
  {
    String s;
    String s;
 
 
    switch (segType)
    switch (segType)
    {
    {
    case PathIterator.SEG_CLOSE:
    case PathIterator.SEG_CLOSE:
      return "SEG_CLOSE";
      return "SEG_CLOSE";
 
 
    case PathIterator.SEG_MOVETO:
    case PathIterator.SEG_MOVETO:
      return "SEG_MOVETO (" + d[offset] + ", " + d[offset + 1] + ")";
      return "SEG_MOVETO (" + d[offset] + ", " + d[offset + 1] + ")";
 
 
    case PathIterator.SEG_LINETO:
    case PathIterator.SEG_LINETO:
      return "SEG_LINETO (" + d[offset] + ", " + d[offset + 1] + ")";
      return "SEG_LINETO (" + d[offset] + ", " + d[offset + 1] + ")";
 
 
    case PathIterator.SEG_QUADTO:
    case PathIterator.SEG_QUADTO:
      return "SEG_QUADTO (" + d[offset] + ", " + d[offset + 1]
      return "SEG_QUADTO (" + d[offset] + ", " + d[offset + 1]
        + ") (" + d[offset + 2] + ", " + d[offset + 3] + ")";
        + ") (" + d[offset + 2] + ", " + d[offset + 3] + ")";
 
 
    case PathIterator.SEG_CUBICTO:
    case PathIterator.SEG_CUBICTO:
      return "SEG_CUBICTO (" + d[offset] + ", " + d[offset + 1]
      return "SEG_CUBICTO (" + d[offset] + ", " + d[offset + 1]
        + ") (" + d[offset + 2] + ", " + d[offset + 3]
        + ") (" + d[offset + 2] + ", " + d[offset + 3]
        + ") (" + d[offset + 4] + ", " + d[offset + 5] + ")";
        + ") (" + d[offset + 4] + ", " + d[offset + 5] + ")";
    }
    }
 
 
    throw new IllegalStateException();
    throw new IllegalStateException();
  }
  }
 
 
 
 
  private void dumpQuadraticStack(String msg)
  private void dumpQuadraticStack(String msg)
  {
  {
    int sp = stack.length - 4 * stackSize - 2;
    int sp = stack.length - 4 * stackSize - 2;
    int i = 0;
    int i = 0;
    System.err.print("    " + msg + ":");
    System.err.print("    " + msg + ":");
    while (sp < stack.length)
    while (sp < stack.length)
    {
    {
      System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
      System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
      if (i < recLevel.length)
      if (i < recLevel.length)
        System.out.print("/" + recLevel[i++]);
        System.out.print("/" + recLevel[i++]);
      if (sp + 3 < stack.length)
      if (sp + 3 < stack.length)
        System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
        System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
      sp += 4;
      sp += 4;
    }
    }
    System.err.println();
    System.err.println();
  }
  }
 
 
 
 
  private void dumpCubicStack(String msg)
  private void dumpCubicStack(String msg)
  {
  {
    int sp = stack.length - 6 * stackSize - 2;
    int sp = stack.length - 6 * stackSize - 2;
    int i = 0;
    int i = 0;
    System.err.print("    " + msg + ":");
    System.err.print("    " + msg + ":");
    while (sp < stack.length)
    while (sp < stack.length)
    {
    {
      System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
      System.err.print(" (" + stack[sp] + ", " + stack[sp+1] + ")");
      if (i < recLevel.length)
      if (i < recLevel.length)
        System.out.print("/" + recLevel[i++]);
        System.out.print("/" + recLevel[i++]);
      if (sp + 3 < stack.length)
      if (sp + 3 < stack.length)
      {
      {
        System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
        System.err.print(" [" + stack[sp+2] + ", " + stack[sp+3] + "]");
        System.err.print(" [" + stack[sp+4] + ", " + stack[sp+5] + "]");
        System.err.print(" [" + stack[sp+4] + ", " + stack[sp+5] + "]");
      }
      }
      sp += 6;
      sp += 6;
    }
    }
    System.err.println();
    System.err.println();
  }
  }
 
 
  *
  *
  *
  *
  */
  */
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.