| 1 | /* Copyright (C) 1999, 2000, 2002 Free Software Foundation
|
|---|
| 2 |
|
|---|
| 3 | This file is part of GNU Classpath.
|
|---|
| 4 |
|
|---|
| 5 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 6 | it under the terms of the GNU General Public License as published by
|
|---|
| 7 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 8 | any later version.
|
|---|
| 9 |
|
|---|
| 10 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 13 | General Public License for more details.
|
|---|
| 14 |
|
|---|
| 15 | You should have received a copy of the GNU General Public License
|
|---|
| 16 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 17 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 18 | 02111-1307 USA.
|
|---|
| 19 |
|
|---|
| 20 | Linking this library statically or dynamically with other modules is
|
|---|
| 21 | making a combined work based on this library. Thus, the terms and
|
|---|
| 22 | conditions of the GNU General Public License cover the whole
|
|---|
| 23 | combination.
|
|---|
| 24 |
|
|---|
| 25 | As a special exception, the copyright holders of this library give you
|
|---|
| 26 | permission to link this library with independent modules to produce an
|
|---|
| 27 | executable, regardless of the license terms of these independent
|
|---|
| 28 | modules, and to copy and distribute the resulting executable under
|
|---|
| 29 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 30 | independent module, the terms and conditions of the license of that
|
|---|
| 31 | module. An independent module is a module which is not derived from
|
|---|
| 32 | or based on this library. If you modify this library, you may extend
|
|---|
| 33 | this exception to your version of the library, but you are not
|
|---|
| 34 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 35 | exception statement from your version. */
|
|---|
| 36 |
|
|---|
| 37 | package java.awt.geom;
|
|---|
| 38 |
|
|---|
| 39 | /**
|
|---|
| 40 | * @author Per Bothner <[email protected]>
|
|---|
| 41 | * @date February 8, 1999.
|
|---|
| 42 | */
|
|---|
| 43 |
|
|---|
| 44 | /* Written using "Java Class Libraries", 2nd edition, plus online
|
|---|
| 45 | * API docs for JDK 1.2 beta from http://www.javasoft.com.
|
|---|
| 46 | * Status: Believed complete and correct, except that neither toString
|
|---|
| 47 | * nor hashCode have been compared with JDK output.
|
|---|
| 48 | */
|
|---|
| 49 |
|
|---|
| 50 | public abstract class Point2D implements Cloneable
|
|---|
| 51 | {
|
|---|
| 52 | public abstract double getX();
|
|---|
| 53 | public abstract double getY();
|
|---|
| 54 |
|
|---|
| 55 | public abstract void setLocation (double x, double y);
|
|---|
| 56 |
|
|---|
| 57 | protected Point2D ()
|
|---|
| 58 | {
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | public void setLocation (Point2D pt) { setLocation(pt.getX(), pt.getY()); }
|
|---|
| 62 |
|
|---|
| 63 | static public double distanceSq (double X1, double Y1, double X2, double Y2)
|
|---|
| 64 | {
|
|---|
| 65 | X2 -= X1;
|
|---|
| 66 | Y2 -= Y1;
|
|---|
| 67 | return X2*X2 + Y2*Y2;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | static public double distance (double X1, double Y1, double X2, double Y2)
|
|---|
| 71 | {
|
|---|
| 72 | return Math.sqrt(distanceSq(X1, Y1, X2, Y2));
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | public double distanceSq (double PX, double PY)
|
|---|
| 76 | {
|
|---|
| 77 | return distanceSq (getX(), PX, getY(), PY);
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | public double distance (double PX, double PY)
|
|---|
| 81 | {
|
|---|
| 82 | return distance (getX(), PX, getY(), PY);
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | public double distanceSq (Point2D pt)
|
|---|
| 86 | {
|
|---|
| 87 | return distanceSq (getX(), pt.getX(), getY(), pt.getY());
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | public double distance (Point2D pt)
|
|---|
| 91 | {
|
|---|
| 92 | return distance (getX(), pt.getX(), getY(), pt.getY());
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | public int hashCode() { return (int) getX() ^ (int) getY(); }
|
|---|
| 96 |
|
|---|
| 97 | public Object clone()
|
|---|
| 98 | {
|
|---|
| 99 | try
|
|---|
| 100 | {
|
|---|
| 101 | return super.clone ();
|
|---|
| 102 | }
|
|---|
| 103 | catch (CloneNotSupportedException _) {return null;}
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | public boolean equals (Object o)
|
|---|
| 107 | {
|
|---|
| 108 | if (! (o instanceof Point2D))
|
|---|
| 109 | return false;
|
|---|
| 110 | Point2D p = (Point2D) o;
|
|---|
| 111 | return getX () == p.getX () && getY () == p.getY ();
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | public static class Double extends Point2D
|
|---|
| 115 | {
|
|---|
| 116 | public double x;
|
|---|
| 117 | public double y;
|
|---|
| 118 |
|
|---|
| 119 | public Double ()
|
|---|
| 120 | {
|
|---|
| 121 | x = 0;
|
|---|
| 122 | y = 0;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | public Double (double x, double y)
|
|---|
| 126 | {
|
|---|
| 127 | this.x = x;
|
|---|
| 128 | this.y = y;
|
|---|
| 129 | }
|
|---|
| 130 |
|
|---|
| 131 | public double getX ()
|
|---|
| 132 | {
|
|---|
| 133 | return x;
|
|---|
| 134 | }
|
|---|
| 135 |
|
|---|
| 136 | public double getY ()
|
|---|
| 137 | {
|
|---|
| 138 | return y;
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | public void setLocation (double x, double y)
|
|---|
| 142 | {
|
|---|
| 143 | this.x = x;
|
|---|
| 144 | this.y = y;
|
|---|
| 145 | }
|
|---|
| 146 |
|
|---|
| 147 | public String toString ()
|
|---|
| 148 | {
|
|---|
| 149 | return "(" + x + ", " + y + ")";
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 |
|
|---|
| 153 | public static class Float extends Point2D
|
|---|
| 154 | {
|
|---|
| 155 | public float x;
|
|---|
| 156 | public float y;
|
|---|
| 157 |
|
|---|
| 158 | public Float ()
|
|---|
| 159 | {
|
|---|
| 160 | x = 0;
|
|---|
| 161 | y = 0;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | public Float (float x, float y)
|
|---|
| 165 | {
|
|---|
| 166 | this.x = x;
|
|---|
| 167 | this.y = y;
|
|---|
| 168 | }
|
|---|
| 169 |
|
|---|
| 170 | public double getX ()
|
|---|
| 171 | {
|
|---|
| 172 | return x;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | public double getY ()
|
|---|
| 176 | {
|
|---|
| 177 | return y;
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | public void setLocation (double x, double y)
|
|---|
| 181 | {
|
|---|
| 182 | this.x = (float) x;
|
|---|
| 183 | this.y = (float) y;
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | public void setLocation (float x, float y)
|
|---|
| 187 | {
|
|---|
| 188 | this.x = x;
|
|---|
| 189 | this.y = y;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | public String toString ()
|
|---|
| 193 | {
|
|---|
| 194 | return "(" + x + ", " + y + ")";
|
|---|
| 195 | }
|
|---|
| 196 | }
|
|---|
| 197 | }
|
|---|