Point implements Serializable, Cloneable { public static double distance(double x1, double y1, double x2, double y2) { return Math.sqrt(distanceSq(x1, y1, x2, y2)); } Point();  Point(int x, int y);  Point(double x, double y);  Point(Point p); @Override boolean equals(Object obj); @Override String toString(); double getX(); double getY(); Point getLocation(); void setLocation(Point p); void setLocation(int x, int y); void setLocation(double x, double y); void move(double x, double y); void translate(double dx, double dy); @Override int hashCode(); static double distanceSq(double x1, double y1, double x2, double y2); double distanceSq(double px, double py); double distanceSq(Point p); static double distance(double x1, double y1, double x2, double y2); double distance(double px, double py); double distance(Point p); @SuppressWarnings("CloneDoesntCallSuperClone") @Override Object clone(); public double x; public double y; }
@Test public void distanceBetweenCoordinatesTest() { Point first = new Point(1, 1); Point second = new Point(1.1, 1.1); double expected = Math.sqrt(0.02); Assert.assertEquals(expected, Point.distance(first.x, first.y, second.x, second.y), EPSILON_COMPARISON); }
@Test public void distanceByCoordinatesTest() { Point first = new Point(1, 1); Point second = new Point(1.1, 1.1); double expected = Math.sqrt(0.02); Assert.assertEquals(expected, first.distance(second.x, second.y), EPSILON_COMPARISON); }
@Test public void distanceByPointTest() { Point first = new Point(1, 1); Point second = new Point(1.1, 1.1); double expected = Math.sqrt(0.02); Assert.assertEquals(expected, first.distance(second), EPSILON_COMPARISON); }
@Test public void distanceItselfTest() { Point first = new Point(1, 1); Assert.assertEquals(0, first.distance(first), EPSILON_COMPARISON); }