java.awt.geom

Class FlatteningPathIterator

Implemented Interfaces:
PathIterator

public class FlatteningPathIterator
extends Object
implements PathIterator

The FlatteningPathIterator class returns a flattened view of another PathIterator object. Other Shape classes can use this class to provide flattening behavior for their paths without having to perform the interpolation calculations themselves.

Fields inherited from interface java.awt.geom.PathIterator

SEG_CLOSE, SEG_CUBICTO, SEG_LINETO, SEG_MOVETO, SEG_QUADTO, WIND_EVEN_ODD, WIND_NON_ZERO

Constructor Summary

FlatteningPathIterator(PathIterator src, double flatness)
Constructs a new FlatteningPathIterator object that flattens a path as it iterates over it.
FlatteningPathIterator(PathIterator src, double flatness, int limit)
Constructs a new FlatteningPathIterator object that flattens a path as it iterates over it.

Method Summary

int
currentSegment(double[] coords)
Returns the coordinates and type of the current path segment in the iteration.
int
currentSegment(float[] coords)
Returns the coordinates and type of the current path segment in the iteration.
double
getFlatness()
Returns the flatness of this iterator.
int
getRecursionLimit()
Returns the recursion limit of this iterator.
int
getWindingRule()
Returns the winding rule for determining the interior of the path.
boolean
isDone()
Tests if the iteration is complete.
void
next()
Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

FlatteningPathIterator

public FlatteningPathIterator(PathIterator src,
                              double flatness)
Constructs a new FlatteningPathIterator object that flattens a path as it iterates over it. The iterator does not subdivide any curve read from the source iterator to more than 10 levels of subdivision which yields a maximum of 1024 line segments per curve.
Parameters:
src - the original unflattened path being iterated over
flatness - the maximum allowable distance between the control points and the flattened curve
Usages and Demos :

View More Examples of FlatteningPathIterator(PathIterator src,double flatness)
   1:                     PathIterator p = shape.getPathIterator(null);
   2:                     FlatteningPathIterator f = new FlatteningPathIterator(p,0.1);
   3:                     while ( !f.isDone() ) {
   4:                         float[] pts = new float[6];
   5:                         switch ( f.currentSegment(pts) ) {

View Full Code Here
   1:         
   2:     FlatteningPathIterator fp = new FlatteningPathIterator(p, flatness);
   3:         
   4:     path.clear();
   5:     while(!fp.isDone()) {

View Full Code Here
   1:         if (!isFlattenedShape()) {
   2:             iterator = new FlatteningPathIterator(iterator, flatness);
   3:         }
   4:         return iterator;
   5:     }

View Full Code Here

FlatteningPathIterator

public FlatteningPathIterator(PathIterator src,
                              double flatness,
                              int limit)
Constructs a new FlatteningPathIterator object that flattens a path as it iterates over it. The limit parameter allows you to control the maximum number of recursive subdivisions that the iterator can make before it assumes that the curve is flat enough without measuring against the flatness parameter. The flattened iteration therefore never generates more than a maximum of (2^limit) line segments per curve.
Parameters:
src - the original unflattened path being iterated over
flatness - the maximum allowable distance between the control points and the flattened curve
limit - the maximum number of recursive subdivisions allowed for any curved segment

Method Details

currentSegment

public int currentSegment(double[] coords)
Returns the coordinates and type of the current path segment in the iteration. The return value is the path segment type: SEG_MOVETO, SEG_LINETO, or SEG_CLOSE. A double array of length 6 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a pair of double x,y coordinates. SEG_MOVETO and SEG_LINETO types return one point, and SEG_CLOSE does not return any points.
Specified by:
currentSegment in interface PathIterator
Parameters:
coords - an array that holds the data returned from this method
Returns:
the path segment type of the current path segment.
Usages and Demos :

View More Examples of currentSegment(double[] coords)
   1: import java.awt.geom.PathIterator;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.font.TextLayout;
   4:         ...
   5:                         float[] pts = new float[6];
   6:                         switch ( f.currentSegment(pts) ) {
   7:                             case PathIterator.SEG_MOVETO:
   8:         ...
   9:                     PathIterator p = shape.getPathIterator(null);
  10:                     FlatteningPathIterator f = new FlatteningPathIterator(p,0.1);
  11:                     while ( !f.isDone() ) {
  12:         ...
  13:                         float[] pts = new float[6];
  14:                         switch ( f.currentSegment(pts) ) {

View Full Code Here
   1:         double[] cs = new double[6];
   2:         FlatteningPathIterator i = new FlatteningPathIterator(getShape().getPathIterator(null), 1);
   3:         while (!i.isDone()) {
   4:         ...
   5:             switch (i.currentSegment(cs)) {
   6:                 case PathIterator.SEG_LINETO: {
   7:                     lastX = currentX;
   8:                     lastY = currentY;

View Full Code Here
   1:         
   2:     FlatteningPathIterator fp = new FlatteningPathIterator(p, flatness);
   3:         
   4:         ...
   5:         double[] farr = new double[6];
   6:         int type = fp.currentSegment(farr);
   7:             
   8:         if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
   9:         path.add(new Point2D.Double(farr[0],farr[1]));

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.geom.GeneralPath;
   4:         ...
   5: 
   6:         FlatteningPathIterator fpi = new FlatteningPathIterator(path.getPathIterator(new AffineTransform()), 0.01f);
   7:         segments = new Vector(20);
   8:         ...
   9: 
  10:             segType = fpi.currentSegment(seg);

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:         AffineTransform at = AffineTransform.getScaleInstance(1, 1);
   6:         FlatteningPathIterator pIter = new FlatteningPathIterator(
   7:                 getClippingShape().getPathIterator(at),
   8:         ...
   9:         while (!pIter.isDone()) {
  10:             pIter.currentSegment(coords);
  11:             polygon.addPoint((int)coords[0], (int)coords[1]);

View Full Code Here

currentSegment

public int currentSegment(float[] coords)
Returns the coordinates and type of the current path segment in the iteration. The return value is the path segment type: SEG_MOVETO, SEG_LINETO, or SEG_CLOSE. A float array of length 6 must be passed in and can be used to store the coordinates of the point(s). Each point is stored as a pair of float x,y coordinates. SEG_MOVETO and SEG_LINETO types return one point, and SEG_CLOSE does not return any points.
Specified by:
currentSegment in interface PathIterator
Parameters:
coords - an array that holds the data returned from this method
Returns:
the path segment type of the current path segment.
Usages and Demos :

View More Examples of currentSegment(float[] coords)
   1: import java.awt.geom.PathIterator;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.font.TextLayout;
   4:         ...
   5:                         float[] pts = new float[6];
   6:                         switch ( f.currentSegment(pts) ) {
   7:                             case PathIterator.SEG_MOVETO:
   8:         ...
   9:                     PathIterator p = shape.getPathIterator(null);
  10:                     FlatteningPathIterator f = new FlatteningPathIterator(p,0.1);
  11:                     while ( !f.isDone() ) {
  12:         ...
  13:                         float[] pts = new float[6];
  14:                         switch ( f.currentSegment(pts) ) {

View Full Code Here
   1:         double[] cs = new double[6];
   2:         FlatteningPathIterator i = new FlatteningPathIterator(getShape().getPathIterator(null), 1);
   3:         while (!i.isDone()) {
   4:         ...
   5:             switch (i.currentSegment(cs)) {
   6:                 case PathIterator.SEG_LINETO: {
   7:                     lastX = currentX;
   8:                     lastY = currentY;

View Full Code Here
   1:         
   2:     FlatteningPathIterator fp = new FlatteningPathIterator(p, flatness);
   3:         
   4:         ...
   5:         double[] farr = new double[6];
   6:         int type = fp.currentSegment(farr);
   7:             
   8:         if (type == PathIterator.SEG_MOVETO || type == PathIterator.SEG_LINETO) {
   9:         path.add(new Point2D.Double(farr[0],farr[1]));

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.geom.GeneralPath;
   4:         ...
   5: 
   6:         FlatteningPathIterator fpi = new FlatteningPathIterator(path.getPathIterator(new AffineTransform()), 0.01f);
   7:         segments = new Vector(20);
   8:         ...
   9: 
  10:             segType = fpi.currentSegment(seg);

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:         AffineTransform at = AffineTransform.getScaleInstance(1, 1);
   6:         FlatteningPathIterator pIter = new FlatteningPathIterator(
   7:                 getClippingShape().getPathIterator(at),
   8:         ...
   9:         while (!pIter.isDone()) {
  10:             pIter.currentSegment(coords);
  11:             polygon.addPoint((int)coords[0], (int)coords[1]);

View Full Code Here

getFlatness

public double getFlatness()
Returns the flatness of this iterator.
Returns:
the flatness of this FlatteningPathIterator.

getRecursionLimit

public int getRecursionLimit()
Returns the recursion limit of this iterator.
Returns:
the recursion limit of this FlatteningPathIterator.

getWindingRule

public int getWindingRule()
Returns the winding rule for determining the interior of the path.
Specified by:
getWindingRule in interface PathIterator
Returns:
the winding rule of the original unflattened path being iterated over.

isDone

public boolean isDone()
Tests if the iteration is complete.
Specified by:
isDone in interface PathIterator
Returns:
true if all the segments have been read; false otherwise.
Usages and Demos :

View More Examples of isDone()
   1: import java.awt.geom.PathIterator;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.font.TextLayout;
   4:         ...
   5:                     PathIterator f = shape.getPathIterator(null);
   6:                     while ( !f.isDone() ) {
   7:                         float[] pts = new float[6];
   8:         ...
   9:                     PathIterator p = shape.getPathIterator(null);
  10:                     FlatteningPathIterator f = new FlatteningPathIterator(p,0.1);
  11:         ...
  12:                     while ( !f.isDone() ) {

View Full Code Here
   1:         double[] cs = new double[6];
   2:         FlatteningPathIterator i = new FlatteningPathIterator(getShape().getPathIterator(null), 1);
   3:         ...
   4:         while (!i.isDone()) {
   5:             switch (i.currentSegment(cs)) {
   6:                 case PathIterator.SEG_LINETO: {
   7:                     lastX = currentX;

View Full Code Here
   1:         
   2:     FlatteningPathIterator fp = new FlatteningPathIterator(p, flatness);
   3:         
   4:         ...
   5:     path.clear();
   6:     while(!fp.isDone()) {
   7:         double[] farr = new double[6];
   8:         int type = fp.currentSegment(farr);
   9:             

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.geom.GeneralPath;
   4:         ...
   5: 
   6:         FlatteningPathIterator fpi = new FlatteningPathIterator(path.getPathIterator(new AffineTransform()), 0.01f);
   7:         segments = new Vector(20);
   8:         ...
   9: 
  10:         while (!fpi.isDone()) {

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:         AffineTransform at = AffineTransform.getScaleInstance(1, 1);
   6:         FlatteningPathIterator pIter = new FlatteningPathIterator(
   7:                 getClippingShape().getPathIterator(at),
   8:         ...
   9:         double[] coords = new double[6];
  10:         while (!pIter.isDone()) {
  11:             pIter.currentSegment(coords);

View Full Code Here

next

public void next()
Moves the iterator to the next segment of the path forwards along the primary direction of traversal as long as there are more points in that direction.
Specified by:
next in interface PathIterator
Usages and Demos :

View More Examples of next()
   1: import java.awt.geom.PathIterator;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.font.TextLayout;
   4:         ...
   5:                         }
   6:                         f.next();
   7:                     }
   8:         ...
   9:                     PathIterator p = shape.getPathIterator(null);
  10:                     FlatteningPathIterator f = new FlatteningPathIterator(p,0.1);
  11:                     while ( !f.isDone() ) {
  12:         ...
  13:                         }
  14:                         f.next();

View Full Code Here
   1:         double[] cs = new double[6];
   2:         FlatteningPathIterator i = new FlatteningPathIterator(getShape().getPathIterator(null), 1);
   3:         while (!i.isDone()) {
   4:         ...
   5: 
   6:             i.next();
   7:         }
   8:         return false;
   9:     }

View Full Code Here
   1:         
   2:     FlatteningPathIterator fp = new FlatteningPathIterator(p, flatness);
   3:         
   4:         ...
   5:         }
   6:         fp.next();
   7:     }
   8:     }

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.geom.GeneralPath;
   4:         ...
   5: 
   6:         FlatteningPathIterator fpi = new FlatteningPathIterator(path.getPathIterator(new AffineTransform()), 0.01f);
   7:         segments = new Vector(20);
   8:         ...
   9: 
  10:             fpi.next();

View Full Code Here
   1: import java.awt.geom.AffineTransform;
   2: import java.awt.geom.FlatteningPathIterator;
   3: import java.awt.image.BufferedImage;
   4:         ...
   5:         AffineTransform at = AffineTransform.getScaleInstance(1, 1);
   6:         FlatteningPathIterator pIter = new FlatteningPathIterator(
   7:                 getClippingShape().getPathIterator(at),
   8:         ...
   9:             polygon.addPoint((int)coords[0], (int)coords[1]);
  10:             pIter.next();
  11:         }

View Full Code Here