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