|
Java example source code file (FlatteningPathIterator.java)
The FlatteningPathIterator.java Java example source code/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.awt.geom;
import java.util.*;
/**
* The <code>FlatteningPathIterator class returns a flattened view of
* another {@link PathIterator} object. Other {@link java.awt.Shape Shape}
* classes can use this class to provide flattening behavior for their paths
* without having to perform the interpolation calculations themselves.
*
* @author Jim Graham
*/
public class FlatteningPathIterator implements PathIterator {
static final int GROW_SIZE = 24; // Multiple of cubic & quad curve size
PathIterator src; // The source iterator
double squareflat; // Square of the flatness parameter
// for testing against squared lengths
int limit; // Maximum number of recursion levels
double hold[] = new double[14]; // The cache of interpolated coords
// Note that this must be long enough
// to store a full cubic segment and
// a relative cubic segment to avoid
// aliasing when copying the coords
// of a curve to the end of the array.
// This is also serendipitously equal
// to the size of a full quad segment
// and 2 relative quad segments.
double curx, cury; // The ending x,y of the last segment
double movx, movy; // The x,y of the last move segment
int holdType; // The type of the curve being held
// for interpolation
int holdEnd; // The index of the last curve segment
// being held for interpolation
int holdIndex; // The index of the curve segment
// that was last interpolated. This
// is the curve segment ready to be
// returned in the next call to
// currentSegment().
int levels[]; // The recursion level at which
// each curve being held in storage
// was generated.
int levelIndex; // The index of the entry in the
// levels array of the curve segment
// at the holdIndex
boolean done; // True when iteration is done
/**
* Constructs a new <code>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.
* @param src the original unflattened path being iterated over
* @param flatness the maximum allowable distance between the
* control points and the flattened curve
*/
public FlatteningPathIterator(PathIterator src, double flatness) {
this(src, flatness, 10);
}
/**
* Constructs a new <code>FlatteningPathIterator object
* that flattens a path as it iterates over it.
* The <code>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 <code>flatness parameter.
* The flattened iteration therefore never generates more than
* a maximum of <code>(2^limit) line segments per curve.
* @param src the original unflattened path being iterated over
* @param flatness the maximum allowable distance between the
* control points and the flattened curve
* @param limit the maximum number of recursive subdivisions
* allowed for any curved segment
* @exception IllegalArgumentException if
* <code>flatness or
Other Java examples (source code examples)Here is a short list of links related to this Java FlatteningPathIterator.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.