initial commit
[applet-bots.git] / src / appletbots / geometry / Point.java
blobf5247874e38583baa08ce6436757de6ddd377204
1 /*
2 * Copyright (c) 2002 Erik Rasmussen - All Rights Reserverd
3 */
4 package appletbots.geometry;
6 /**
7 * This class represents a point in two-dimensional space
9 * @author Erik Rasmussen
11 public class Point
13 /**
14 * The x-coordinate
16 public double x;
17 /**
18 * The y-coordinate
20 public double y;
22 /**
23 * Creates a new point with the given coordinates
25 * @param x The x-coordinate
26 * @param y The y-coordinate
28 public Point(final double x, final double y)
30 this.x = x;
31 this.y = y;
34 /**
35 * Returns the distance between this point and another point
37 * @param point Another point
38 * @return The distance between this point and another point
40 public double distance(final Point point)
42 final double px = point.x - x;
43 final double py = point.y - y;
44 return Math.sqrt(px * px + py * py);
47 /**
48 * Returns the result of adding a vector to this point
50 * @param vector The vector to add
51 * @return The result of adding a vector to this point
53 public Point add(final Vector vector)
55 return new Point(x + vector.x, y + vector.y);
58 /**
59 * Returns whether or not this point equals another point
61 * @param obj Another point
62 * @return Whether or not this point equals another point
64 public boolean equals(final Object obj)
66 if (obj instanceof Point)
68 final Point that = (Point) obj;
69 return this.x == that.x && this.y == that.y;
71 return false;
74 /**
75 * Returns a copy of this point
77 * @return A copy of this point
79 public Object clone()
81 return new Point(x, y);
84 /**
85 * Returns a string representation of this point
87 * @return A string representation of this point
89 public String toString()
91 return "(" + x + "," + y + ")";