jdk/src/java.desktop/share/classes/java/awt/geom/Arc2D.java
author prr
Sat, 19 Sep 2015 15:45:59 -0700
changeset 32865 f9cb6e427f9e
parent 25859 3317bb8137f4
child 35667 ed476aba94de
permissions -rw-r--r--
8136783: Run blessed-modifier-order script on java.desktop Reviewed-by: martin, serb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
25770
d132697706ea 8037511: Tidy warnings cleanup for java.awt - 2d part
avstepan
parents: 23010
diff changeset
     2
 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * <CODE>Arc2D</CODE> is the abstract superclass for all objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * store a 2D arc defined by a framing rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * start angle, angular extent (length of the arc), and a closure type
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * (<CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or <CODE>PIE</CODE>).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <a name="inscribes">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The arc is a partial section of a full ellipse which
25770
d132697706ea 8037511: Tidy warnings cleanup for java.awt - 2d part
avstepan
parents: 23010
diff changeset
    38
 * inscribes the framing rectangle of its parent</a> {@link RectangularShape}.
d132697706ea 8037511: Tidy warnings cleanup for java.awt - 2d part
avstepan
parents: 23010
diff changeset
    39
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <a name="angles">
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The angles are specified relative to the non-square
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * framing rectangle such that 45 degrees always falls on the line from
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the center of the ellipse to the upper right corner of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * As a result, if the framing rectangle is noticeably longer along one
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * axis than the other, the angles to the start and end of the arc segment
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * will be skewed farther along the longer axis of the frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * The actual storage representation of the coordinates is left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * the subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public abstract class Arc2D extends RectangularShape {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * The closure type for an open arc with no path segments
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * connecting the two ends of the arc segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    63
    public static final int OPEN = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * The closure type for an arc closed by drawing a straight
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * line segment from the start of the arc segment to the end of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * arc segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    71
    public static final int CHORD = 1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * The closure type for an arc closed by drawing straight line
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * segments from the start of the arc segment to the center
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * of the full ellipse and from that point to the end of the arc segment.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     */
32865
f9cb6e427f9e 8136783: Run blessed-modifier-order script on java.desktop
prr
parents: 25859
diff changeset
    79
    public static final int PIE = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * This class defines an arc specified in {@code float} precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static class Float extends Arc2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
         * The X coordinate of the upper-left corner of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * rectangle of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        public float x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * The Y coordinate of the upper-left corner of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * rectangle of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        public float y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * The overall width of the full ellipse of which this arc is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * a partial section (not considering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * angular extents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        public float width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
         * The overall height of the full ellipse of which this arc is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * a partial section (not considering the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * angular extents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        public float height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
         * The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        public float start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        public float extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * Constructs a new OPEN arc, initialized to location (0, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * size (0, 0), angular extents (start = 0, extent = 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        public Float() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            super(OPEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * Constructs a new arc, initialized to location (0, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * size (0, 0), angular extents (start = 0, extent = 0), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         * the specified closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        public Float(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * Constructs a new arc, initialized to the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * size, angular extents, and closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * @param x The X coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         *          the arc's framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * @param y The Y coordinate of the upper-left corner of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         *          the arc's framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * @param w The overall width of the full ellipse of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         *          this arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         * @param h The overall height of the full ellipse of which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
         *          arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
         * @param start The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
         * @param extent The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public Float(float x, float y, float w, float h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                     float start, float extent, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            this.width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            this.height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            this.extent = extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * Constructs a new arc, initialized to the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         * size, angular extents, and closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * @param ellipseBounds The framing rectangle that defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * outer boundary of the full ellipse of which this arc is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         * @param start The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * @param extent The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        public Float(Rectangle2D ellipseBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                     float start, float extent, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            this.x = (float) ellipseBounds.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            this.y = (float) ellipseBounds.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            this.width = (float) ellipseBounds.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            this.height = (float) ellipseBounds.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            this.extent = extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        public double getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            return (double) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        public double getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return (double) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        public double getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            return (double) width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        public double getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return (double) height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        public double getAngleStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return (double) start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        public double getAngleExtent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return (double) extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            return (width <= 0.0 || height <= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        public void setArc(double x, double y, double w, double h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                           double angSt, double angExt, int closure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            this.setArcType(closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            this.x = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            this.y = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            this.width = (float) w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            this.height = (float) h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            this.start = (float) angSt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            this.extent = (float) angExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        public void setAngleStart(double angSt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            this.start = (float) angSt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        public void setAngleExtent(double angExt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
            this.extent = (float) angExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        protected Rectangle2D makeBounds(double x, double y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                                         double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            return new Rectangle2D.Float((float) x, (float) y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                         (float) w, (float) h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        private static final long serialVersionUID = 9130893014586380278L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
         * <code>ObjectOutputStream</code> followed by a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
         * indicating the arc type of this <code>Arc2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
         * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
         * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
         * followed by a <code>byte</code> indicating the arc type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            s.writeByte(getArcType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * <code>ObjectInputStream</code> followed by a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         * indicating the arc type of this <code>Arc2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
         * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
         * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
         * followed by a <code>byte</code> indicating the arc type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                setArcType(s.readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                throw new java.io.InvalidObjectException(iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * This class defines an arc specified in {@code double} precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public static class Double extends Arc2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
         * The X coordinate of the upper-left corner of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
         * rectangle of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        public double x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
         * The Y coordinate of the upper-left corner of the framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
         * rectangle of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
        public double y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
         * The overall width of the full ellipse of which this arc is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
         * a partial section (not considering the angular extents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        public double width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
         * The overall height of the full ellipse of which this arc is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
         * a partial section (not considering the angular extents).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        public double height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
         * The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
        public double start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
         * The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        public double extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
         * Constructs a new OPEN arc, initialized to location (0, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
         * size (0, 0), angular extents (start = 0, extent = 0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        public Double() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            super(OPEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
         * Constructs a new arc, initialized to location (0, 0),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
         * size (0, 0), angular extents (start = 0, extent = 0), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
         * the specified closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        public Double(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
         * Constructs a new arc, initialized to the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
         * size, angular extents, and closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
         * @param x The X coordinate of the upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
         *          of the arc's framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
         * @param y The Y coordinate of the upper-left corner
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
         *          of the arc's framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
         * @param w The overall width of the full ellipse of which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
         *          arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
         * @param h The overall height of the full ellipse of which this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
         *          arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
         * @param start The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
         * @param extent The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        public Double(double x, double y, double w, double h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
                      double start, double extent, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            this.width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            this.height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            this.extent = extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
         * Constructs a new arc, initialized to the specified location,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
         * size, angular extents, and closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
         * @param ellipseBounds The framing rectangle that defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
         * outer boundary of the full ellipse of which this arc is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
         * partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
         * @param start The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
         * @param extent The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
         * @param type The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        public Double(Rectangle2D ellipseBounds,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                      double start, double extent, int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            super(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            this.x = ellipseBounds.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            this.y = ellipseBounds.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            this.width = ellipseBounds.getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            this.height = ellipseBounds.getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            this.start = start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            this.extent = extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        public double getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        public double getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        public double getWidth() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
            return width;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
         * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
         * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
         * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
        public double getHeight() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            return height;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        public double getAngleStart() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
            return start;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        public double getAngleExtent() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            return extent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        public boolean isEmpty() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            return (width <= 0.0 || height <= 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
        public void setArc(double x, double y, double w, double h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
                           double angSt, double angExt, int closure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            this.setArcType(closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            this.width = w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            this.height = h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            this.start = angSt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            this.extent = angExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        public void setAngleStart(double angSt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            this.start = angSt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        public void setAngleExtent(double angExt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
            this.extent = angExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        protected Rectangle2D makeBounds(double x, double y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                                         double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            return new Rectangle2D.Double(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        private static final long serialVersionUID = 728264085846882001L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
         * Writes the default serializable fields to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
         * <code>ObjectOutputStream</code> followed by a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
         * indicating the arc type of this <code>Arc2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
         * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
         * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
         * followed by a <code>byte</code> indicating the arc type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
        private void writeObject(java.io.ObjectOutputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
            throws java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
            s.writeByte(getArcType());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
         * Reads the default serializable fields from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
         * <code>ObjectInputStream</code> followed by a byte
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
         * indicating the arc type of this <code>Arc2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
         * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
         * @serialData
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
         * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
         * <li>The default serializable fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
         * <li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
         * followed by a <code>byte</code> indicating the arc type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
         * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
         * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        private void readObject(java.io.ObjectInputStream s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            throws java.lang.ClassNotFoundException, java.io.IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
            s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                setArcType(s.readByte());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            } catch (IllegalArgumentException iae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                throw new java.io.InvalidObjectException(iae.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    private int type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * Type-specific implementation subclasses are available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * instantiation and provide a number of formats for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * the information necessary to satisfy the various accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * methods below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * This constructor creates an object with a default closure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * type of {@link #OPEN}.  It is provided only to enable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * serialization of subclasses.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @see java.awt.geom.Arc2D.Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * @see java.awt.geom.Arc2D.Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     */
9465
d336b679b605 6522514: Extending Arc2D.Double and serializing the object causes InvalidClassException
flar
parents: 5506
diff changeset
   684
    protected Arc2D() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
        this(OPEN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * Type-specific implementation subclasses are available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * instantiation and provide a number of formats for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * the information necessary to satisfy the various accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * methods below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @param type The closure type of this arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @see java.awt.geom.Arc2D.Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @see java.awt.geom.Arc2D.Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    protected Arc2D(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        setArcType(type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Returns the starting angle of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * @return A double value that represents the starting angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * @see #setAngleStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    public abstract double getAngleStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * Returns the angular extent of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
     * @return A double value that represents the angular extent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * @see #setAngleExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
    public abstract double getAngleExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Returns the arc closure type of the arc: {@link #OPEN},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     * @return One of the integer constant closure types defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * in this class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     * @see #setArcType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    public int getArcType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        return type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
     * Returns the starting point of the arc.  This point is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * intersection of the ray from the center defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * starting angle and the elliptical boundary of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
     * @return A <CODE>Point2D</CODE> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * x,y coordinates of the starting point of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
    public Point2D getStartPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
        double angle = Math.toRadians(-getAngleStart());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
        return new Point2D.Double(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
     * Returns the ending point of the arc.  This point is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
     * intersection of the ray from the center defined by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
     * starting angle plus the angular extent of the arc and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * elliptical boundary of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
     * @return A <CODE>Point2D</CODE> object representing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
     * x,y coordinates  of the ending point of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    public Point2D getEndPoint() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
        double angle = Math.toRadians(-getAngleStart() - getAngleExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
        double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        return new Point2D.Double(x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
     * Sets the location, size, angular extents, and closure type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
     * this arc to the specified double values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
     * @param x The X coordinate of the upper-left corner of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * @param y The Y coordinate of the upper-left corner of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * @param w The overall width of the full ellipse of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     *          this arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * @param h The overall height of the full ellipse of which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     *          this arc is a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * @param angSt The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @param angExt The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @param closure The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    public abstract void setArc(double x, double y, double w, double h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
                                double angSt, double angExt, int closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Sets the location, size, angular extents, and closure type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * this arc to the specified values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * @param loc The <CODE>Point2D</CODE> representing the coordinates of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * the upper-left corner of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * @param size The <CODE>Dimension2D</CODE> representing the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * and height of the full ellipse of which this arc is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * a partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @param angSt The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     * @param angExt The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @param closure The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    public void setArc(Point2D loc, Dimension2D size,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
                       double angSt, double angExt, int closure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        setArc(loc.getX(), loc.getY(), size.getWidth(), size.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
               angSt, angExt, closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * Sets the location, size, angular extents, and closure type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * this arc to the specified values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @param rect The framing rectangle that defines the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     * outer boundary of the full ellipse of which this arc is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
     * partial section.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
     * @param angSt The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
     * @param angExt The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
     * @param closure The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    public void setArc(Rectangle2D rect, double angSt, double angExt,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
                       int closure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
        setArc(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
               angSt, angExt, closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     * Sets this arc to be the same as the specified arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @param a The <CODE>Arc2D</CODE> to use to set the arc's values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
    public void setArc(Arc2D a) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
        setArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
               a.getAngleStart(), a.getAngleExtent(), a.type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Sets the position, bounds, angular extents, and closure type of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * this arc to the specified values. The arc is defined by a center
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * point and a radius rather than a framing rectangle for the full ellipse.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * @param x The X coordinate of the center of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * @param y The Y coordinate of the center of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     * @param radius The radius of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param angSt The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @param angExt The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * @param closure The closure type for the arc:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public void setArcByCenter(double x, double y, double radius,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
                               double angSt, double angExt, int closure) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
        setArc(x - radius, y - radius, radius * 2.0, radius * 2.0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
               angSt, angExt, closure);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * Sets the position, bounds, and angular extents of this arc to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * specified value. The starting angle of the arc is tangent to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * line specified by points (p1, p2), the ending angle is tangent to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     * the line specified by points (p2, p3), and the arc has the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * specified radius.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @param p1 The first point that defines the arc. The starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * angle of the arc is tangent to the line specified by points (p1, p2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @param p2 The second point that defines the arc. The starting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * angle of the arc is tangent to the line specified by points (p1, p2).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * The ending angle of the arc is tangent to the line specified by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * points (p2, p3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * @param p3 The third point that defines the arc. The ending angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * of the arc is tangent to the line specified by points (p2, p3).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * @param radius The radius of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
    public void setArcByTangent(Point2D p1, Point2D p2, Point2D p3,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
                                double radius) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        double ang1 = Math.atan2(p1.getY() - p2.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
                                 p1.getX() - p2.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        double ang2 = Math.atan2(p3.getY() - p2.getY(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                                 p3.getX() - p2.getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
        double diff = ang2 - ang1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
        if (diff > Math.PI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
            ang2 -= Math.PI * 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
        } else if (diff < -Math.PI) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            ang2 += Math.PI * 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        double bisect = (ang1 + ang2) / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        double theta = Math.abs(ang2 - bisect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
        double dist = radius / Math.sin(theta);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        double x = p2.getX() + dist * Math.cos(bisect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
        double y = p2.getY() + dist * Math.sin(bisect);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
        // REMIND: This needs some work...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
        if (ang1 < ang2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
            ang1 -= Math.PI / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
            ang2 += Math.PI / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            ang1 += Math.PI / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
            ang2 -= Math.PI / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
        ang1 = Math.toDegrees(-ang1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        ang2 = Math.toDegrees(-ang2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
        diff = ang2 - ang1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
        if (diff < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
            diff += 360;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            diff -= 360;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
        setArcByCenter(x, y, radius, ang1, diff, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * Sets the starting angle of this arc to the specified double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
     * @param angSt The starting angle of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
     * @see #getAngleStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
    public abstract void setAngleStart(double angSt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * Sets the angular extent of this arc to the specified double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * @param angExt The angular extent of the arc in degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * @see #getAngleExtent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
    public abstract void setAngleExtent(double angExt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * Sets the starting angle of this arc to the angle that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * specified point defines relative to the center of this arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * The angular extent of the arc will remain the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * @param p The <CODE>Point2D</CODE> that defines the starting angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * @see #getAngleStart
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    public void setAngleStart(Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        // Bias the dx and dy by the height and width of the oval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
        double dx = getHeight() * (p.getX() - getCenterX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
        double dy = getWidth() * (p.getY() - getCenterY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        setAngleStart(-Math.toDegrees(Math.atan2(dy, dx)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     * Sets the starting angle and angular extent of this arc using two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * sets of coordinates. The first set of coordinates is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * determine the angle of the starting point relative to the arc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * center. The second set of coordinates is used to determine the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     * angle of the end point relative to the arc's center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
     * The arc will always be non-empty and extend counterclockwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
     * from the first point around to the second point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * @param x1 The X coordinate of the arc's starting point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * @param y1 The Y coordinate of the arc's starting point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * @param x2 The X coordinate of the arc's ending point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     * @param y2 The Y coordinate of the arc's ending point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
    public void setAngles(double x1, double y1, double x2, double y2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
        double x = getCenterX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        double y = getCenterY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
        double w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
        double h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
        // Note: reversing the Y equations negates the angle to adjust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
        // for the upside down coordinate system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        // Also we should bias atans by the height and width of the oval.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
        double ang1 = Math.atan2(w * (y - y1), h * (x1 - x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        double ang2 = Math.atan2(w * (y - y2), h * (x2 - x));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
        ang2 -= ang1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
        if (ang2 <= 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
            ang2 += Math.PI * 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        setAngleStart(Math.toDegrees(ang1));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        setAngleExtent(Math.toDegrees(ang2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     * Sets the starting angle and angular extent of this arc using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * two points. The first point is used to determine the angle of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * the starting point relative to the arc's center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * The second point is used to determine the angle of the end point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     * relative to the arc's center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
     * The arc will always be non-empty and extend counterclockwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
     * from the first point around to the second point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
     * @param p1 The <CODE>Point2D</CODE> that defines the arc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
     * starting point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * @param p2 The <CODE>Point2D</CODE> that defines the arc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * ending point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    public void setAngles(Point2D p1, Point2D p2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
        setAngles(p1.getX(), p1.getY(), p2.getX(), p2.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * Sets the closure type of this arc to the specified value:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * <CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or <CODE>PIE</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * @param type The integer constant that represents the closure
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * type of this arc: {@link #OPEN}, {@link #CHORD}, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * {@link #PIE}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * @throws IllegalArgumentException if <code>type</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * 0, 1, or 2.+
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @see #getArcType
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
    public void setArcType(int type) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
        if (type < OPEN || type > PIE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
            throw new IllegalArgumentException("invalid type for Arc: "+type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
     * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
     * Note that the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * <a href="Arc2D.html#inscribes">partially inscribes</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * the framing rectangle of this {@code RectangularShape}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
    public void setFrame(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
        setArc(x, y, w, h, getAngleStart(), getAngleExtent(), 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
     * Returns the high-precision framing rectangle of the arc.  The framing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * rectangle contains only the part of this <code>Arc2D</code> that is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * in between the starting and ending angles and contains the pie
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * wedge, if this <code>Arc2D</code> has a <code>PIE</code> closure type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     * This method differs from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * {@link RectangularShape#getBounds() getBounds} in that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     * <code>getBounds</code> method only returns the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * enclosing ellipse of this <code>Arc2D</code> without considering
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * the starting and ending angles of this <code>Arc2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * @return the <CODE>Rectangle2D</CODE> that represents the arc's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
    public Rectangle2D getBounds2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        if (isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            return makeBounds(getX(), getY(), getWidth(), getHeight());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
        double x1, y1, x2, y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        if (getArcType() == PIE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
            x1 = y1 = x2 = y2 = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            x1 = y1 = 1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
            x2 = y2 = -1.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
        double angle = 0.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
        for (int i = 0; i < 6; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            if (i < 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                // 0-3 are the four quadrants
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
                angle += 90.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                if (!containsAngle(angle)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            } else if (i == 4) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
                // 4 is start angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
                angle = getAngleStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
                // 5 is end angle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
                angle += getAngleExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
            double rads = Math.toRadians(-angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
            double xe = Math.cos(rads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            double ye = Math.sin(rads);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            x1 = Math.min(x1, xe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            y1 = Math.min(y1, ye);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
            x2 = Math.max(x2, xe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            y2 = Math.max(y2, ye);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
        double w = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        double h = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
        x2 = (x2 - x1) * 0.5 * w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        y2 = (y2 - y1) * 0.5 * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
        x1 = getX() + (x1 * 0.5 + 0.5) * w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        y1 = getY() + (y1 * 0.5 + 0.5) * h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        return makeBounds(x1, y1, x2, y2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * Constructs a <code>Rectangle2D</code> of the appropriate precision
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * to hold the parameters calculated to be the framing rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * of this arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
     * @param x The X coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * @param y The Y coordinate of the upper-left corner of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * @param w The width of the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * @param h The height of the framing rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     * @return a <code>Rectangle2D</code> that is the framing rectangle
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     *     of this arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
    protected abstract Rectangle2D makeBounds(double x, double y,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
                                              double w, double h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * Normalizes the specified angle into the range -180 to 180.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
    static double normalizeDegrees(double angle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        if (angle > 180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
            if (angle <= (180.0 + 360.0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
                angle = angle - 360.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
                angle = Math.IEEEremainder(angle, 360.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                // IEEEremainder can return -180 here for some input values...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
                if (angle == -180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
                    angle = 180.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        } else if (angle <= -180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
            if (angle > (-180.0 - 360.0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
                angle = angle + 360.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
                angle = Math.IEEEremainder(angle, 360.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                // IEEEremainder can return -180 here for some input values...
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
                if (angle == -180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                    angle = 180.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
        return angle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     * Determines whether or not the specified angle is within the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * angular extents of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     * @param angle The angle to test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @return <CODE>true</CODE> if the arc contains the angle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     * <CODE>false</CODE> if the arc doesn't contain the angle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    public boolean containsAngle(double angle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
        double angExt = getAngleExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        boolean backwards = (angExt < 0.0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
        if (backwards) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            angExt = -angExt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
        if (angExt >= 360.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
        angle = normalizeDegrees(angle) - normalizeDegrees(getAngleStart());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
        if (backwards) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
            angle = -angle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
        if (angle < 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
            angle += 360.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
        return (angle >= 0.0) && (angle < angExt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * Determines whether or not the specified point is inside the boundary
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     * @param x The X coordinate of the point to test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @param y The Y coordinate of the point to test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @return <CODE>true</CODE> if the point lies within the bound of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     * the arc, <CODE>false</CODE> if the point lies outside of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
     * arc's bounds.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
    public boolean contains(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
        // Normalize the coordinates compared to the ellipse
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
        // having a center at 0,0 and a radius of 0.5.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
        double ellw = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
        if (ellw <= 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
        double normx = (x - getX()) / ellw - 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
        double ellh = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
        if (ellh <= 0.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
        double normy = (y - getY()) / ellh - 0.5;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        double distSq = (normx * normx + normy * normy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
        if (distSq >= 0.25) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
        double angExt = Math.abs(getAngleExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
        if (angExt >= 360.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
        boolean inarc = containsAngle(-Math.toDegrees(Math.atan2(normy,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                                                                 normx)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
        if (type == PIE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            return inarc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
        // CHORD and OPEN behave the same way
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
        if (inarc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            if (angExt >= 180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
            // point must be outside the "pie triangle"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
            if (angExt <= 180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
            // point must be inside the "pie triangle"
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        // The point is inside the pie triangle iff it is on the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        // side of the line connecting the ends of the arc as the center.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
        double angle = Math.toRadians(-getAngleStart());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        double x1 = Math.cos(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
        double y1 = Math.sin(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        angle += Math.toRadians(-getAngleExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
        double x2 = Math.cos(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
        double y2 = Math.sin(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        boolean inside = (Line2D.relativeCCW(x1, y1, x2, y2, 2*normx, 2*normy) *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
                          Line2D.relativeCCW(x1, y1, x2, y2, 0, 0) >= 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        return inarc ? !inside : inside;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
     * Determines whether or not the interior of the arc intersects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
     * the interior of the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
     * @param x The X coordinate of the rectangle's upper-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * @param y The Y coordinate of the rectangle's upper-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
     * @param w The width of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
     * @param h The height of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     * @return <CODE>true</CODE> if the arc intersects the rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * <CODE>false</CODE> if the arc doesn't intersect the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
    public boolean intersects(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        double aw = getWidth();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        double ah = getHeight();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        if ( w <= 0 || h <= 0 || aw <= 0 || ah <= 0 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        double ext = getAngleExtent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
        if (ext == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
        double ax  = getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        double ay  = getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        double axw = ax + aw;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
        double ayh = ay + ah;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        double xw  = x + w;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
        double yh  = y + h;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        // check bbox
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        if (x >= axw || y >= ayh || xw <= ax || yh <= ay) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        // extract necessary data
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
        double axc = getCenterX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
        double ayc = getCenterY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
        Point2D sp = getStartPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        Point2D ep = getEndPoint();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
        double sx = sp.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
        double sy = sp.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
        double ex = ep.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
        double ey = ep.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
         * Try to catch rectangles that intersect arc in areas
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
         * outside of rectagle with left top corner coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
         * (min(center x, start point x, end point x),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
         *  min(center y, start point y, end point y))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
         * and rigth bottom corner coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
         * (max(center x, start point x, end point x),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
         *  max(center y, start point y, end point y)).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
         * So we'll check axis segments outside of rectangle above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        if (ayc >= y && ayc <= yh) { // 0 and 180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            if ((sx < xw && ex < xw && axc < xw &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
                 axw > x && containsAngle(0)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
                (sx > x && ex > x && axc > x &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                 ax < xw && containsAngle(180))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
        if (axc >= x && axc <= xw) { // 90 and 270
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
            if ((sy > y && ey > y && ayc > y &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
                 ay < yh && containsAngle(90)) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
                (sy < yh && ey < yh && ayc < yh &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
                 ayh > y && containsAngle(270))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
         * For PIE we should check intersection with pie slices;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
         * also we should do the same for arcs with extent is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
         * than 180, because we should cover case of rectangle, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
         * situated between center of arc and chord, but does not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
         * intersect the chord.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
        Rectangle2D rect = new Rectangle2D.Double(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
        if (type == PIE || Math.abs(ext) > 180) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
            // for PIE: try to find intersections with pie slices
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
            if (rect.intersectsLine(axc, ayc, sx, sy) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
                rect.intersectsLine(axc, ayc, ex, ey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            // for CHORD and OPEN: try to find intersections with chord
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
            if (rect.intersectsLine(sx, sy, ex, ey)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        // finally check the rectangle corners inside the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
        if (contains(x, y) || contains(x + w, y) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            contains(x, y + h) || contains(x + w, y + h)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
     * Determines whether or not the interior of the arc entirely contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
     * the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
     * @param x The X coordinate of the rectangle's upper-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
     * @param y The Y coordinate of the rectangle's upper-left corner.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
     * @param w The width of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1345
     * @param h The height of the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1347
     * @return <CODE>true</CODE> if the arc contains the rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1348
     * <CODE>false</CODE> if the arc doesn't contain the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1349
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1350
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1351
    public boolean contains(double x, double y, double w, double h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
        return contains(x, y, w, h, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1355
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
     * Determines whether or not the interior of the arc entirely contains
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1357
     * the specified rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1359
     * @param r The <CODE>Rectangle2D</CODE> to test.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1360
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1361
     * @return <CODE>true</CODE> if the arc contains the rectangle,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1362
     * <CODE>false</CODE> if the arc doesn't contain the rectangle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1363
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1364
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1365
    public boolean contains(Rectangle2D r) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1366
        return contains(r.getX(), r.getY(), r.getWidth(), r.getHeight(), r);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1368
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1369
    private boolean contains(double x, double y, double w, double h,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1370
                             Rectangle2D origrect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1371
        if (!(contains(x, y) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1372
              contains(x + w, y) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1373
              contains(x, y + h) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1374
              contains(x + w, y + h))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1375
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1376
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1377
        // If the shape is convex then we have done all the testing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1378
        // we need.  Only PIE arcs can be concave and then only if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1379
        // the angular extents are greater than 180 degrees.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1380
        if (type != PIE || Math.abs(getAngleExtent()) <= 180.0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1381
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1382
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
        // For a PIE shape we have an additional test for the case where
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
        // the angular extents are greater than 180 degrees and all four
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1385
        // rectangular corners are inside the shape but one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1386
        // rectangle edges spans across the "missing wedge" of the arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1387
        // We can test for this case by checking if the rectangle intersects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1388
        // either of the pie angle segments.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1389
        if (origrect == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1390
            origrect = new Rectangle2D.Double(x, y, w, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1391
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1392
        double halfW = getWidth() / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1393
        double halfH = getHeight() / 2.0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1394
        double xc = getX() + halfW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1395
        double yc = getY() + halfH;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1396
        double angle = Math.toRadians(-getAngleStart());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1397
        double xe = xc + halfW * Math.cos(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1398
        double ye = yc + halfH * Math.sin(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1399
        if (origrect.intersectsLine(xc, yc, xe, ye)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1400
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1402
        angle += Math.toRadians(-getAngleExtent());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1403
        xe = xc + halfW * Math.cos(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1404
        ye = yc + halfH * Math.sin(angle);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1405
        return !origrect.intersectsLine(xc, yc, xe, ye);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1407
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1409
     * Returns an iteration object that defines the boundary of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1410
     * arc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1411
     * This iterator is multithread safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1412
     * <code>Arc2D</code> guarantees that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1413
     * modifications to the geometry of the arc
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1414
     * do not affect any iterations of that geometry that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1415
     * are already in process.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
     * @param at an optional <CODE>AffineTransform</CODE> to be applied
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
     * to the coordinates as they are returned in the iteration, or null
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1419
     * if the untransformed coordinates are desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
     * @return A <CODE>PathIterator</CODE> that defines the arc's boundary.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
    public PathIterator getPathIterator(AffineTransform at) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1425
        return new ArcIterator(this, at);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1429
     * Returns the hashcode for this <code>Arc2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
     * @return the hashcode for this <code>Arc2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1431
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1433
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1434
        long bits = java.lang.Double.doubleToLongBits(getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1435
        bits += java.lang.Double.doubleToLongBits(getY()) * 37;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
        bits += java.lang.Double.doubleToLongBits(getWidth()) * 43;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
        bits += java.lang.Double.doubleToLongBits(getHeight()) * 47;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
        bits += java.lang.Double.doubleToLongBits(getAngleStart()) * 53;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
        bits += java.lang.Double.doubleToLongBits(getAngleExtent()) * 59;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1440
        bits += getArcType() * 61;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1441
        return (((int) bits) ^ ((int) (bits >> 32)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1445
     * Determines whether or not the specified <code>Object</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1446
     * equal to this <code>Arc2D</code>.  The specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1447
     * <code>Object</code> is equal to this <code>Arc2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
     * if it is an instance of <code>Arc2D</code> and if its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
     * location, size, arc extents and type are the same as this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
     * <code>Arc2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
     * @param obj  an <code>Object</code> to be compared with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
     *             <code>Arc2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1453
     * @return  <code>true</code> if <code>obj</code> is an instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1454
     *          of <code>Arc2D</code> and has the same values;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1455
     *          <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
        if (obj == this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1461
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1462
        if (obj instanceof Arc2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            Arc2D a2d = (Arc2D) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
            return ((getX() == a2d.getX()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1465
                    (getY() == a2d.getY()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1466
                    (getWidth() == a2d.getWidth()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1467
                    (getHeight() == a2d.getHeight()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
                    (getAngleStart() == a2d.getAngleStart()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                    (getAngleExtent() == a2d.getAngleExtent()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
                    (getArcType() == a2d.getArcType()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1472
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1474
}