jdk/src/share/classes/java/awt/geom/Path2D.java
author neugens
Sat, 03 Dec 2011 15:40:49 +0100
changeset 11080 7e18e343964e
parent 9469 b8ea6866765a
child 21278 ef8a3a2a72f2
permissions -rw-r--r--
7117914: Fix javac warnings in src/share/classes/sun/java2d Summary: Fix some javac warnings in java2d related code for the Warning Cleanup Day. Reviewed-by: prr, flar
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
                    }
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9469
diff changeset
   670
                    lineTo(coords[0], coords[1]);
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9469
diff changeset
   671
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                    lineTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
                    quadTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                           coords[2], coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                    curveTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                            coords[2], coords[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                            coords[4], coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
                connect = false;
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
        public final void transform(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
            at.transform(floatCoords, 0, floatCoords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
        public final synchronized Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
            float x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            int i = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
                y1 = y2 = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
                x1 = x2 = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
                while (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
                    float y = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
                    float x = floatCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
                    if (x < x1) x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
                    if (y < y1) y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
                    if (x > x2) x2 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
                    if (y > y2) y2 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                x1 = y1 = x2 = y2 = 0.0f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            return new Rectangle2D.Float(x1, y1, x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
         * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
         * which means that the {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
         * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
         * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
         * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
         */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
   736
        public final PathIterator getPathIterator(AffineTransform at) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
                return new CopyIterator(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
                return new TxIterator(this, at);
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
         * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
         * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
         * @exception  OutOfMemoryError    if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
         * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
         * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
        public final Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
            // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
            // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
            if (this instanceof GeneralPath) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
                return new GeneralPath(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
                return new Path2D.Float(this);
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
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        private static final long serialVersionUID = 6990832515060788886L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
         * {@code ObjectOutputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
         * <a name="Path2DSerialData"><!-- --></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
         * a byte indicating the storage type of the original object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
         * as a hint (SERIAL_STORAGE_FLT_ARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
         * an integer indicating the number of path segments to follow (NP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
         * or -1 to indicate an unknown number of path segments follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
         * an integer indicating the total number of coordinates to follow (NC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
         * or -1 to indicate an unknown number of coordinates follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
         * (NC should always be even since coordinates always appear in pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
         *  representing an x,y pair)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
         * a byte indicating the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
         * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
         *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
         * NP (or unlimited if NP < 0) sets of values consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
         * a single byte indicating a path segment type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
         * followed by one or more pairs of float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
         * values representing the coordinates of the path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
         * a byte indicating the end of the path (SERIAL_PATH_END).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
         * The following byte value constants are used in the serialized form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
         * of {@code Path2D} objects:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
         * <table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
         * <th>Constant Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
         * <th>Byte Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
         * <th>Followed by</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
         * <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
         * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
         * <td>0x30</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
         * the coordinates in a Java array of floats.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
         * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
         * <td>0x31</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
         * the coordinates in a Java array of doubles.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
         * <td>{@code SERIAL_SEG_FLT_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
         * <td>0x40</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
         * <td>{@code SERIAL_SEG_FLT_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
         * <td>0x41</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
         * <td>{@code SERIAL_SEG_FLT_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
         * <td>0x42</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
         * <td>4 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
         * <td>A {@link #quadTo quadTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
         * <td>{@code SERIAL_SEG_FLT_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
         * <td>0x43</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
         * <td>6 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
         * <td>{@code SERIAL_SEG_DBL_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
         * <td>0x50</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
         * <td>{@code SERIAL_SEG_DBL_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
         * <td>0x51</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
         * <td>{@code SERIAL_SEG_DBL_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
         * <td>0x52</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
         * <td>4 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
         * <td>{@code SERIAL_SEG_DBL_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
         * <td>0x53</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
         * <td>6 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
         * <td>{@code SERIAL_SEG_CLOSE}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
         * <td>0x60</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
         * <td>A {@link #closePath closePath} path segment.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * <td>{@code SERIAL_PATH_END}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         * <td>0x61</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
         * <td>There are no more path segments following.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
         * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
            super.writeObject(s, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
         * {@code ObjectInputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
         * The serial data for this object is described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
         * writeObject method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
            super.readObject(s, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
        static class CopyIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            float floatCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
            CopyIterator(Path2D.Float p2df) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
                super(p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
                this.floatCoords = p2df.floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
                    System.arraycopy(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
                                     coords, 0, numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                    for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
                        coords[i] = floatCoords[pointIdx + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        static class TxIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
            float floatCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
            AffineTransform affine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
            TxIterator(Path2D.Float p2df, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
                super(p2df);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
                this.floatCoords = p2df.floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
                this.affine = at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
                    affine.transform(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                    affine.transform(floatCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
                return type;
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
     * The {@code Double} class defines a geometric path with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * coordinates stored in double precision floating point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
    public static class Double extends Path2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        transient double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
         * with a default winding rule of {@link #WIND_NON_ZERO}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
        public Double() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
            this(WIND_NON_ZERO, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
         * with the specified winding rule to control operations that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
         * require the interior of the path to be defined.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
        public Double(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
            this(rule, INIT_SIZE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
         * Constructs a new empty double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
         * with the specified winding rule and the specified initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
         * capacity to store path segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
         * This number is an initial guess as to how many path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
         * are in the path, but the storage is expanded as needed to store
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         * whatever path segments are added to this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
         * @param rule the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
         * @param initialCapacity the estimate for the number of path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
         *                        in the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
         * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
         * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        public Double(int rule, int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
            super(rule, initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            doubleCoords = new double[initialCapacity * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
         * Constructs a new double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
         * from an arbitrary {@link Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
         * taken from the specified {@code Shape} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        public Double(Shape s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
            this(s, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
         * Constructs a new double precision {@code Path2D} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         * from an arbitrary {@link Shape} object, transformed by an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
         * {@link AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
         * All of the initial geometry and the winding rule for this path are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
         * taken from the specified {@code Shape} object and transformed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
         * by the specified {@code AffineTransform} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
         * @param s the specified {@code Shape} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         * @param at the specified {@code AffineTransform} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        public Double(Shape s, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            if (s instanceof Path2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
                Path2D p2d = (Path2D) s;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
                setWindingRule(p2d.windingRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                this.numTypes = p2d.numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                this.pointTypes = Arrays.copyOf(p2d.pointTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
                                                p2d.pointTypes.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                this.numCoords = p2d.numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                this.doubleCoords = p2d.cloneCoordsDouble(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                PathIterator pi = s.getPathIterator(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                setWindingRule(pi.getWindingRule());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
                this.pointTypes = new byte[INIT_SIZE];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                this.doubleCoords = new double[INIT_SIZE * 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                append(pi, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        float[] cloneCoordsFloat(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            float ret[] = new float[doubleCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
                for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
                    ret[i] = (float) doubleCoords[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
                at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        double[] cloneCoordsDouble(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            double ret[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
                ret = Arrays.copyOf(this.doubleCoords,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                                    this.doubleCoords.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
                ret = new double[doubleCoords.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                at.transform(doubleCoords, 0, ret, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            return ret;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
        void append(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        void append(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
        Point2D getPoint(int coordindex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
            return new Point2D.Double(doubleCoords[coordindex],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
                                      doubleCoords[coordindex+1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        void needRoom(boolean needMove, int newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
            if (needMove && numTypes == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
                throw new IllegalPathStateException("missing initial moveto "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                                                    "in path definition");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
            int size = pointTypes.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
            if (numTypes >= size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                if (grow > EXPAND_MAX) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                    grow = EXPAND_MAX;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
                pointTypes = Arrays.copyOf(pointTypes, size+grow);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
            size = doubleCoords.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            if (numCoords + newCoords > size) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                int grow = size;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                if (grow > EXPAND_MAX * 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                    grow = EXPAND_MAX * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                if (grow < newCoords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
                    grow = newCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                doubleCoords = Arrays.copyOf(doubleCoords, size+grow);
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
        public final synchronized void moveTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
            if (numTypes > 0 && pointTypes[numTypes - 1] == SEG_MOVETO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
                doubleCoords[numCoords-2] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
                doubleCoords[numCoords-1] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                needRoom(false, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                pointTypes[numTypes++] = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
                doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                doubleCoords[numCoords++] = y;
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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        public final synchronized void lineTo(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
            needRoom(true, 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
            pointTypes[numTypes++] = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            doubleCoords[numCoords++] = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            doubleCoords[numCoords++] = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
        public final synchronized void quadTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                                              double x2, double y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
            needRoom(true, 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            pointTypes[numTypes++] = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
            doubleCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            doubleCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
            doubleCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
            doubleCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        public final synchronized void curveTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
                                               double x2, double y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                                               double x3, double y3)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            needRoom(true, 6);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
            pointTypes[numTypes++] = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            doubleCoords[numCoords++] = x1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
            doubleCoords[numCoords++] = y1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
            doubleCoords[numCoords++] = x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            doubleCoords[numCoords++] = y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
            doubleCoords[numCoords++] = x3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            doubleCoords[numCoords++] = y3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        int pointCrossings(double px, double py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            double movx, movy, curx, cury, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
            double coords[] = doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            for (int i = 1; i < numTypes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
                        Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
                                                    endy = coords[ci++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
                        Curve.pointCrossingsForQuad(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                                                    curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
            case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
                    crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
                        Curve.pointCrossingsForCubic(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
                                                     curx, cury,
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
                                                     coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
                                                     endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
                                                     endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                                                     0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
                    if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
                        crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
                            Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
                                                        curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
                                                        movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
            if (cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
                crossings +=
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
                    Curve.pointCrossingsForLine(px, py,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
                                                curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                                                movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        int rectCrossings(double rxmin, double rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                          double rxmax, double rymax)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            double coords[] = doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            double curx, cury, movx, movy, endx, endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            curx = movx = coords[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            cury = movy = coords[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
            int crossings = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            int ci = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
            for (int i = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
                 crossings != Curve.RECT_INTERSECTS && i < numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
                 i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
                case PathIterator.SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
                    movx = curx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                    movy = cury = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                case PathIterator.SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                    endx = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
                    endy = coords[ci++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                        Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
                                                   endx, endy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
                case PathIterator.SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
                        Curve.rectCrossingsForQuad(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                                                   rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                                                   rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                                                   curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                                                   coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
                                                   endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                                                   endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                                                   0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
                case PathIterator.SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
                    crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
                        Curve.rectCrossingsForCubic(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
                                                    rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
                                                    rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
                                                    curx, cury,
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
                                                    coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
                                                    endx = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
                                                    endy = coords[ci++],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
                                                    0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                    curx = endx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    cury = endy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
                case PathIterator.SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                    if (curx != movx || cury != movy) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
                        crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
                            Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
                                                       rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
                                                       rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
                                                       curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
                                                       movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                    curx = movx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
                    cury = movy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
                    // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
            if (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
                (curx != movx || cury != movy))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
                crossings =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
                    Curve.rectCrossingsForLine(crossings,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
                                               rxmin, rymin,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
                                               rxmax, rymax,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
                                               curx, cury,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
                                               movx, movy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
            // Count should always be a multiple of 2 here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
            // assert((crossings & 1) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
            return crossings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        public final void append(PathIterator pi, boolean connect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            double coords[] = new double[6];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
            while (!pi.isDone()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
                switch (pi.currentSegment(coords)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
                case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
                    if (!connect || numTypes < 1 || numCoords < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
                        moveTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
                    if (pointTypes[numTypes - 1] != SEG_CLOSE &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
                        doubleCoords[numCoords-2] == coords[0] &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
                        doubleCoords[numCoords-1] == coords[1])
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
                    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
                        // Collapse out initial moveto/lineto
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
                    }
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9469
diff changeset
  1396
                    lineTo(coords[0], coords[1]);
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9469
diff changeset
  1397
                    break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
                    lineTo(coords[0], coords[1]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
                    quadTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
                           coords[2], coords[3]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                    curveTo(coords[0], coords[1],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
                            coords[2], coords[3],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
                            coords[4], coords[5]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
                    closePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
                pi.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
                connect = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
        public final void transform(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
            at.transform(doubleCoords, 0, doubleCoords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
        public final synchronized Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            double x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
            int i = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
            if (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
                y1 = y2 = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
                x1 = x2 = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
                while (i > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
                    double y = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                    double x = doubleCoords[--i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
                    if (x < x1) x1 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
                    if (y < y1) y1 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
                    if (x > x2) x2 = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
                    if (y > y2) y2 = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
                x1 = y1 = x2 = y2 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
            return new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
         * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
         * which means that the {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
         * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
         * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
         * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
         * @param at an {@code AffineTransform}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
         * @return a new {@code PathIterator} that iterates along the boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
         *         of this {@code Shape} and provides access to the geometry
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
         *         of this {@code Shape}'s outline
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
         */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  1466
        public final PathIterator getPathIterator(AffineTransform at) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
            if (at == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                return new CopyIterator(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                return new TxIterator(this, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
         * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
         * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
         * @exception  OutOfMemoryError    if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
         * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
         * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
        public final Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
            // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
            // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
            // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
            // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
            // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1488
            return new Path2D.Double(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        private static final long serialVersionUID = 1826762518450014216L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1498
         * {@code ObjectOutputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1499
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
         * <a name="Path2DSerialData"><!-- --></a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
         * a byte indicating the storage type of the original object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
         * as a hint (SERIAL_STORAGE_DBL_ARRAY)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
         * an integer indicating the number of path segments to follow (NP)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
         * or -1 to indicate an unknown number of path segments follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
         * an integer indicating the total number of coordinates to follow (NC)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
         * or -1 to indicate an unknown number of coordinates follows
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
         * (NC should always be even since coordinates always appear in pairs
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
         *  representing an x,y pair)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
         * a byte indicating the winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
         * ({@link #WIND_EVEN_ODD WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
         *  {@link #WIND_NON_ZERO WIND_NON_ZERO})
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
         * NP (or unlimited if NP < 0) sets of values consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
         * a single byte indicating a path segment type
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1525
         * followed by one or more pairs of float or double
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
         * values representing the coordinates of the path segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
         * <li>followed by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
         * a byte indicating the end of the path (SERIAL_PATH_END).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
         * The following byte value constants are used in the serialized form
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
         * of {@code Path2D} objects:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
         * <table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
         * <th>Constant Name</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
         * <th>Byte Value</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
         * <th>Followed by</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
         * <th>Description</th>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
         * <td>{@code SERIAL_STORAGE_FLT_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
         * <td>0x30</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
         * the coordinates in a Java array of floats.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
         * <td>{@code SERIAL_STORAGE_DBL_ARRAY}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
         * <td>0x31</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
         * <td>A hint that the original {@code Path2D} object stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
         * the coordinates in a Java array of doubles.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1554
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
         * <td>{@code SERIAL_SEG_FLT_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
         * <td>0x40</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
         * <td>{@code SERIAL_SEG_FLT_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
         * <td>0x41</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
         * <td>2 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
         * <td>{@code SERIAL_SEG_FLT_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
         * <td>0x42</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
         * <td>4 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
         * <td>A {@link #quadTo quadTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
         * <td>{@code SERIAL_SEG_FLT_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
         * <td>0x43</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
         * <td>6 floats</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1577
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1578
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
         * <td>{@code SERIAL_SEG_DBL_MOVETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
         * <td>0x50</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
         * <td>A {@link #moveTo moveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
         * <td>{@code SERIAL_SEG_DBL_LINETO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
         * <td>0x51</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
         * <td>2 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
         * <td>A {@link #lineTo lineTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
         * <td>{@code SERIAL_SEG_DBL_QUADTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
         * <td>0x52</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
         * <td>4 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1595
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1596
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1597
         * <td>{@code SERIAL_SEG_DBL_CUBICTO}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1598
         * <td>0x53</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1599
         * <td>6 doubles</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
         * <td>A {@link #curveTo curveTo} path segment follows.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
         * <td>{@code SERIAL_SEG_CLOSE}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
         * <td>0x60</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
         * <td>A {@link #closePath closePath} path segment.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
         * </tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
         * <tr>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
         * <td>{@code SERIAL_PATH_END}</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
         * <td>0x61</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
         * <td></td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
         * <td>There are no more path segments following.</td>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
         * </table>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1618
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1619
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1620
            super.writeObject(s, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1621
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1622
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1625
         * {@code ObjectInputStream} followed by an explicit
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1626
         * serialization of the path segments stored in this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
         * path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
         * There are no default serializable fields as of 1.6.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
         * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
         * The serial data for this object is described in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
         * writeObject method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
         * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
            super.readObject(s, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1642
        static class CopyIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
            double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
            CopyIterator(Path2D.Double p2dd) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
                super(p2dd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
                this.doubleCoords = p2dd.doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1649
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                    for (int i = 0; i < numCoords; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
                        coords[i] = (float) doubleCoords[pointIdx + i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
                    System.arraycopy(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
                                     coords, 0, numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1672
        static class TxIterator extends Path2D.Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1673
            double doubleCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1674
            AffineTransform affine;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1675
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1676
            TxIterator(Path2D.Double p2dd, AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1677
                super(p2dd);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
                this.doubleCoords = p2dd.doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
                this.affine = at;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
            public int currentSegment(float[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                    affine.transform(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1687
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
                return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
            public int currentSegment(double[] coords) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
                int type = path.pointTypes[typeIdx];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
                int numCoords = curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
                if (numCoords > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
                    affine.transform(doubleCoords, pointIdx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
                                     coords, 0, numCoords / 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
                return type;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * Adds a point to the path by moving to the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * coordinates specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
    public abstract void moveTo(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * Adds a point to the path by drawing a straight line from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * current coordinates to the new specified coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1719
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
    public abstract void lineTo(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1726
     * Adds a curved segment, defined by two new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * drawing a Quadratic curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * coordinates and the specified coordinates {@code (x2,y2)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1729
     * using the specified point {@code (x1,y1)} as a quadratic
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * parametric control point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * All coordinates are specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @param x1 the X coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * @param y1 the Y coordinate of the quadratic control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     * @param x2 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     * @param y2 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    public abstract void quadTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1740
                                double x2, double y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
     * Adds a curved segment, defined by three new points, to the path by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1744
     * drawing a B&eacute;zier curve that intersects both the current
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1745
     * coordinates and the specified coordinates {@code (x3,y3)},
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1746
     * using the specified points {@code (x1,y1)} and {@code (x2,y2)} as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1747
     * B&eacute;zier control points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
     * All coordinates are specified in double precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
     * @param x1 the X coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
     * @param y1 the Y coordinate of the first B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
     * @param x2 the X coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
     * @param y2 the Y coordinate of the second B&eacute;zier control point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * @param x3 the X coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * @param y3 the Y coordinate of the final end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
    public abstract void curveTo(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
                                 double x2, double y2,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
                                 double x3, double y3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * Closes the current subpath by drawing a straight line back to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * the coordinates of the last {@code moveTo}.  If the path is already
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * closed then this method has no effect.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
    public final synchronized void closePath() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
        if (numTypes == 0 || pointTypes[numTypes - 1] != SEG_CLOSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
            needRoom(true, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
            pointTypes[numTypes++] = SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1774
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
     * Appends the geometry of the specified {@code Shape} object to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1778
     * path, possibly connecting the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
     * segments with a line segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1780
     * If the {@code connect} parameter is {@code true} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1781
     * path is not empty then any initial {@code moveTo} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
     * geometry of the appended {@code Shape}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1783
     * is turned into a {@code lineTo} segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1784
     * If the destination coordinates of such a connecting {@code lineTo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
     * segment match the ending coordinates of a currently open
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
     * subpath then the segment is omitted as superfluous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1787
     * The winding rule of the specified {@code Shape} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1788
     * and the appended geometry is governed by the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1789
     * rule specified for this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
     * @param s the {@code Shape} whose geometry is appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
     *          to this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
     * @param connect a boolean to control whether or not to turn an initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     *                {@code moveTo} segment into a {@code lineTo} segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     *                to connect the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
    public final void append(Shape s, boolean connect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
        append(s.getPathIterator(null), connect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     * Appends the geometry of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
     * {@link PathIterator} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1805
     * to the path, possibly connecting the new geometry to the existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
     * path segments with a line segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
     * If the {@code connect} parameter is {@code true} and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
     * path is not empty then any initial {@code moveTo} in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1809
     * geometry of the appended {@code Shape} is turned into a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
     * {@code lineTo} segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
     * If the destination coordinates of such a connecting {@code lineTo}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
     * segment match the ending coordinates of a currently open
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
     * subpath then the segment is omitted as superfluous.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
     * The winding rule of the specified {@code Shape} is ignored
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * and the appended geometry is governed by the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * rule specified for this path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * @param pi the {@code PathIterator} whose geometry is appended to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     *           this path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * @param connect a boolean to control whether or not to turn an initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     *                {@code moveTo} segment into a {@code lineTo} segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     *                to connect the new geometry to the existing path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
    public abstract void append(PathIterator pi, boolean connect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * Returns the fill style winding rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * @return an integer representing the current winding rule.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * @see #WIND_EVEN_ODD
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * @see #WIND_NON_ZERO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * @see #setWindingRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
    public final synchronized int getWindingRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
        return windingRule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     * Sets the winding rule for this path to the specified value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @param rule an integer representing the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     *             winding rule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
     * @exception IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1846
     *          {@code rule} is not either
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
     *          {@link #WIND_EVEN_ODD} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1848
     *          {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
     * @see #getWindingRule
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
    public final void setWindingRule(int rule) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
        if (rule != WIND_EVEN_ODD && rule != WIND_NON_ZERO) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
            throw new IllegalArgumentException("winding rule must be "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1855
                                               "WIND_EVEN_ODD or "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
                                               "WIND_NON_ZERO");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
        windingRule = rule;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
     * Returns the coordinates most recently added to the end of the path
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
     * as a {@link Point2D} object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
     * @return a {@code Point2D} object containing the ending coordinates of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
     *         the path or {@code null} if there are no points in the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1867
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
    public final synchronized Point2D getCurrentPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        int index = numCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        if (numTypes < 1 || index < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1874
        if (pointTypes[numTypes - 1] == SEG_CLOSE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
        loop:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
            for (int i = numTypes - 2; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1879
                    break loop;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1880
                case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1881
                    index -= 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
                    index -= 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
                case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
                    index -= 6;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
                case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1893
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1894
        return getPoint(index - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
     * Resets the path to empty.  The append position is set back to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
     * beginning of the path and all coordinates and point types are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
     * forgotten.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1903
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1904
    public final synchronized void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
        numTypes = numCoords = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
     * Transforms the geometry of this path using the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
     * {@link AffineTransform}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
     * The geometry is transformed in place, which permanently changes the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1912
     * boundary defined by this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
     * @param at the {@code AffineTransform} used to transform the area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
    public abstract void transform(AffineTransform at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
     * Returns a new {@code Shape} representing a transformed version
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
     * of this {@code Path2D}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
     * Note that the exact type and coordinate precision of the return
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
     * value is not specified for this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
     * The method will return a Shape that contains no less precision
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
     * for the transformed geometry than this {@code Path2D} currently
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
     * maintains, but it may contain no more precision either.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1927
     * If the tradeoff of precision vs. storage size in the result is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1928
     * important then the convenience constructors in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1929
     * {@link Path2D.Float#Path2D.Float(Shape, AffineTransform) Path2D.Float}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
     * and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1931
     * {@link Path2D.Double#Path2D.Double(Shape, AffineTransform) Path2D.Double}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
     * subclasses should be used to make the choice explicit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1933
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
     * @param at the {@code AffineTransform} used to transform a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
     *           new {@code Shape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
     * @return a new {@code Shape}, transformed with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
     *         {@code AffineTransform}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
    public final synchronized Shape createTransformedShape(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
        Path2D p2d = (Path2D) clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
        if (at != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
            p2d.transform(at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
        return p2d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1952
    public final Rectangle getBounds() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1953
        return getBounds2D().getBounds();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
     * Tests if the specified coordinates are inside the closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
     * boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
     * {@link Shape#contains(double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
     * @return {@code true} if the specified coordinates are inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
     *         specified {@code PathIterator}; {@code false} otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    public static boolean contains(PathIterator pi, double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        if (x * 0.0 + y * 0.0 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1973
            /* N * 0.0 is 0.0 only if N is finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
             * Here we know that both x and y are finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
            int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1977
            int cross = Curve.pointCrossingsForPath(pi, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            return ((cross & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
            /* Either x or y was infinite or NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
             * A NaN always produces a negative response to any test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
             * and Infinity values cannot be "inside" any path so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1983
             * they should return false as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1985
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1986
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1987
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1990
     * Tests if the specified {@link Point2D} is inside the closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
     * boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
     * {@link Shape#contains(Point2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1998
     * @param p the specified {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
     * @return {@code true} if the specified coordinates are inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
     *         specified {@code PathIterator}; {@code false} otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
    public static boolean contains(PathIterator pi, Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2004
        return contains(pi, p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2005
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
    public final boolean contains(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        if (x * 0.0 + y * 0.0 == 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2013
            /* N * 0.0 is 0.0 only if N is finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
             * Here we know that both x and y are finite.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
            if (numTypes < 2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2019
            int mask = (windingRule == WIND_NON_ZERO ? -1 : 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            return ((pointCrossings(x, y) & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
            /* Either x or y was infinite or NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
             * A NaN always produces a negative response to any test
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2024
             * and Infinity values cannot be "inside" any path so
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2025
             * they should return false as well.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2027
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2028
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2029
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2035
    public final boolean contains(Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2036
        return contains(p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2037
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2038
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2039
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2040
     * Tests if the specified rectangular area is entirely inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2041
     * closed boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2042
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2043
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2044
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2045
     * {@link Shape#contains(double, double, double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2046
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2047
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2048
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2049
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2050
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2051
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2052
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2053
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
     * @param w the width of the specified rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
     * @param h the height of the specified rectangular area
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
     * @return {@code true} if the specified {@code PathIterator} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
     *         the specified rectangluar area; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
    public static boolean contains(PathIterator pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
                                   double x, double y, double w, double h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
        int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
        int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
        return (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
     * Tests if the specified {@link Rectangle2D} is entirely inside the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
     * closed boundary of the specified {@link PathIterator}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
     * {@link Shape#contains(Rectangle2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
     * @param r a specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     * @return {@code true} if the specified {@code PathIterator} contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
     *         the specified {@code Rectangle2D}; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2121
    public static boolean contains(PathIterator pi, Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
        return contains(pi, r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2127
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2130
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2131
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2132
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2133
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2134
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2135
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2136
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2137
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2138
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2139
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2140
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2142
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
    public final boolean contains(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2146
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2149
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2152
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2153
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2154
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2156
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
        int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        int crossings = rectCrossings(x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
        return (crossings != Curve.RECT_INTERSECTS &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2162
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2167
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2168
     * This method object may conservatively return false in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
     * Such segments could lie entirely within the interior of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
     * path if they are part of a path with a {@link #WIND_NON_ZERO}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
     * winding rule or if the segments are retraced in the reverse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2175
     * direction such that the two sets of segments cancel each
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
     * other out without any exterior area falling between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2178
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2182
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
    public final boolean contains(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
        return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
     * Tests if the interior of the specified {@link PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
     * intersects the interior of a specified set of rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2192
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2193
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2194
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
     * {@link Shape#intersects(double, double, double, double)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2198
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2199
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2202
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
     * @param x the specified X coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
     * @param y the specified Y coordinate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
     * @param w the width of the specified rectangular coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
     * @param h the height of the specified rectangular coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
     * @return {@code true} if the specified {@code PathIterator} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
     *         the interior of the specified set of rectangular
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
     *         coordinates intersect each other; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
    public static boolean intersects(PathIterator pi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
                                     double x, double y, double w, double h)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
        int mask = (pi.getWindingRule() == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
        int crossings = Curve.rectCrossingsForPath(pi, x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
        return (crossings == Curve.RECT_INTERSECTS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
     * Tests if the interior of the specified {@link PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
     * intersects the interior of a specified {@link Rectangle2D}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
     * This method provides a basic facility for implementors of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
     * the {@link Shape} interface to implement support for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
     * {@link Shape#intersects(Rectangle2D)} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
     * @param pi the specified {@code PathIterator}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
     * @param r the specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
     * @return {@code true} if the specified {@code PathIterator} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
     *         the interior of the specified {@code Rectangle2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
     *         intersect each other; {@code false} otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
    public static boolean intersects(PathIterator pi, Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
        return intersects(pi, r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2275
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2277
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
    public final boolean intersects(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
        if (java.lang.Double.isNaN(x+w) || java.lang.Double.isNaN(y+h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            /* [xy]+[wh] is NaN if any of those values are NaN,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
             * or if adding the two together would produce NaN
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
             * by virtue of adding opposing Infinte values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2298
             * Since we need to add them below, their sum must
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2299
             * not be NaN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2300
             * We return false because NaN always produces a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
             * negative response to tests
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2304
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
        if (w <= 0 || h <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
        int mask = (windingRule == WIND_NON_ZERO ? -1 : 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
        int crossings = rectCrossings(x, y, x+w, y+h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
        return (crossings == Curve.RECT_INTERSECTS ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
                (crossings & mask) != 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
     * This method object may conservatively return true in
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
     * cases where the specified rectangular area intersects a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
     * segment of the path, but that segment does not represent a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
     * boundary between the interior and exterior of the path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     * Such a case may occur if some set of segments of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
     * path are retraced in the reverse direction such that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2323
     * two sets of segments cancel each other out without any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
     * interior area between them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2325
     * To determine whether segments represent true boundaries of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2326
     * the interior of the path would require extensive calculations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2327
     * involving all of the segments of the path and the winding
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
     * rule and are thus beyond the scope of this implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2330
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
    public final boolean intersects(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2333
        return intersects(r.getX(), r.getY(), r.getWidth(), r.getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2334
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2336
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2337
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2338
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2339
     * The iterator for this class is not multi-threaded safe,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2340
     * which means that this {@code Path2D} class does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2341
     * guarantee that modifications to the geometry of this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2342
     * {@code Path2D} object do not affect any iterations of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2343
     * that geometry that are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2345
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2346
     */
9469
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  2347
    public final PathIterator getPathIterator(AffineTransform at,
b8ea6866765a 6563734: Path2D.Float and Path2D.Double should have final getPathIterator methods
flar
parents: 5506
diff changeset
  2348
                                              double flatness)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2349
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2350
        return new FlatteningPathIterator(getPathIterator(at), flatness);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2351
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2353
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2354
     * Creates a new object of the same class as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2356
     * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2357
     * @exception  OutOfMemoryError            if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2358
     * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2359
     * @since      1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2361
    public abstract Object clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2362
        // Note: It would be nice to have this return Path2D
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2363
        // but one of our subclasses (GeneralPath) needs to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2364
        // offer "public Object clone()" for backwards
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2365
        // compatibility so we cannot restrict it further.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2366
        // REMIND: Can we do both somehow?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2367
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2368
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2369
     * Support fields and methods for serializing the subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
    private static final byte SERIAL_STORAGE_FLT_ARRAY = 0x30;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2372
    private static final byte SERIAL_STORAGE_DBL_ARRAY = 0x31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2374
    private static final byte SERIAL_SEG_FLT_MOVETO    = 0x40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
    private static final byte SERIAL_SEG_FLT_LINETO    = 0x41;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
    private static final byte SERIAL_SEG_FLT_QUADTO    = 0x42;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
    private static final byte SERIAL_SEG_FLT_CUBICTO   = 0x43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2379
    private static final byte SERIAL_SEG_DBL_MOVETO    = 0x50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
    private static final byte SERIAL_SEG_DBL_LINETO    = 0x51;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2381
    private static final byte SERIAL_SEG_DBL_QUADTO    = 0x52;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2382
    private static final byte SERIAL_SEG_DBL_CUBICTO   = 0x53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2384
    private static final byte SERIAL_SEG_CLOSE         = 0x60;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2385
    private static final byte SERIAL_PATH_END          = 0x61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
    final void writeObject(java.io.ObjectOutputStream s, boolean isdbl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2388
        throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2390
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2391
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2392
        float fCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2393
        double dCoords[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2394
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
        if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2396
            dCoords = ((Path2D.Double) this).doubleCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2397
            fCoords = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2398
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2399
            fCoords = ((Path2D.Float) this).floatCoords;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2400
            dCoords = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2402
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2403
        int numTypes = this.numTypes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2404
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2405
        s.writeByte(isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
                    ? SERIAL_STORAGE_DBL_ARRAY
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2407
                    : SERIAL_STORAGE_FLT_ARRAY);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2408
        s.writeInt(numTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2409
        s.writeInt(numCoords);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        s.writeByte((byte) windingRule);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
        int cindex = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2413
        for (int i = 0; i < numTypes; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2414
            int npoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2415
            byte serialtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2416
            switch (pointTypes[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2417
            case SEG_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2418
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2419
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2420
                              ? SERIAL_SEG_DBL_MOVETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2421
                              : SERIAL_SEG_FLT_MOVETO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2422
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2423
            case SEG_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2424
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2425
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
                              ? SERIAL_SEG_DBL_LINETO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
                              : SERIAL_SEG_FLT_LINETO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2429
            case SEG_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2430
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
                              ? SERIAL_SEG_DBL_QUADTO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
                              : SERIAL_SEG_FLT_QUADTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            case SEG_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
                serialtype = (isdbl
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2438
                              ? SERIAL_SEG_DBL_CUBICTO
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
                              : SERIAL_SEG_FLT_CUBICTO);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2440
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2441
            case SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2442
                npoints = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
                serialtype = SERIAL_SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2445
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2446
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2447
                // Should never happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
                throw new InternalError("unrecognized path type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            s.writeByte(serialtype);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
            while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
                if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
                    s.writeDouble(dCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
                    s.writeDouble(dCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
                    s.writeFloat(fCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
                    s.writeFloat(fCoords[cindex++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2460
        }
11080
7e18e343964e 7117914: Fix javac warnings in src/share/classes/sun/java2d
neugens
parents: 9469
diff changeset
  2461
        s.writeByte(SERIAL_PATH_END);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
    final void readObject(java.io.ObjectInputStream s, boolean storedbl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
        throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
        // The subclass calls this method with the storage type that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        // they want us to use (storedbl) so we ignore the storage
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        // method hint from the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
        s.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        int nT = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        int nC = s.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            setWindingRule(s.readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
        } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
            throw new java.io.InvalidObjectException(iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
        pointTypes = new byte[(nT < 0) ? INIT_SIZE : nT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
        if (nC < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
            nC = INIT_SIZE * 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        if (storedbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
            ((Path2D.Double) this).doubleCoords = new double[nC];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            ((Path2D.Float) this).floatCoords = new float[nC];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
    PATHDONE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
        for (int i = 0; nT < 0 || i < nT; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
            boolean isdbl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
            int npoints;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
            byte segtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
            byte serialtype = s.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
            switch (serialtype) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
            case SERIAL_SEG_FLT_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
                segtype = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
            case SERIAL_SEG_FLT_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
                segtype = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
            case SERIAL_SEG_FLT_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
                segtype = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
            case SERIAL_SEG_FLT_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
                segtype = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
            case SERIAL_SEG_DBL_MOVETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
                segtype = SEG_MOVETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
            case SERIAL_SEG_DBL_LINETO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
                npoints = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
                segtype = SEG_LINETO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
            case SERIAL_SEG_DBL_QUADTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
                npoints = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
                segtype = SEG_QUADTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
            case SERIAL_SEG_DBL_CUBICTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
                isdbl = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
                npoints = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
                segtype = SEG_CUBICTO;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
            case SERIAL_SEG_CLOSE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
                isdbl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
                npoints = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
                segtype = SEG_CLOSE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2546
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2547
            case SERIAL_PATH_END:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2548
                if (nT < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2549
                    break PATHDONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2550
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2551
                throw new StreamCorruptedException("unexpected PATH_END");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
                throw new StreamCorruptedException("unrecognized path type");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2556
            needRoom(segtype != SEG_MOVETO, npoints * 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2557
            if (isdbl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2558
                while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2559
                    append(s.readDouble(), s.readDouble());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2560
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
                while (--npoints >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
                    append(s.readFloat(), s.readFloat());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
            pointTypes[numTypes++] = segtype;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
        if (nT >= 0 && s.readByte() != SERIAL_PATH_END) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
            throw new StreamCorruptedException("missing PATH_END");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
    static abstract class Iterator implements PathIterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
        int typeIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
        int pointIdx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
        Path2D path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
        static final int curvecoords[] = {2, 2, 4, 6, 0};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
        Iterator(Path2D path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
            this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
        public int getWindingRule() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
            return path.getWindingRule();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
        public boolean isDone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
            return (typeIdx >= path.numTypes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
        public void next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
            int type = path.pointTypes[typeIdx++];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
            pointIdx += curvecoords[type];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
}