diff --git a/commons/src/main/java/lcsb/mapviewer/common/geometry/PointTransformation.java b/commons/src/main/java/lcsb/mapviewer/common/geometry/PointTransformation.java index 5f32d1fcdd2ea89d1ed64151d79f9562f90d20ae..01480e7b3fbb254ac5ab73d4ba6fe434115bf158 100644 --- a/commons/src/main/java/lcsb/mapviewer/common/geometry/PointTransformation.java +++ b/commons/src/main/java/lcsb/mapviewer/common/geometry/PointTransformation.java @@ -27,7 +27,7 @@ public class PointTransformation { * angle by which we want to rotate * @param center * central point around which we rotate the object - * @return the same object rotated by the apropriate angle + * @return the same object rotated by the appropriate angle */ public Point2D rotatePoint(final Point2D point, final double angle, final Point2D center) { double s = Math.sin(angle); @@ -60,4 +60,15 @@ public class PointTransformation { return Double.isFinite(point.getX()) && Double.isFinite(point.getY()); } + /** + * Creates a copy of the point. + * + * @param point + * object to be copied + * @return copy of the object + */ + public Point2D copyPoint(Point2D point) { + return new Point2D.Double(point.getX(), point.getY()); + } + } diff --git a/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java b/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java index 1868f38ed3f4b3ad201de963e04297b147d85e3e..872d50bce88b05f5f9e1b570fa19a51824247176 100644 --- a/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java +++ b/commons/src/test/java/lcsb/mapviewer/common/geometry/PointTransformationTest.java @@ -1,6 +1,8 @@ package lcsb.mapviewer.common.geometry; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import java.awt.geom.Point2D; @@ -12,33 +14,42 @@ import lcsb.mapviewer.common.Configuration; public class PointTransformationTest { - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testRotate() { - PointTransformation pt = new PointTransformation(); - Point2D p1 = new Point2D.Double(1, 0); - Point2D p2 = new Point2D.Double(2, 0); - Point2D p3 = new Point2D.Double(3, 0); - Point2D res = pt.rotatePoint(p1, Math.PI, p2); - assertEquals(0.0, p3.distance(res), Configuration.EPSILON); - } - - @Test - public void testIsValid() { - PointTransformation pt = new PointTransformation(); - Point2D p1 = new Point2D.Double(1, 0); - Point2D p2 = new Point2D.Double(1, Double.NEGATIVE_INFINITY); - Point2D p3 = new Point2D.Double(Double.NEGATIVE_INFINITY, 2); - assertTrue(pt.isValidPoint(p1)); - assertFalse(pt.isValidPoint(p2)); - assertFalse(pt.isValidPoint(p3)); - } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testRotate() { + PointTransformation pt = new PointTransformation(); + Point2D p1 = new Point2D.Double(1, 0); + Point2D p2 = new Point2D.Double(2, 0); + Point2D p3 = new Point2D.Double(3, 0); + Point2D res = pt.rotatePoint(p1, Math.PI, p2); + assertEquals(0.0, p3.distance(res), Configuration.EPSILON); + } + + @Test + public void testIsValid() { + PointTransformation pt = new PointTransformation(); + Point2D p1 = new Point2D.Double(1, 0); + Point2D p2 = new Point2D.Double(1, Double.NEGATIVE_INFINITY); + Point2D p3 = new Point2D.Double(Double.NEGATIVE_INFINITY, 2); + assertTrue(pt.isValidPoint(p1)); + assertFalse(pt.isValidPoint(p2)); + assertFalse(pt.isValidPoint(p3)); + } + + @Test + public void testCopy() { + PointTransformation pt = new PointTransformation(); + Point2D p1 = new Point2D.Double(1, 0); + Point2D p2 = pt.copyPoint(p1); + assertFalse(p2 == p1); + assertEquals(0, p1.distance(p2), Configuration.EPSILON); + } }