001/*
002 * @(#)Arc2D.java       1.31 06/02/24
003 *
004 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
005 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
006 */
007package armyc2.c2sd.graphics2d;
008
009/**
010 * <CODE>Arc2D</CODE> is the abstract superclass for all objects that store a 2D
011 * arc defined by a framing rectangle, start angle, angular extent (length of
012 * the arc), and a closure type (<CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or
013 * <CODE>PIE</CODE>).
014 * <p>
015 * <a name="inscribes">
016 * The arc is a partial section of a full ellipse which inscribes the framing
017 * rectangle of its parent {@link RectangularShape}.
018 * </a>
019 * <a name="angles">
020 * The angles are specified relative to the non-square framing rectangle such
021 * that 45 degrees always falls on the line from the center of the ellipse to
022 * the upper right corner of the framing rectangle. As a result, if the framing
023 * rectangle is noticeably longer along one axis than the other, the angles to
024 * the start and end of the arc segment will be skewed farther along the longer
025 * axis of the frame.
026 * </a>
027 * <p>
028 * The actual storage representation of the coordinates is left to the subclass.
029 *
030 * @version 10 Feb 1997
031 * @author      Jim Graham
032 * @since 1.2
033 */
034public /* abstract */ class Arc2D /*extends RectangularShape*/ {
035
036    /**
037     * The closure type for an open arc with no path segments connecting the two
038     * ends of the arc segment.
039     *
040     * @since 1.2
041     */
042    public final static int OPEN = 0;
043
044    /**
045     * The closure type for an arc closed by drawing a straight line segment
046     * from the start of the arc segment to the end of the arc segment.
047     *
048     * @since 1.2
049     */
050    public final static int CHORD = 1;
051
052    /**
053     * The closure type for an arc closed by drawing straight line segments from
054     * the start of the arc segment to the center of the full ellipse and from
055     * that point to the end of the arc segment.
056     *
057     * @since 1.2
058     */
059    public final static int PIE = 2;
060
061    /**
062     * The X coordinate of the upper-left corner of the framing rectangle of the
063     * arc.
064     *
065     * @since 1.2
066     * @serial
067     */
068    public double x;
069
070    /**
071     * The Y coordinate of the upper-left corner of the framing rectangle of the
072     * arc.
073     *
074     * @since 1.2
075     * @serial
076     */
077    public double y;
078
079    /**
080     * The overall width of the full ellipse of which this arc is a partial
081     * section (not considering the angular extents).
082     *
083     * @since 1.2
084     * @serial
085     */
086    public double width;
087
088    /**
089     * The overall height of the full ellipse of which this arc is a partial
090     * section (not considering the angular extents).
091     *
092     * @since 1.2
093     * @serial
094     */
095    public double height;
096
097    /**
098     * The starting angle of the arc in degrees.
099     *
100     * @since 1.2
101     * @serial
102     */
103    public double start;
104
105    /**
106     * The angular extent of the arc in degrees.
107     *
108     * @since 1.2
109     * @serial
110     */
111    public double extent;
112
113    /**
114     * Constructs a new arc, initialized to the specified location, size,
115     * angular extents, and closure type.
116     *
117     * @param x The X coordinate of the upper-left corner of the arc's framing
118     * rectangle.
119     * @param y The Y coordinate of the upper-left corner of the arc's framing
120     * rectangle.
121     * @param w The overall width of the full ellipse of which this arc is a
122     * partial section.
123     * @param h The overall height of the full ellipse of which this arc is a
124     * partial section.
125     * @param start The starting angle of the arc in degrees.
126     * @param extent The angular extent of the arc in degrees.
127     * @param type The closure type for the arc: {@link #OPEN}, {@link #CHORD},
128     * or {@link #PIE}.
129     * @since 1.2
130     */
131    public Arc2D(double x, double y, double w, double h,
132            double start, double extent, int type) {
133        //super(type);
134        setArcType(type);
135        this.x = x;
136        this.y = y;
137        this.width = w;
138        this.height = h;
139        this.start = start;
140        this.extent = extent;
141    }
142
143    /**
144     * Constructs a new arc, initialized to the specified location, size,
145     * angular extents, and closure type.
146     *
147     * @param ellipseBounds The framing rectangle that defines the outer
148     * boundary of the full ellipse of which this arc is a partial section.
149     * @param start The starting angle of the arc in degrees.
150     * @param extent The angular extent of the arc in degrees.
151     * @param type The closure type for the arc: {@link #OPEN}, {@link #CHORD},
152     * or {@link #PIE}.
153     * @since 1.2
154     */
155    //public Double(Rectangle2D ellipseBounds,
156    public Arc2D(Rectangle2D ellipseBounds,
157            double start, double extent, int type) {
158        //super(type);
159        setArcType(type);
160        this.x = ellipseBounds.getX();
161        this.y = ellipseBounds.getY();
162        this.width = ellipseBounds.getWidth();
163        this.height = ellipseBounds.getHeight();
164        this.start = start;
165        this.extent = extent;
166    }
167
168    /**
169     * {@inheritDoc} Note that the arc
170     * <a href="Arc2D.html#inscribes">partially inscribes</a>
171     * the framing rectangle of this {@code RectangularShape}.
172     *
173     * @since 1.2
174     */
175    public double getX() {
176        return x;
177    }
178
179    /**
180     * {@inheritDoc} Note that the arc
181     * <a href="Arc2D.html#inscribes">partially inscribes</a>
182     * the framing rectangle of this {@code RectangularShape}.
183     *
184     * @since 1.2
185     */
186    public double getY() {
187        return y;
188    }
189
190    /**
191     * {@inheritDoc} Note that the arc
192     * <a href="Arc2D.html#inscribes">partially inscribes</a>
193     * the framing rectangle of this {@code RectangularShape}.
194     *
195     * @since 1.2
196     */
197    public double getWidth() {
198        return width;
199    }
200
201    /**
202     * {@inheritDoc} Note that the arc
203     * <a href="Arc2D.html#inscribes">partially inscribes</a>
204     * the framing rectangle of this {@code RectangularShape}.
205     *
206     * @since 1.2
207     */
208    public double getHeight() {
209        return height;
210    }
211
212    /**
213     * {@inheritDoc}
214     *
215     * @since 1.2
216     */
217    public double getAngleStart() {
218        return start;
219    }
220
221    /**
222     * {@inheritDoc}
223     *
224     * @since 1.2
225     */
226    public double getAngleExtent() {
227        return extent;
228    }
229
230    /**
231     * {@inheritDoc}
232     *
233     * @since 1.2
234     */
235    public boolean isEmpty() {
236        return (width <= 0.0 || height <= 0.0);
237    }
238
239    /**
240     * {@inheritDoc}
241     *
242     * @since 1.2
243     */
244    public void setArc(double x, double y, double w, double h,
245            double angSt, double angExt, int closure) {
246        this.setArcType(closure);
247        this.x = x;
248        this.y = y;
249        this.width = w;
250        this.height = h;
251        this.start = angSt;
252        this.extent = angExt;
253    }
254
255    /**
256     * {@inheritDoc}
257     *
258     * @since 1.2
259     */
260    public void setAngleStart(double angSt) {
261        this.start = angSt;
262    }
263
264    /**
265     * {@inheritDoc}
266     *
267     * @since 1.2
268     */
269    public void setAngleExtent(double angExt) {
270        this.extent = angExt;
271    }
272
273    /*
274     * JDK 1.6 serialVersionUID
275     */
276    private static final long serialVersionUID = 728264085846882001L;
277
278    /**
279     * Writes the default serializable fields to the
280     * <code>ObjectOutputStream</code> followed by a byte indicating the arc
281     * type of this <code>Arc2D</code> instance.
282     *
283     * @serialData
284     * <ol>
285     * <li>The default serializable fields.
286     * <li>
287     * followed by a <code>byte</code> indicating the arc type
288     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
289     * </ol>
290     */
291    private void writeObject(java.io.ObjectOutputStream s)
292            throws java.io.IOException {
293        s.defaultWriteObject();
294
295        s.writeByte(getArcType());
296    }
297
298    /**
299     * Reads the default serializable fields from the
300     * <code>ObjectInputStream</code> followed by a byte indicating the arc type
301     * of this <code>Arc2D</code> instance.
302     *
303     * @serialData
304     * <ol>
305     * <li>The default serializable fields.
306     * <li>
307     * followed by a <code>byte</code> indicating the arc type
308     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
309     * </ol>
310     */
311    private void readObject(java.io.ObjectInputStream s)
312            throws java.lang.ClassNotFoundException, java.io.IOException {
313        s.defaultReadObject();
314
315        try {
316            setArcType(s.readByte());
317        } catch (IllegalArgumentException iae) {
318            throw new java.io.InvalidObjectException(iae.getMessage());
319        }
320    }
321//    }
322
323    private int type;
324
325    /**
326     * This is an abstract class that cannot be instantiated directly.
327     * Type-specific implementation subclasses are available for instantiation
328     * and provide a number of formats for storing the information necessary to
329     * satisfy the various accessor methods below.
330     * <p>
331     * This constructor creates an object with a default closure type of
332     * {@link #OPEN}. It is provided only to enable serialization of subclasses.
333     *
334     * @see java.awt.geom.Arc2D.Float
335     * @see java.awt.geom.Arc2D.Double
336     */
337    Arc2D() {
338        this(OPEN);
339    }
340
341    /**
342     * This is an abstract class that cannot be instantiated directly.
343     * Type-specific implementation subclasses are available for instantiation
344     * and provide a number of formats for storing the information necessary to
345     * satisfy the various accessor methods below.
346     *
347     * @param type The closure type of this arc: {@link #OPEN}, {@link #CHORD},
348     * or {@link #PIE}.
349     * @see java.awt.geom.Arc2D.Float
350     * @see java.awt.geom.Arc2D.Double
351     * @since 1.2
352     */
353    protected Arc2D(int type) {
354        setArcType(type);
355    }
356
357    /**
358     * Returns the arc closure type of the arc: {@link #OPEN},
359     * {@link #CHORD}, or {@link #PIE}.
360     *
361     * @return One of the integer constant closure types defined in this class.
362     * @see #setArcType
363     * @since 1.2
364     */
365    public int getArcType() {
366        return type;
367    }
368
369    /**
370     * Returns the starting point of the arc. This point is the intersection of
371     * the ray from the center defined by the starting angle and the elliptical
372     * boundary of the arc.
373     *
374     * @return A <CODE>Point2D</CODE> object representing the x,y coordinates of
375     * the starting point of the arc.
376     * @since 1.2
377     */
378    public Point2D getStartPoint() {
379        double angle = Math.toRadians(-getAngleStart());
380        double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth();
381        double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight();
382        //return new Point2D.Double(x, y);
383        return new Point2D.Double(x, y);
384    }
385
386    /**
387     * Returns the ending point of the arc. This point is the intersection of
388     * the ray from the center defined by the starting angle plus the angular
389     * extent of the arc and the elliptical boundary of the arc.
390     *
391     * @return A <CODE>Point2D</CODE> object representing the x,y coordinates of
392     * the ending point of the arc.
393     * @since 1.2
394     */
395    public Point2D getEndPoint() {
396        double angle = Math.toRadians(-getAngleStart() - getAngleExtent());
397        double x = getX() + (Math.cos(angle) * 0.5 + 0.5) * getWidth();
398        double y = getY() + (Math.sin(angle) * 0.5 + 0.5) * getHeight();
399        //return new Point2D.Double(x, y);
400        return new Point2D.Double(x, y);
401    }
402
403    /**
404     * Sets the location, size, angular extents, and closure type of this arc to
405     * the specified values.
406     *
407     * @param rect The framing rectangle that defines the outer boundary of the
408     * full ellipse of which this arc is a partial section.
409     * @param angSt The starting angle of the arc in degrees.
410     * @param angExt The angular extent of the arc in degrees.
411     * @param closure The closure type for the arc:
412     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
413     * @since 1.2
414     */
415    public void setArc2(Rectangle2D rect, double angSt, double angExt,
416            int closure) {
417        setArc(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight(),
418                angSt, angExt, closure);
419    }
420
421    /**
422     * Sets this arc to be the same as the specified arc.
423     *
424     * @param a The <CODE>Arc2D</CODE> to use to set the arc's values.
425     * @since 1.2
426     */
427    public void setArc3(Arc2D a) {
428        setArc(a.getX(), a.getY(), a.getWidth(), a.getHeight(),
429                a.getAngleStart(), a.getAngleExtent(), a.type);
430    }
431
432    /**
433     * Sets the position, bounds, angular extents, and closure type of this arc
434     * to the specified values. The arc is defined by a center point and a
435     * radius rather than a framing rectangle for the full ellipse.
436     *
437     * @param x The X coordinate of the center of the arc.
438     * @param y The Y coordinate of the center of the arc.
439     * @param radius The radius of the arc.
440     * @param angSt The starting angle of the arc in degrees.
441     * @param angExt The angular extent of the arc in degrees.
442     * @param closure The closure type for the arc:
443     * {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
444     * @since 1.2
445     */
446    public void setArcByCenter(double x, double y, double radius,
447            double angSt, double angExt, int closure) {
448        setArc(x - radius, y - radius, radius * 2.0, radius * 2.0,
449                angSt, angExt, closure);
450    }
451
452    /**
453     * Sets the position, bounds, and angular extents of this arc to the
454     * specified value. The starting angle of the arc is tangent to the line
455     * specified by points (p1, p2), the ending angle is tangent to the line
456     * specified by points (p2, p3), and the arc has the specified radius.
457     *
458     * @param p1 The first point that defines the arc. The starting angle of the
459     * arc is tangent to the line specified by points (p1, p2).
460     * @param p2 The second point that defines the arc. The starting angle of
461     * the arc is tangent to the line specified by points (p1, p2). The ending
462     * angle of the arc is tangent to the line specified by points (p2, p3).
463     * @param p3 The third point that defines the arc. The ending angle of the
464     * arc is tangent to the line specified by points (p2, p3).
465     * @param radius The radius of the arc.
466     * @since 1.2
467     */
468    public void setArcByTangent(Point2D p1, Point2D p2, Point2D p3,
469            double radius) {
470        double ang1 = Math.atan2(p1.getY() - p2.getY(),
471                p1.getX() - p2.getX());
472        double ang2 = Math.atan2(p3.getY() - p2.getY(),
473                p3.getX() - p2.getX());
474        double diff = ang2 - ang1;
475        if (diff > Math.PI) {
476            ang2 -= Math.PI * 2.0;
477        } else if (diff < -Math.PI) {
478            ang2 += Math.PI * 2.0;
479        }
480        double bisect = (ang1 + ang2) / 2.0;
481        double theta = Math.abs(ang2 - bisect);
482        double dist = radius / Math.sin(theta);
483        double x = p2.getX() + dist * Math.cos(bisect);
484        double y = p2.getY() + dist * Math.sin(bisect);
485        // REMIND: This needs some work...
486        if (ang1 < ang2) {
487            ang1 -= Math.PI / 2.0;
488            ang2 += Math.PI / 2.0;
489        } else {
490            ang1 += Math.PI / 2.0;
491            ang2 -= Math.PI / 2.0;
492        }
493        ang1 = Math.toDegrees(-ang1);
494        ang2 = Math.toDegrees(-ang2);
495        diff = ang2 - ang1;
496        if (diff < 0) {
497            diff += 360;
498        } else {
499            diff -= 360;
500        }
501        setArcByCenter(x, y, radius, ang1, diff, type);
502    }
503
504    /**
505     * Sets the closure type of this arc to the specified value:
506     * <CODE>OPEN</CODE>, <CODE>CHORD</CODE>, or <CODE>PIE</CODE>.
507     *
508     * @param type The integer constant that represents the closure type of this
509     * arc: {@link #OPEN}, {@link #CHORD}, or {@link #PIE}.
510     *
511     * @throws IllegalArgumentException if <code>type</code> is not 0, 1, or 2.+
512     * @see #getArcType
513     * @since 1.2
514     */
515    public void setArcType(int type) {
516        if (type < OPEN || type > PIE) {
517            throw new IllegalArgumentException("invalid type for Arc: " + type);
518        }
519        this.type = type;
520    }
521
522    /**
523     * {@inheritDoc} Note that the arc
524     * <a href="Arc2D.html#inscribes">partially inscribes</a>
525     * the framing rectangle of this {@code RectangularShape}.
526     *
527     * @since 1.2
528     */
529    public void setFrame(double x, double y, double w, double h) {
530        setArc(x, y, w, h, getAngleStart(), getAngleExtent(), type);
531    }
532
533    /**
534     * Returns the high-precision framing rectangle of the arc. The framing
535     * rectangle contains only the part of this <code>Arc2D</code> that is in
536     * between the starting and ending angles and contains the pie wedge, if
537     * this <code>Arc2D</code> has a <code>PIE</code> closure type.
538     * <p>
539     * This method differs from the
540     * {@link RectangularShape#getBounds() getBounds} in that the
541     * <code>getBounds</code> method only returns the bounds of the enclosing
542     * ellipse of this <code>Arc2D</code> without considering the starting and
543     * ending angles of this <code>Arc2D</code>.
544     *
545     * @return the <CODE>Rectangle2D</CODE> that represents the arc's framing
546     * rectangle.
547     * @since 1.2
548     */
549    public Rectangle2D getBounds2D() {
550        if (isEmpty()) {
551            return makeBounds(getX(), getY(), getWidth(), getHeight());
552        }
553        double x1, y1, x2, y2;
554        if (getArcType() == PIE) {
555            x1 = y1 = x2 = y2 = 0.0;
556        } else {
557            x1 = y1 = 1.0;
558            x2 = y2 = -1.0;
559        }
560        double angle = 0.0;
561        for (int i = 0; i < 6; i++) {
562            if (i < 4) {
563                // 0-3 are the four quadrants
564                angle += 90.0;
565                if (!containsAngle(angle)) {
566                    continue;
567                }
568            } else if (i == 4) {
569                // 4 is start angle
570                angle = getAngleStart();
571            } else {
572                // 5 is end angle
573                angle += getAngleExtent();
574            }
575            double rads = Math.toRadians(-angle);
576            double xe = Math.cos(rads);
577            double ye = Math.sin(rads);
578            x1 = Math.min(x1, xe);
579            y1 = Math.min(y1, ye);
580            x2 = Math.max(x2, xe);
581            y2 = Math.max(y2, ye);
582        }
583        double w = getWidth();
584        double h = getHeight();
585        x2 = (x2 - x1) * 0.5 * w;
586        y2 = (y2 - y1) * 0.5 * h;
587        x1 = getX() + (x1 * 0.5 + 0.5) * w;
588        y1 = getY() + (y1 * 0.5 + 0.5) * h;
589        return makeBounds(x1, y1, x2, y2);
590    }
591
592    protected Rectangle2D makeBounds(double x, double y,
593            double w, double h) {
594        return null;
595    }
596    /*
597     * Normalizes the specified angle into the range -180 to 180.
598     */
599    static double normalizeDegrees(double angle) {
600        if (angle > 180.0) {
601            if (angle <= (180.0 + 360.0)) {
602                angle = angle - 360.0;
603            } else {
604                angle = Math.IEEEremainder(angle, 360.0);
605                // IEEEremainder can return -180 here for some input values...
606                if (angle == -180.0) {
607                    angle = 180.0;
608                }
609            }
610        } else if (angle <= -180.0) {
611            if (angle > (-180.0 - 360.0)) {
612                angle = angle + 360.0;
613            } else {
614                angle = Math.IEEEremainder(angle, 360.0);
615                // IEEEremainder can return -180 here for some input values...
616                if (angle == -180.0) {
617                    angle = 180.0;
618                }
619            }
620        }
621        return angle;
622    }
623
624    /**
625     * Determines whether or not the specified angle is within the angular
626     * extents of the arc.
627     *
628     * @param angle The angle to test.
629     *
630     * @return <CODE>true</CODE> if the arc contains the angle,
631     * <CODE>false</CODE> if the arc doesn't contain the angle.
632     * @since 1.2
633     */
634    public boolean containsAngle(double angle) {
635        double angExt = getAngleExtent();
636        boolean backwards = (angExt < 0.0);
637        if (backwards) {
638            angExt = -angExt;
639        }
640        if (angExt >= 360.0) {
641            return true;
642        }
643        angle = normalizeDegrees(angle) - normalizeDegrees(getAngleStart());
644        if (backwards) {
645            angle = -angle;
646        }
647        if (angle < 0.0) {
648            angle += 360.0;
649        }
650
651        return (angle >= 0.0) && (angle < angExt);
652    }
653
654    /**
655     * Determines whether or not the specified point is inside the boundary of
656     * the arc.
657     *
658     * @param x The X coordinate of the point to test.
659     * @param y The Y coordinate of the point to test.
660     *
661     * @return <CODE>true</CODE> if the point lies within the bound of the arc,
662     * <CODE>false</CODE> if the point lies outside of the arc's bounds.
663     * @since 1.2
664     */
665    public boolean contains(double x, double y) {
666        // Normalize the coordinates compared to the ellipse
667        // having a center at 0,0 and a radius of 0.5.
668        double ellw = getWidth();
669        if (ellw <= 0.0) {
670            return false;
671        }
672        double normx = (x - getX()) / ellw - 0.5;
673        double ellh = getHeight();
674        if (ellh <= 0.0) {
675            return false;
676        }
677        double normy = (y - getY()) / ellh - 0.5;
678        double distSq = (normx * normx + normy * normy);
679        if (distSq >= 0.25) {
680            return false;
681        }
682        double angExt = Math.abs(getAngleExtent());
683        if (angExt >= 360.0) {
684            return true;
685        }
686        boolean inarc = containsAngle(-Math.toDegrees(Math.atan2(normy,
687                normx)));
688        if (type == PIE) {
689            return inarc;
690        }
691        // CHORD and OPEN behave the same way
692        if (inarc) {
693            if (angExt >= 180.0) {
694                return true;
695            }
696            // point must be outside the "pie triangle"
697        } else {
698            if (angExt <= 180.0) {
699                return false;
700            }
701            // point must be inside the "pie triangle"
702        }
703        // The point is inside the pie triangle iff it is on the same
704        // side of the line connecting the ends of the arc as the center.
705        double angle = Math.toRadians(-getAngleStart());
706        double x1 = Math.cos(angle);
707        double y1 = Math.sin(angle);
708        angle += Math.toRadians(-getAngleExtent());
709        double x2 = Math.cos(angle);
710        double y2 = Math.sin(angle);
711        boolean inside = (Line2D.relativeCCW(x1, y1, x2, y2, 2 * normx, 2 * normy)
712                * Line2D.relativeCCW(x1, y1, x2, y2, 0, 0) >= 0);
713        return inarc ? !inside : inside;
714    }
715
716    /**
717     * Returns an iteration object that defines the boundary of the arc. This
718     * iterator is multithread safe. <code>Arc2D</code> guarantees that
719     * modifications to the geometry of the arc do not affect any iterations of
720     * that geometry that are already in process.
721     *
722     * @param at an optional <CODE>AffineTransform</CODE> to be applied to the
723     * coordinates as they are returned in the iteration, or null if the
724     * untransformed coordinates are desired.
725     *
726     * @return A <CODE>PathIterator</CODE> that defines the arc's boundary.
727     * @since 1.2
728     */
729    public ArcIterator getPathIterator(AffineTransform at) {
730        return new ArcIterator(this, at);
731    }
732
733    /**
734     * Returns the hashcode for this <code>Arc2D</code>.
735     *
736     * @return the hashcode for this <code>Arc2D</code>.
737     * @since 1.6
738     */
739    public int hashCode() {
740        long bits = java.lang.Double.doubleToLongBits(getX());
741        bits += java.lang.Double.doubleToLongBits(getY()) * 37;
742        bits += java.lang.Double.doubleToLongBits(getWidth()) * 43;
743        bits += java.lang.Double.doubleToLongBits(getHeight()) * 47;
744        bits += java.lang.Double.doubleToLongBits(getAngleStart()) * 53;
745        bits += java.lang.Double.doubleToLongBits(getAngleExtent()) * 59;
746        bits += getArcType() * 61;
747        return (((int) bits) ^ ((int) (bits >> 32)));
748    }
749
750    /**
751     * Determines whether or not the specified <code>Object</code> is equal to
752     * this <code>Arc2D</code>. The specified <code>Object</code> is equal to
753     * this <code>Arc2D</code> if it is an instance of <code>Arc2D</code> and if
754     * its location, size, arc extents and type are the same as this
755     * <code>Arc2D</code>.
756     *
757     * @param obj an <code>Object</code> to be compared with this
758     * <code>Arc2D</code>.
759     * @return  <code>true</code> if <code>obj</code> is an instance of
760     * <code>Arc2D</code> and has the same values; <code>false</code> otherwise.
761     * @since 1.6
762     */
763    public boolean equals(Object obj) {
764        if (obj == this) {
765            return true;
766        }
767        if (obj instanceof Arc2D) {
768            Arc2D a2d = (Arc2D) obj;
769            return ((getX() == a2d.getX())
770                    && (getY() == a2d.getY())
771                    && (getWidth() == a2d.getWidth())
772                    && (getHeight() == a2d.getHeight())
773                    && (getAngleStart() == a2d.getAngleStart())
774                    && (getAngleExtent() == a2d.getAngleExtent())
775                    && (getArcType() == a2d.getArcType()));
776        }
777        return false;
778    }
779}