jdk/src/share/classes/java/awt/geom/Point2D.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 5506 202f599c92aa
child 23010 6dadb192ad81
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.geom;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.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
 * The <code>Point2D</code> class defines a point representing a location
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * in {@code (x,y)} coordinate space.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * This class is only the abstract superclass for all objects that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * store a 2D coordinate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * The actual storage representation of the coordinates is left to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author      Jim Graham
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public abstract class Point2D implements Cloneable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * The <code>Float</code> class defines a point specified in float
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static class Float extends Point2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
         * The X coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        public float x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
         * The Y coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        public float y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
         * Constructs and initializes a <code>Point2D</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         * coordinates (0,&nbsp;0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        public Float() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
         * Constructs and initializes a <code>Point2D</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
         * the specified coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
         * @param x the X coordinate of the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
         *          constructed <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
         * @param y the Y coordinate of the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
         *          constructed <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        public Float(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        public double getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return (double) 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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        public double getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            return (double) 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
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public void setLocation(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            this.x = (float) x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            this.y = (float) y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * Sets the location of this <code>Point2D</code> to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * specified <code>float</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
         * @param x the new X coordinate of this {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
         * @param y the new Y coordinate of this {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        public void setLocation(float x, float y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
         * Returns a <code>String</code> that represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
         * of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * @return a string representation of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            return "Point2D.Float["+x+", "+y+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        private static final long serialVersionUID = -2870572449815403710L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * The <code>Double</code> class defines a point specified in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public static class Double extends Point2D implements Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * The X coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        public double x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         * The Y coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        public double y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * Constructs and initializes a <code>Point2D</code> with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * coordinates (0,&nbsp;0).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        public Double() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
         * Constructs and initializes a <code>Point2D</code> with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
         * specified coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
         * @param x the X coordinate of the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
         *          constructed <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * @param y the Y coordinate of the newly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         *          constructed <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public Double(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            this.y = y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        public double getX() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            return x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        public double getY() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return y;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
         * {@inheritDoc}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        public void setLocation(double x, double y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            this.x = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            this.y = y;
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
         * Returns a <code>String</code> that represents the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         * @return a string representation of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            return "Point2D.Double["+x+", "+y+"]";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * JDK 1.6 serialVersionUID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        private static final long serialVersionUID = 6150783262733311327L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * This is an abstract class that cannot be instantiated directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * Type-specific implementation subclasses are available for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * instantiation and provide a number of formats for storing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * the information necessary to satisfy the various accessor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * methods below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @see java.awt.geom.Point2D.Float
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see java.awt.geom.Point2D.Double
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * @see java.awt.Point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    protected Point2D() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns the X coordinate of this <code>Point2D</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @return the X coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public abstract double getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Returns the Y coordinate of this <code>Point2D</code> in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * <code>double</code> precision.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return the Y coordinate of this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public abstract double getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * Sets the location of this <code>Point2D</code> to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * specified <code>double</code> coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param x the new X coordinate of this {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param y the new Y coordinate of this {@code Point2D}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    public abstract void setLocation(double x, double y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * Sets the location of this <code>Point2D</code> to the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * coordinates as the specified <code>Point2D</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param p the specified <code>Point2D</code> to which to set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    public void setLocation(Point2D p) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        setLocation(p.getX(), p.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Returns the square of the distance between two points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * @param x1 the X coordinate of the first specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @param y1 the Y coordinate of the first specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param x2 the X coordinate of the second specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @param y2 the Y coordinate of the second specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return the square of the distance between the two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * sets of specified coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public static double distanceSq(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                                    double x2, double y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        x1 -= x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        y1 -= y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        return (x1 * x1 + y1 * y1);
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
     * Returns the distance between two points.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @param x1 the X coordinate of the first specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @param y1 the Y coordinate of the first specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * @param x2 the X coordinate of the second specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @param y2 the Y coordinate of the second specified point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @return the distance between the two sets of specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public static double distance(double x1, double y1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                  double x2, double y2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        x1 -= x2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        y1 -= y2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        return Math.sqrt(x1 * x1 + y1 * y1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * Returns the square of the distance from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <code>Point2D</code> to a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * @param px the X coordinate of the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * @param py the Y coordinate of the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @return the square of the distance between this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * <code>Point2D</code> and the specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    public double distanceSq(double px, double py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        px -= getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
        py -= getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        return (px * px + py * py);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * Returns the square of the distance from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <code>Point2D</code> to a specified <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @param pt the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @return the square of the distance between this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * <code>Point2D</code> to a specified <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    public double distanceSq(Point2D pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        double px = pt.getX() - this.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        double py = pt.getY() - this.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        return (px * px + py * py);
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
     * Returns the distance from this <code>Point2D</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @param px the X coordinate of the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @param py the Y coordinate of the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @return the distance between this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * and a specified point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    public double distance(double px, double py) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        px -= getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        py -= getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        return Math.sqrt(px * px + py * py);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * Returns the distance from this <code>Point2D</code> to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * specified <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @param pt the specified point to be measured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *           against this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @return the distance between this <code>Point2D</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the specified <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public double distance(Point2D pt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        double px = pt.getX() - this.getX();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        double py = pt.getY() - this.getY();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        return Math.sqrt(px * px + py * py);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * Creates a new object of the same class and with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * same contents as this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @return     a clone of this instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * @exception  OutOfMemoryError            if there is not enough memory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @see        java.lang.Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @since      1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            // this shouldn't happen, since we are Cloneable
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 5506
diff changeset
   396
            throw new InternalError(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Returns the hashcode for this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * @return      a hash code for this <code>Point2D</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        long bits = java.lang.Double.doubleToLongBits(getX());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        bits ^= java.lang.Double.doubleToLongBits(getY()) * 31;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return (((int) bits) ^ ((int) (bits >> 32)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Determines whether or not two points are equal. Two instances of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * <code>Point2D</code> are equal if the values of their
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <code>x</code> and <code>y</code> member fields, representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * their position in the coordinate space, are the same.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param obj an object to be compared with this <code>Point2D</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return <code>true</code> if the object to be compared is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *         an instance of <code>Point2D</code> and has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *         the same values; <code>false</code> otherwise.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (obj instanceof Point2D) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            Point2D p2d = (Point2D) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            return (getX() == p2d.getX()) && (getY() == p2d.getY());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return super.equals(obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
}