Point implements Serializable, Cloneable { public void translate(double dx, double dy) { x += dx; y += dy; } 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 translateTest() { float w = 3.73f; float h = 5.23f; Rectangle rectangle = new Rectangle(0, 0, w, h); Point[] expectedPoints = rectangle.toPointsArray(); Point point = new Point(0, 0); point.translate(w, 0); Assert.assertEquals(expectedPoints[1], point); point.translate(0, h); Assert.assertEquals(expectedPoints[2], point); point.translate(-w, 0); Assert.assertEquals(expectedPoints[3], point); point.translate(0, -h); Assert.assertEquals(expectedPoints[0], point); }