/** * Determines whether or not two points are equal. Two instances of <code>Point2D</code> are equal * if the values of their <code>x</code> and <code>y</code> member fields, representing their * position in the coordinate space, are the same. * * @param obj an object to be compared with this <code>Point2D</code> * @return <code>true</code> if the object to be compared is an instance of <code>Point2D</code> * and has the same values; <code>false</code> otherwise. * @since 1.2 */ public boolean equals(Object obj) { if (obj instanceof Point2D) { Point2D p2d = (Point2D) obj; return (getX() == p2d.getX()) && (getY() == p2d.getY()); } return super.equals(obj); }
/** * Returns the distance from this <code>Point2D</code> to a specified <code>Point2D</code>. * * @param pt the specified point to be measured against this <code>Point2D</code> * @return the distance between this <code>Point2D</code> and the specified <code>Point2D</code>. * @since 1.2 */ public double distance(Point2D pt) { double px = pt.getX() - this.getX(); double py = pt.getY() - this.getY(); return Math.sqrt(px * px + py * py); }
/** * Sets the location of this <code>Point2D</code> to the same coordinates as the specified <code> * Point2D</code> object. * * @param p the specified <code>Point2D</code> to which to set this <code>Point2D</code> * @since 1.2 */ public void setLocation(Point2D p) { setLocation(p.getX(), p.getY()); }