Commit 8b367025 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

copyPoint method implemented

parent e50e751f
......@@ -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());
}
}
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);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment