/**************************************************************************** ** Point2d.java - model a 2d point or vector ** Copyright (C) 1996 Ray L. Ewbank ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2 of the License, or ** (at your option) any later version. ** ** This program is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. ** ** You should have received a copy of the GNU General Public License ** along with this program; if not, write to the Free Software ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ** ** Direct any questions concerning this piece of Software to: ** ** Ray L. Ewbank ** 29-02 Arlington Road ** Woburn, MA 01801 ** ** (617) 938-7137 ** ** ewbank@gis.net **************************************************************************** */ class Point2d { public double x; public double y; public Point2d() {x=y=0.0;} public Point2d(double inx, double iny) {x=inx;y=iny;} public void normalize() { double r = x*x+y*y; if (r > 0.0) { r = Math.sqrt(r); x/=r; y/=r; } } public double dot(Point2d p) { return x*p.x+y*p.y; } public Point2d subtract(Point2d p) { Point2d t = new Point2d(); t.x = x-p.x; t.y = y-p.y; return t; } public int hashCode() { return (int)(x*27) ^ (int)(y*31); } public boolean equals(Object obj) { if (obj instanceof Point3d) { Point3d p = (Point3d)obj; return (x==p.x) && (y==p.y); } return false; } public String toString() { return getClass().getName()+ "[x=" + x + ",y=" + y + "]"; } }