jdk/src/share/classes/java/awt/geom/Path2D.java
author flar
Mon, 02 May 2011 14:38:22 -0700
changeset 9469 b8ea6866765a
parent 5506 202f599c92aa
child 11080 7e18e343964e
permissions -rw-r--r--
6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Shape;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import sun.awt.geom.Curve;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.StreamCorruptedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The {@code Path2D} class provides a simple, yet flexible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * shape which represents an arbitrary geometric path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * It can fully represent any path which can be iterated by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * {@link PathIterator} interface including all of its segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * types and winding rules and it implements all of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * basic hit testing methods of the {@link Shape} interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Use {@link Path2D.Float} when dealing with data that can be represented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * and used with floating point precision.  Use {@link Path2D.Double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * for data that requires the accuracy or range of double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * {@code Path2D} provides exactly those facilities required for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * basic construction and management of a geometric path and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * implementation of the above interfaces with little added
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * interpretation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * If it is useful to manipulate the interiors of closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * geometric shapes beyond simple hit testing then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * {@link Area} class provides additional capabilities
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * specifically targeted at closed figures.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * While both classes nominally implement the {@code Shape}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * interface, they differ in purpose and together they provide
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * two useful views of a geometric shape where {@code Path2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * deals primarily with a trajectory formed by path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * and {@code Area} deals more with interpretation and manipulation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * of enclosed regions of 2D geometric space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * The {@link PathIterator} interface has more detailed descriptions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * of the types of segments that make up a path and the winding rules
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * that control how to determine which regions are inside or outside
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @author Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
public abstract class Path2D implements Shape, Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * An even-odd winding rule for determining the interior of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * a path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * @see PathIterator#WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    public static final int WIND_EVEN_ODD = PathIterator.WIND_EVEN_ODD;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * A non-zero winding rule for determining the interior of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @see PathIterator#WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final int WIND_NON_ZERO = PathIterator.WIND_NON_ZERO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    // For code simplicity, copy these constants to our namespace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // and cast them to byte constants for easy storage.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final byte SEG_MOVETO  = (byte) PathIterator.SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    private static final byte SEG_LINETO  = (byte) PathIterator.SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private static final byte SEG_QUADTO  = (byte) PathIterator.SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final byte SEG_CUBICTO = (byte) PathIterator.SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private static final byte SEG_CLOSE   = (byte) PathIterator.SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    transient byte[] pointTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    transient int numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    transient int numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    transient int windingRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    static final int INIT_SIZE = 20;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static final int EXPAND_MAX = 500;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * Constructs a new empty {@code Path2D} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * It is assumed that the package sibling subclass that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * defaulting to this constructor will fill in all values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /* private protected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    Path2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Constructs a new {@code Path2D} object from the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * specified initial values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * This method is only intended for internal use and should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * not be made public if the other constructors for this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * are ever exposed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param initialTypes the size to make the initial array to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     *                     store the path segment types
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /* private protected */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    Path2D(int rule, int initialTypes) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        setWindingRule(rule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.pointTypes = new byte[initialTypes];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    abstract float[] cloneCoordsFloat(AffineTransform at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    abstract double[] cloneCoordsDouble(AffineTransform at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    abstract void append(float x, float y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    abstract void append(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    abstract Point2D getPoint(int coordindex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    abstract void needRoom(boolean needMove, int newCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    abstract int pointCrossings(double px, double py);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    abstract int rectCrossings(double rxmin, double rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                               double rxmax, double rymax);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * The {@code Float} class defines a geometric path with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * coordinates stored in single precision floating point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    public static class Float extends Path2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        transient float floatCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * Constructs a new empty single precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * with a default winding rule of {@link #WIND_NON_ZERO}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public Float() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            this(WIND_NON_ZERO, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * Constructs a new empty single precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * with the specified winding rule to control operations that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * require the interior of the path to be defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        public Float(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            this(rule, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         * Constructs a new empty single precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
         * with the specified winding rule and the specified initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
         * capacity to store path segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
         * This number is an initial guess as to how many path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * will be added to the path, but the storage is expanded as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * needed to store whatever path segments are added.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * @param initialCapacity the estimate for the number of path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         *                        in the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public Float(int rule, int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            super(rule, initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            floatCoords = new float[initialCapacity * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         * Constructs a new single precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
         * from an arbitrary {@link Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * taken from the specified {@code Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        public Float(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            this(s, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * Constructs a new single precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * from an arbitrary {@link Shape} object, transformed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * {@link AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * taken from the specified {@code Shape} object and transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         * by the specified {@code AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * @param at the specified {@code AffineTransform} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        public Float(Shape s, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (s instanceof Path2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                Path2D p2d = (Path2D) s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                setWindingRule(p2d.windingRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                this.numTypes = p2d.numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
                this.pointTypes = Arrays.copyOf(p2d.pointTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
                                                p2d.pointTypes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                this.numCoords = p2d.numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                this.floatCoords = p2d.cloneCoordsFloat(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                PathIterator pi = s.getPathIterator(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                setWindingRule(pi.getWindingRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                this.pointTypes = new byte[INIT_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                this.floatCoords = new float[INIT_SIZE * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                append(pi, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        float[] cloneCoordsFloat(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            float ret[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                ret = Arrays.copyOf(this.floatCoords, this.floatCoords.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                ret = new float[floatCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                at.transform(floatCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        double[] cloneCoordsDouble(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            double ret[] = new double[floatCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    ret[i] = floatCoords[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                at.transform(floatCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        void append(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            floatCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            floatCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        void append(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            floatCoords[numCoords++] = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            floatCoords[numCoords++] = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        Point2D getPoint(int coordindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return new Point2D.Float(floatCoords[coordindex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                                     floatCoords[coordindex+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        void needRoom(boolean needMove, int newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (needMove && numTypes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                throw new IllegalPathStateException("missing initial moveto "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                                                    "in path definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            int size = pointTypes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            if (numTypes >= size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                if (grow > EXPAND_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                    grow = EXPAND_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                pointTypes = Arrays.copyOf(pointTypes, size+grow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            size = floatCoords.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            if (numCoords + newCoords > size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                if (grow > EXPAND_MAX * 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                    grow = EXPAND_MAX * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                if (grow < newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                    grow = newCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                floatCoords = Arrays.copyOf(floatCoords, size+grow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        public final synchronized void moveTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                floatCoords[numCoords-2] = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                floatCoords[numCoords-1] = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                needRoom(false, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                pointTypes[numTypes++] = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
                floatCoords[numCoords++] = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                floatCoords[numCoords++] = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
         * Adds a point to the path by moving to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
         * coordinates specified in float precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         * This method provides a single precision variant of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * the double precision {@code moveTo()} method on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * base {@code Path2D} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * @see Path2D#moveTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        public final synchronized void moveTo(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
                floatCoords[numCoords-2] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                floatCoords[numCoords-1] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
                needRoom(false, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                pointTypes[numTypes++] = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                floatCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                floatCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        public final synchronized void lineTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            needRoom(true, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            pointTypes[numTypes++] = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            floatCoords[numCoords++] = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
            floatCoords[numCoords++] = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * Adds a point to the path by drawing a straight line from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * current coordinates to the new specified coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * specified in float precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * This method provides a single precision variant of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * the double precision {@code lineTo()} method on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         * base {@code Path2D} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
         * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
         * @see Path2D#lineTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        public final synchronized void lineTo(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            needRoom(true, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            pointTypes[numTypes++] = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            floatCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            floatCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        public final synchronized void quadTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
                                              double x2, double y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            needRoom(true, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            pointTypes[numTypes++] = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            floatCoords[numCoords++] = (float) x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            floatCoords[numCoords++] = (float) y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            floatCoords[numCoords++] = (float) x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            floatCoords[numCoords++] = (float) y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * Adds a curved segment, defined by two new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         * drawing a Quadratic curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
         * coordinates and the specified coordinates {@code (x2,y2)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
         * using the specified point {@code (x1,y1)} as a quadratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
         * parametric control point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * All coordinates are specified in float precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * This method provides a single precision variant of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * the double precision {@code quadTo()} method on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         * base {@code Path2D} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
         * @param x1 the X coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
         * @param y1 the Y coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * @param x2 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * @param y2 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * @see Path2D#quadTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public final synchronized void quadTo(float x1, float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                                              float x2, float y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            needRoom(true, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            pointTypes[numTypes++] = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            floatCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            floatCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            floatCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            floatCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        public final synchronized void curveTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                                               double x2, double y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                                               double x3, double y3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            needRoom(true, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            pointTypes[numTypes++] = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            floatCoords[numCoords++] = (float) x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            floatCoords[numCoords++] = (float) y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            floatCoords[numCoords++] = (float) x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            floatCoords[numCoords++] = (float) y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            floatCoords[numCoords++] = (float) x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            floatCoords[numCoords++] = (float) y3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         * Adds a curved segment, defined by three new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         * drawing a B&eacute;zier curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         * coordinates and the specified coordinates {@code (x3,y3)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
         * using the specified points {@code (x1,y1)} and {@code (x2,y2)} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
         * B&eacute;zier control points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
         * All coordinates are specified in float precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
         * This method provides a single precision variant of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
         * the double precision {@code curveTo()} method on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         * base {@code Path2D} class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         * @param x1 the X coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         * @param y1 the Y coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         * @param x2 the X coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         * @param y2 the Y coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         * @param x3 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         * @param y3 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
         * @see Path2D#curveTo
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
        public final synchronized void curveTo(float x1, float y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                               float x2, float y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
                                               float x3, float y3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            needRoom(true, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            pointTypes[numTypes++] = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            floatCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            floatCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            floatCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            floatCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            floatCoords[numCoords++] = x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            floatCoords[numCoords++] = y3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        int pointCrossings(double px, double py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            double movx, movy, curx, cury, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            float coords[] = floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            for (int i = 1; i < numTypes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                                                    endy = coords[ci++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                        Curve.pointCrossingsForQuad(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        Curve.pointCrossingsForCubic(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                                     curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                                                     endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                                                     endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                                                     0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                                                curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                                                movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        int rectCrossings(double rxmin, double rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                          double rxmax, double rymax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            float coords[] = floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
            double curx, cury, movx, movy, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
            for (int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
                 crossings != Curve.RECT_INTERSECTS && i < numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
                 i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                        Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                                                   endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                                                   endy = coords[ci++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                        Curve.rectCrossingsForQuad(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                                   endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                                   endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                                   0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                        Curve.rectCrossingsForCubic(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                                    rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                                                    rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
            if (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                (curx != movx || cury != movy))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                    Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                                               rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                                               rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                                               curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                                               movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        public final void append(PathIterator pi, boolean connect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            float coords[] = new float[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                switch (pi.currentSegment(coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    if (!connect || numTypes < 1 || numCoords < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                        moveTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    if (pointTypes[numTypes - 1] != SEG_CLOSE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                        floatCoords[numCoords-2] == coords[0] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                        floatCoords[numCoords-1] == coords[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
                        // Collapse out initial moveto/lineto
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
                    // NO BREAK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    lineTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                    quadTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                           coords[2], coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                    curveTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                            coords[2], coords[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                            coords[4], coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                    closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                connect = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
        public final void transform(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            at.transform(floatCoords, 0, floatCoords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
        public final synchronized Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
            float x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            int i = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
                y1 = y2 = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                x1 = x2 = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                while (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                    float y = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    float x = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    if (x < x1) x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    if (y < y1) y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    if (x > x2) x2 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    if (y > y2) y2 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
                x1 = y1 = x2 = y2 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            return new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         * which means that the {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
         * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
         * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
         * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
   735
        public final PathIterator getPathIterator(AffineTransform at) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                return new CopyIterator(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
                return new TxIterator(this, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
         * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         * @exception  OutOfMemoryError    if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
        public final Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
            // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            if (this instanceof GeneralPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
                return new GeneralPath(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                return new Path2D.Float(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        private static final long serialVersionUID = 6990832515060788886L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         * {@code ObjectOutputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * <a name="Path2DSerialData"><!-- --></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * a byte indicating the storage type of the original object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * as a hint (SERIAL_STORAGE_FLT_ARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * an integer indicating the number of path segments to follow (NP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * or -1 to indicate an unknown number of path segments follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         * an integer indicating the total number of coordinates to follow (NC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * or -1 to indicate an unknown number of coordinates follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         * (NC should always be even since coordinates always appear in pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         *  representing an x,y pair)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         * a byte indicating the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         * NP (or unlimited if NP < 0) sets of values consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * a single byte indicating a path segment type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         * followed by one or more pairs of float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         * values representing the coordinates of the path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         * a byte indicating the end of the path (SERIAL_PATH_END).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         * The following byte value constants are used in the serialized form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         * of {@code Path2D} objects:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         * <table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
         * <th>Constant Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         * <th>Byte Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         * <th>Followed by</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
         * <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
         * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
         * <td>0x30</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
         * the coordinates in a Java array of floats.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
         * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         * <td>0x31</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
         * the coordinates in a Java array of doubles.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
         * <td>{@code SERIAL_SEG_FLT_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
         * <td>0x40</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
         * <td>{@code SERIAL_SEG_FLT_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
         * <td>0x41</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
         * <td>{@code SERIAL_SEG_FLT_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         * <td>0x42</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
         * <td>4 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
         * <td>A {@link #quadTo quadTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
         * <td>{@code SERIAL_SEG_FLT_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
         * <td>0x43</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
         * <td>6 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * <td>{@code SERIAL_SEG_DBL_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * <td>0x50</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         * <td>{@code SERIAL_SEG_DBL_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         * <td>0x51</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * <td>{@code SERIAL_SEG_DBL_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         * <td>0x52</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * <td>4 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         * <td>{@code SERIAL_SEG_DBL_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * <td>0x53</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * <td>6 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * <td>{@code SERIAL_SEG_CLOSE}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         * <td>0x60</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * <td>A {@link #closePath closePath} path segment.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * <td>{@code SERIAL_PATH_END}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * <td>0x61</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         * <td>There are no more path segments following.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
            super.writeObject(s, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         * {@code ObjectInputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         * The serial data for this object is described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
         * writeObject method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
            super.readObject(s, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
        static class CopyIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
            float floatCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
            CopyIterator(Path2D.Float p2df) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
                super(p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                this.floatCoords = p2df.floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                    System.arraycopy(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                                     coords, 0, numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                    for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                        coords[i] = floatCoords[pointIdx + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        static class TxIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
            float floatCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            AffineTransform affine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
            TxIterator(Path2D.Float p2df, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
                super(p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                this.floatCoords = p2df.floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                this.affine = at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                    affine.transform(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                    affine.transform(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
     * The {@code Double} class defines a geometric path with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * coordinates stored in double precision floating point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
    public static class Double extends Path2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
        transient double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         * with a default winding rule of {@link #WIND_NON_ZERO}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
        public Double() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
            this(WIND_NON_ZERO, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * with the specified winding rule to control operations that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         * require the interior of the path to be defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
        public Double(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
            this(rule, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
         * with the specified winding rule and the specified initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
         * capacity to store path segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
         * This number is an initial guess as to how many path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
         * are in the path, but the storage is expanded as needed to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * whatever path segments are added to this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
         * @param initialCapacity the estimate for the number of path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
         *                        in the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
        public Double(int rule, int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            super(rule, initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            doubleCoords = new double[initialCapacity * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
         * Constructs a new double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
         * from an arbitrary {@link Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         * taken from the specified {@code Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        public Double(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
            this(s, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         * Constructs a new double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
         * from an arbitrary {@link Shape} object, transformed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         * {@link AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * taken from the specified {@code Shape} object and transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * by the specified {@code AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * @param at the specified {@code AffineTransform} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
        public Double(Shape s, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
            if (s instanceof Path2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
                Path2D p2d = (Path2D) s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                setWindingRule(p2d.windingRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                this.numTypes = p2d.numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                this.pointTypes = Arrays.copyOf(p2d.pointTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                                                p2d.pointTypes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                this.numCoords = p2d.numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                this.doubleCoords = p2d.cloneCoordsDouble(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                PathIterator pi = s.getPathIterator(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                setWindingRule(pi.getWindingRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                this.pointTypes = new byte[INIT_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                this.doubleCoords = new double[INIT_SIZE * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                append(pi, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
        float[] cloneCoordsFloat(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            float ret[] = new float[doubleCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
                for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                    ret[i] = (float) doubleCoords[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        double[] cloneCoordsDouble(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
            double ret[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
                ret = Arrays.copyOf(this.doubleCoords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                                    this.doubleCoords.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
                ret = new double[doubleCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        void append(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
        void append(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
        Point2D getPoint(int coordindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
            return new Point2D.Double(doubleCoords[coordindex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
                                      doubleCoords[coordindex+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        void needRoom(boolean needMove, int newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
            if (needMove && numTypes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
                throw new IllegalPathStateException("missing initial moveto "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                                                    "in path definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            int size = pointTypes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            if (numTypes >= size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                if (grow > EXPAND_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                    grow = EXPAND_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                pointTypes = Arrays.copyOf(pointTypes, size+grow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            size = doubleCoords.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            if (numCoords + newCoords > size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                if (grow > EXPAND_MAX * 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    grow = EXPAND_MAX * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                if (grow < newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                    grow = newCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                doubleCoords = Arrays.copyOf(doubleCoords, size+grow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
        public final synchronized void moveTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
                doubleCoords[numCoords-2] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                doubleCoords[numCoords-1] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                needRoom(false, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                pointTypes[numTypes++] = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        public final synchronized void lineTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            needRoom(true, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            pointTypes[numTypes++] = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
        public final synchronized void quadTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
                                              double x2, double y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
            needRoom(true, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            pointTypes[numTypes++] = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            doubleCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            doubleCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            doubleCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            doubleCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        public final synchronized void curveTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
                                               double x2, double y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                                               double x3, double y3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            needRoom(true, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            pointTypes[numTypes++] = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            doubleCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            doubleCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            doubleCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            doubleCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            doubleCoords[numCoords++] = x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            doubleCoords[numCoords++] = y3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        int pointCrossings(double px, double py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            double movx, movy, curx, cury, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            double coords[] = doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            for (int i = 1; i < numTypes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                        Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                                                    endy = coords[ci++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                        Curve.pointCrossingsForQuad(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                        Curve.pointCrossingsForCubic(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                                                     curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
                                                     endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                                                     endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                                                     0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
                crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                    Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                                                curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                                movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        int rectCrossings(double rxmin, double rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
                          double rxmax, double rymax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
            double coords[] = doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            double curx, cury, movx, movy, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            for (int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                 crossings != Curve.RECT_INTERSECTS && i < numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                 i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                    endx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    endy = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                        Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                                                   endx, endy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                        Curve.rectCrossingsForQuad(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                                                   endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                                                   endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                                                   0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                        Curve.rectCrossingsForCubic(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                                                    rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                                                    rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            if (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
                (curx != movx || cury != movy))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
                crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                    Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                                               rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                                               rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                                               curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                               movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        public final void append(PathIterator pi, boolean connect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
            double coords[] = new double[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
                switch (pi.currentSegment(coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                    if (!connect || numTypes < 1 || numCoords < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                        moveTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                    if (pointTypes[numTypes - 1] != SEG_CLOSE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                        doubleCoords[numCoords-2] == coords[0] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        doubleCoords[numCoords-1] == coords[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                        // Collapse out initial moveto/lineto
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    // NO BREAK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
                    lineTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    quadTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                           coords[2], coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                    curveTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                            coords[2], coords[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                            coords[4], coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                connect = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
        public final void transform(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
            at.transform(doubleCoords, 0, doubleCoords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
        public final synchronized Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            double x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
            int i = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
                y1 = y2 = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
                x1 = x2 = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                while (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                    double y = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                    double x = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                    if (x < x1) x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    if (y < y1) y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                    if (x > x2) x2 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    if (y > y2) y2 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                x1 = y1 = x2 = y2 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
            return new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
         * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * which means that the {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
         * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
         * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
         * @param at an {@code AffineTransform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         * @return a new {@code PathIterator} that iterates along the boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
         *         of this {@code Shape} and provides access to the geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
         *         of this {@code Shape}'s outline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
         */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  1464
        public final PathIterator getPathIterator(AffineTransform at) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                return new CopyIterator(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                return new TxIterator(this, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
         * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
         * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
         * @exception  OutOfMemoryError    if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
         * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
         * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
        public final Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
            // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            return new Path2D.Double(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
        private static final long serialVersionUID = 1826762518450014216L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
         * {@code ObjectOutputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
         * <a name="Path2DSerialData"><!-- --></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         * a byte indicating the storage type of the original object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         * as a hint (SERIAL_STORAGE_DBL_ARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
         * an integer indicating the number of path segments to follow (NP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
         * or -1 to indicate an unknown number of path segments follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
         * an integer indicating the total number of coordinates to follow (NC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         * or -1 to indicate an unknown number of coordinates follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         * (NC should always be even since coordinates always appear in pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         *  representing an x,y pair)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
         * a byte indicating the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
         *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         * NP (or unlimited if NP < 0) sets of values consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * a single byte indicating a path segment type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * followed by one or more pairs of float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         * values representing the coordinates of the path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         * a byte indicating the end of the path (SERIAL_PATH_END).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         * The following byte value constants are used in the serialized form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         * of {@code Path2D} objects:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         * <table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         * <th>Constant Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * <th>Byte Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         * <th>Followed by</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
         * <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
         * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
         * <td>0x30</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         * the coordinates in a Java array of floats.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * <td>0x31</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
         * the coordinates in a Java array of doubles.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
         * <td>{@code SERIAL_SEG_FLT_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
         * <td>0x40</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         * <td>{@code SERIAL_SEG_FLT_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         * <td>0x41</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
         * <td>{@code SERIAL_SEG_FLT_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
         * <td>0x42</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
         * <td>4 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * <td>A {@link #quadTo quadTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
         * <td>{@code SERIAL_SEG_FLT_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
         * <td>0x43</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
         * <td>6 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
         * <td>{@code SERIAL_SEG_DBL_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
         * <td>0x50</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
         * <td>{@code SERIAL_SEG_DBL_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
         * <td>0x51</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
         * <td>{@code SERIAL_SEG_DBL_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
         * <td>0x52</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
         * <td>4 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
         * <td>{@code SERIAL_SEG_DBL_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
         * <td>0x53</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
         * <td>6 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
         * <td>{@code SERIAL_SEG_CLOSE}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
         * <td>0x60</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
         * <td>A {@link #closePath closePath} path segment.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
         * <td>{@code SERIAL_PATH_END}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
         * <td>0x61</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         * <td>There are no more path segments following.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
         * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            super.writeObject(s, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
         * {@code ObjectInputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
         * The serial data for this object is described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
         * writeObject method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            super.readObject(s, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        static class CopyIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
            double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            CopyIterator(Path2D.Double p2dd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
                super(p2dd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
                this.doubleCoords = p2dd.doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                        coords[i] = (float) doubleCoords[pointIdx + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                    System.arraycopy(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                                     coords, 0, numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        static class TxIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
            AffineTransform affine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            TxIterator(Path2D.Double p2dd, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
                super(p2dd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
                this.doubleCoords = p2dd.doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                this.affine = at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                    affine.transform(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                    affine.transform(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * Adds a point to the path by moving to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * coordinates specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
    public abstract void moveTo(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * Adds a point to the path by drawing a straight line from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * current coordinates to the new specified coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
    public abstract void lineTo(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * Adds a curved segment, defined by two new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
     * drawing a Quadratic curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * coordinates and the specified coordinates {@code (x2,y2)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * using the specified point {@code (x1,y1)} as a quadratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * parametric control point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * All coordinates are specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * @param x1 the X coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * @param y1 the Y coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @param x2 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * @param y2 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
    public abstract void quadTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
                                double x2, double y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
     * Adds a curved segment, defined by three new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
     * drawing a B&eacute;zier curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * coordinates and the specified coordinates {@code (x3,y3)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * using the specified points {@code (x1,y1)} and {@code (x2,y2)} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * B&eacute;zier control points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * All coordinates are specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * @param x1 the X coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     * @param y1 the Y coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * @param x2 the X coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * @param y2 the Y coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @param x3 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * @param y3 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
    public abstract void curveTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
                                 double x2, double y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
                                 double x3, double y3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * Closes the current subpath by drawing a straight line back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * the coordinates of the last {@code moveTo}.  If the path is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * closed then this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
    public final synchronized void closePath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
        if (numTypes == 0 || pointTypes[numTypes - 1] != SEG_CLOSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
            needRoom(true, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
            pointTypes[numTypes++] = SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
     * Appends the geometry of the specified {@code Shape} object to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
     * path, possibly connecting the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * segments with a line segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * If the {@code connect} parameter is {@code true} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * path is not empty then any initial {@code moveTo} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * geometry of the appended {@code Shape}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * is turned into a {@code lineTo} segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * If the destination coordinates of such a connecting {@code lineTo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * segment match the ending coordinates of a currently open
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * subpath then the segment is omitted as superfluous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * The winding rule of the specified {@code Shape} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * and the appended geometry is governed by the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * rule specified for this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * @param s the {@code Shape} whose geometry is appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     *          to this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * @param connect a boolean to control whether or not to turn an initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     *                {@code moveTo} segment into a {@code lineTo} segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     *                to connect the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
    public final void append(Shape s, boolean connect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
        append(s.getPathIterator(null), connect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * Appends the geometry of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * {@link PathIterator} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * to the path, possibly connecting the new geometry to the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * path segments with a line segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * If the {@code connect} parameter is {@code true} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * path is not empty then any initial {@code moveTo} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * geometry of the appended {@code Shape} is turned into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * {@code lineTo} segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * If the destination coordinates of such a connecting {@code lineTo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * segment match the ending coordinates of a currently open
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * subpath then the segment is omitted as superfluous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * The winding rule of the specified {@code Shape} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * and the appended geometry is governed by the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * rule specified for this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * @param pi the {@code PathIterator} whose geometry is appended to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     *           this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @param connect a boolean to control whether or not to turn an initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     *                {@code moveTo} segment into a {@code lineTo} segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     *                to connect the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
    public abstract void append(PathIterator pi, boolean connect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * Returns the fill style winding rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * @return an integer representing the current winding rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * @see #setWindingRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
    public final synchronized int getWindingRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
        return windingRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * Sets the winding rule for this path to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * @param rule an integer representing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     *             winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     *          {@code rule} is not either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     *          {@link #WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     *          {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     * @see #getWindingRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
    public final void setWindingRule(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
        if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
            throw new IllegalArgumentException("winding rule must be "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
                                               "WIND_EVEN_ODD or "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
                                               "WIND_NON_ZERO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        windingRule = rule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
     * Returns the coordinates most recently added to the end of the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
     * as a {@link Point2D} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * @return a {@code Point2D} object containing the ending coordinates of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *         the path or {@code null} if there are no points in the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
    public final synchronized Point2D getCurrentPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
        int index = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        if (numTypes < 1 || index < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
        if (pointTypes[numTypes - 1] == SEG_CLOSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
            for (int i = numTypes - 2; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    index -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    index -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    index -= 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
        return getPoint(index - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
     * Resets the path to empty.  The append position is set back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
     * beginning of the path and all coordinates and point types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * forgotten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
    public final synchronized void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
        numTypes = numCoords = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
     * Transforms the geometry of this path using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
     * {@link AffineTransform}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     * The geometry is transformed in place, which permanently changes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     * boundary defined by this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * @param at the {@code AffineTransform} used to transform the area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
    public abstract void transform(AffineTransform at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
     * Returns a new {@code Shape} representing a transformed version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
     * of this {@code Path2D}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * Note that the exact type and coordinate precision of the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * value is not specified for this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * The method will return a Shape that contains no less precision
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * for the transformed geometry than this {@code Path2D} currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * maintains, but it may contain no more precision either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * If the tradeoff of precision vs. storage size in the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * important then the convenience constructors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * {@link Path2D.Float#Path2D.Float(Shape, AffineTransform) Path2D.Float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * {@link Path2D.Double#Path2D.Double(Shape, AffineTransform) Path2D.Double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * subclasses should be used to make the choice explicit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * @param at the {@code AffineTransform} used to transform a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     *           new {@code Shape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * @return a new {@code Shape}, transformed with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *         {@code AffineTransform}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    public final synchronized Shape createTransformedShape(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
        Path2D p2d = (Path2D) clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
        if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
            p2d.transform(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
        return p2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
    public final Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
        return getBounds2D().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
     * Tests if the specified coordinates are inside the closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
     * boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * {@link Shape#contains(double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @return {@code true} if the specified coordinates are inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     *         specified {@code PathIterator}; {@code false} otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    public static boolean contains(PathIterator pi, double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
        if (x * 0.0 + y * 0.0 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
            /* N * 0.0 is 0.0 only if N is finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
             * Here we know that both x and y are finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
            int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            int cross = Curve.pointCrossingsForPath(pi, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            return ((cross & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            /* Either x or y was infinite or NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
             * A NaN always produces a negative response to any test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
             * and Infinity values cannot be "inside" any path so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
             * they should return false as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
     * Tests if the specified {@link Point2D} is inside the closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
     * boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * {@link Shape#contains(Point2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     * @param p the specified {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * @return {@code true} if the specified coordinates are inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     *         specified {@code PathIterator}; {@code false} otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
    public static boolean contains(PathIterator pi, Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        return contains(pi, p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
    public final boolean contains(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        if (x * 0.0 + y * 0.0 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            /* N * 0.0 is 0.0 only if N is finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
             * Here we know that both x and y are finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
            if (numTypes < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            int mask = (windingRule == WIND_NON_ZERO ? -1 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            return ((pointCrossings(x, y) & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            /* Either x or y was infinite or NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
             * A NaN always produces a negative response to any test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
             * and Infinity values cannot be "inside" any path so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
             * they should return false as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
    public final boolean contains(Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
        return contains(p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
     * Tests if the specified rectangular area is entirely inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
     * closed boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * {@link Shape#contains(double, double, double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * @param w the width of the specified rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * @param h the height of the specified rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * @return {@code true} if the specified {@code PathIterator} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     *         the specified rectangluar area; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
    public static boolean contains(PathIterator pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
                                   double x, double y, double w, double h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
        int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        return (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
     * Tests if the specified {@link Rectangle2D} is entirely inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
     * closed boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * {@link Shape#contains(Rectangle2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     * @param r a specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * @return {@code true} if the specified {@code PathIterator} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     *         the specified {@code Rectangle2D}; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    public static boolean contains(PathIterator pi, Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        return contains(pi, r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
    public final boolean contains(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
        int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        int crossings = rectCrossings(x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        return (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
    public final boolean contains(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
        return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
     * Tests if the interior of the specified {@link PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
     * intersects the interior of a specified set of rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * {@link Shape#intersects(double, double, double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * @param w the width of the specified rectangular coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * @param h the height of the specified rectangular coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * @return {@code true} if the specified {@code PathIterator} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     *         the interior of the specified set of rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     *         coordinates intersect each other; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
    public static boolean intersects(PathIterator pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
                                     double x, double y, double w, double h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
        int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        return (crossings == Curve.RECT_INTERSECTS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
     * Tests if the interior of the specified {@link PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
     * intersects the interior of a specified {@link Rectangle2D}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * {@link Shape#intersects(Rectangle2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     * @param r the specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * @return {@code true} if the specified {@code PathIterator} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     *         the interior of the specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     *         intersect each other; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
    public static boolean intersects(PathIterator pi, Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
        return intersects(pi, r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
    public final boolean intersects(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        int crossings = rectCrossings(x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        return (crossings == Curve.RECT_INTERSECTS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
    public final boolean intersects(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
        return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * which means that this {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  2345
    public final PathIterator getPathIterator(AffineTransform at,
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  2346
                                              double flatness)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2347
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2348
        return new FlatteningPathIterator(getPathIterator(at), flatness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
     * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     * @exception  OutOfMemoryError            if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
    public abstract Object clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
        // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
        // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
        // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
        // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
     * Support fields and methods for serializing the subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
    private static final byte SERIAL_STORAGE_FLT_ARRAY = 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
    private static final byte SERIAL_STORAGE_DBL_ARRAY = 0x31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    private static final byte SERIAL_SEG_FLT_MOVETO    = 0x40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
    private static final byte SERIAL_SEG_FLT_LINETO    = 0x41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
    private static final byte SERIAL_SEG_FLT_QUADTO    = 0x42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
    private static final byte SERIAL_SEG_FLT_CUBICTO   = 0x43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
    private static final byte SERIAL_SEG_DBL_MOVETO    = 0x50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
    private static final byte SERIAL_SEG_DBL_LINETO    = 0x51;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
    private static final byte SERIAL_SEG_DBL_QUADTO    = 0x52;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    private static final byte SERIAL_SEG_DBL_CUBICTO   = 0x53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    private static final byte SERIAL_SEG_CLOSE         = 0x60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
    private static final byte SERIAL_PATH_END          = 0x61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
    final void writeObject(java.io.ObjectOutputStream s, boolean isdbl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
        throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        float fCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
        double dCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
            dCoords = ((Path2D.Double) this).doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
            fCoords = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            fCoords = ((Path2D.Float) this).floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
            dCoords = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        int numTypes = this.numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        s.writeByte(isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
                    ? SERIAL_STORAGE_DBL_ARRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
                    : SERIAL_STORAGE_FLT_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
        s.writeInt(numTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
        s.writeInt(numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        s.writeByte((byte) windingRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        int cindex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
        for (int i = 0; i < numTypes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
            int npoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
            byte serialtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
            case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                              ? SERIAL_SEG_DBL_MOVETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                              : SERIAL_SEG_FLT_MOVETO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
            case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                              ? SERIAL_SEG_DBL_LINETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                              : SERIAL_SEG_FLT_LINETO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
            case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                              ? SERIAL_SEG_DBL_QUADTO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                              : SERIAL_SEG_FLT_QUADTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
            case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                              ? SERIAL_SEG_DBL_CUBICTO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                              : SERIAL_SEG_FLT_CUBICTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
            case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
                npoints = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
                serialtype = SERIAL_SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
                // Should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
                throw new InternalError("unrecognized path type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            s.writeByte(serialtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
                if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
                    s.writeDouble(dCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                    s.writeDouble(dCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                    s.writeFloat(fCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
                    s.writeFloat(fCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
        s.writeByte((byte) SERIAL_PATH_END);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
    final void readObject(java.io.ObjectInputStream s, boolean storedbl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        // The subclass calls this method with the storage type that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
        // they want us to use (storedbl) so we ignore the storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        // method hint from the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        s.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        int nT = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        int nC = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
            setWindingRule(s.readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            throw new java.io.InvalidObjectException(iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        pointTypes = new byte[(nT < 0) ? INIT_SIZE : nT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
        if (nC < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
            nC = INIT_SIZE * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        if (storedbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
            ((Path2D.Double) this).doubleCoords = new double[nC];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
            ((Path2D.Float) this).floatCoords = new float[nC];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
    PATHDONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
        for (int i = 0; nT < 0 || i < nT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            boolean isdbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
            int npoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
            byte segtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            byte serialtype = s.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
            switch (serialtype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
            case SERIAL_SEG_FLT_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                segtype = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
            case SERIAL_SEG_FLT_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                segtype = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
            case SERIAL_SEG_FLT_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                segtype = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            case SERIAL_SEG_FLT_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                segtype = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
            case SERIAL_SEG_DBL_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                segtype = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
            case SERIAL_SEG_DBL_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
                segtype = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
            case SERIAL_SEG_DBL_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                segtype = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
            case SERIAL_SEG_DBL_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                segtype = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
            case SERIAL_SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
                npoints = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                segtype = SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            case SERIAL_PATH_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
                if (nT < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
                    break PATHDONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
                throw new StreamCorruptedException("unexpected PATH_END");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
                throw new StreamCorruptedException("unrecognized path type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
            needRoom(segtype != SEG_MOVETO, npoints * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
                while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
                    append(s.readDouble(), s.readDouble());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
                while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
                    append(s.readFloat(), s.readFloat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
            pointTypes[numTypes++] = segtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
        if (nT >= 0 && s.readByte() != SERIAL_PATH_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
            throw new StreamCorruptedException("missing PATH_END");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    static abstract class Iterator implements PathIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
        int typeIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
        int pointIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
        Path2D path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
        static final int curvecoords[] = {2, 2, 4, 6, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
        Iterator(Path2D path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
            this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        public int getWindingRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
            return path.getWindingRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        public boolean isDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
            return (typeIdx >= path.numTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        public void next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
            int type = path.pointTypes[typeIdx++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
            pointIdx += curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
}