2002-04-08 Alberto Biancardi <alberto.biancardi@unipv.it>
[official-gcc.git] / libjava / java / awt / geom / Point2D.java
blob598402b00c0d141d4f22775939f0996d2a5b4dfe
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)
8 any later version.
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
18 02111-1307 USA.
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.
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;
39 /**
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);
57 protected Point2D ()
61 public void setLocation (Point2D pt) { setLocation(pt.getX(), pt.getY()); }
63 static public double distanceSq (double X1, double Y1, double X2, double Y2)
65 X2 -= X1;
66 Y2 -= Y1;
67 return X2*X2 + Y2*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(); }
97 public Object clone()
99 try
101 return super.clone ();
103 catch (CloneNotSupportedException _) {return null;}
106 public boolean equals (Object o)
108 if (! (o instanceof Point2D))
109 return false;
110 Point2D p = (Point2D) o;
111 return getX () == p.getX () && getY () == p.getY ();
114 public static class Double extends Point2D
116 public double x;
117 public double y;
119 public Double ()
121 x = 0;
122 y = 0;
125 public Double (double x, double y)
127 this.x = x;
128 this.y = y;
131 public double getX ()
133 return x;
136 public double getY ()
138 return y;
141 public void setLocation (double x, double y)
143 this.x = x;
144 this.y = y;
147 public String toString ()
149 return "(" + x + ", " + y + ")";
153 public static class Float extends Point2D
155 public float x;
156 public float y;
158 public Float ()
160 x = 0;
161 y = 0;
164 public Float (float x, float y)
166 this.x = x;
167 this.y = y;
170 public double getX ()
172 return x;
175 public double getY ()
177 return y;
180 public void setLocation (double x, double y)
182 this.x = (float) x;
183 this.y = (float) y;
186 public void setLocation (float x, float y)
188 this.x = x;
189 this.y = y;
192 public String toString ()
194 return "(" + x + ", " + y + ")";