1 /* Copyright (C) 1999, 2000, 2002 Free Software Foundation
3 This file is part of GNU Classpath.
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)
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.
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
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
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. */
37 package java
.awt
.geom
;
40 * @author Per Bothner <bothner@cygnus.com>
41 * @date February 8, 1999.
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.
50 public abstract class Point2D
implements Cloneable
52 public abstract double getX();
53 public abstract double getY();
55 public abstract void setLocation (double x
, double y
);
61 public void setLocation (Point2D pt
) { setLocation(pt
.getX(), pt
.getY()); }
63 static public double distanceSq (double X1
, double Y1
, double X2
, double Y2
)
70 static public double distance (double X1
, double Y1
, double X2
, double Y2
)
72 return Math
.sqrt(distanceSq(X1
, Y1
, X2
, Y2
));
75 public double distanceSq (double PX
, double PY
)
77 return distanceSq (getX(), PX
, getY(), PY
);
80 public double distance (double PX
, double PY
)
82 return distance (getX(), PX
, getY(), PY
);
85 public double distanceSq (Point2D pt
)
87 return distanceSq (getX(), pt
.getX(), getY(), pt
.getY());
90 public double distance (Point2D pt
)
92 return distance (getX(), pt
.getX(), getY(), pt
.getY());
95 public int hashCode() { return (int) getX() ^
(int) getY(); }
101 return super.clone ();
103 catch (CloneNotSupportedException _
) {return null;}
106 public boolean equals (Object o
)
108 if (! (o
instanceof Point2D
))
110 Point2D p
= (Point2D
) o
;
111 return getX () == p
.getX () && getY () == p
.getY ();
114 public static class Double
extends Point2D
125 public Double (double x
, double y
)
131 public double getX ()
136 public double getY ()
141 public void setLocation (double x
, double y
)
147 public String
toString ()
149 return "(" + x
+ ", " + y
+ ")";
153 public static class Float
extends Point2D
164 public Float (float x
, float y
)
170 public double getX ()
175 public double getY ()
180 public void setLocation (double x
, double y
)
186 public void setLocation (float x
, float y
)
192 public String
toString ()
194 return "(" + x
+ ", " + y
+ ")";