diff --git a/src/main/java/com/treasure/hunt/jts/geom/GeometryAngle.java b/src/main/java/com/treasure/hunt/jts/geom/GeometryAngle.java index e5549e12..21e17f90 100644 --- a/src/main/java/com/treasure/hunt/jts/geom/GeometryAngle.java +++ b/src/main/java/com/treasure/hunt/jts/geom/GeometryAngle.java @@ -28,12 +28,12 @@ public class GeometryAngle extends LineString implements Shapeable { * GeometryAngle constructor via three {@link Coordinate}s. * * @param factory The GeometryFactory suggested to create the Angle - * @param right the right angles arm end point - * @param center the central point of the angle * @param left the left angles arm end point + * @param center the central point of the angle + * @param right the right angles arm end point */ - public GeometryAngle(GeometryFactory factory, Coordinate right, Coordinate center, Coordinate left) { - super(factory.getCoordinateSequenceFactory().create(new Coordinate[]{center, left, right}), factory); + public GeometryAngle(GeometryFactory factory, Coordinate left, Coordinate center, Coordinate right) { + super(factory.getCoordinateSequenceFactory().create(new Coordinate[]{left, center, right}), factory); } /** @@ -43,8 +43,8 @@ public GeometryAngle(GeometryFactory factory, Coordinate right, Coordinate cente * @param center the central point of the angle * @param left the left angles arm end point */ - public GeometryAngle(Coordinate right, Coordinate center, Coordinate left) { - this(JTSUtils.GEOMETRY_FACTORY, right, center, left); + public GeometryAngle(Coordinate left, Coordinate center, Coordinate right) { + this(JTSUtils.GEOMETRY_FACTORY, left, center, right); } /** @@ -58,9 +58,9 @@ public GeometryAngle(Coordinate right, Coordinate center, Coordinate left) { public GeometryAngle(GeometryFactory factory, Coordinate center, double start, double extend) { this( factory, - Vector2D.create(1, 0).rotate(start).translate(center), + Vector2D.create(1, 0).rotate(start + extend).translate(center), center, - Vector2D.create(1, 0).rotate(start + extend).translate(center) + Vector2D.create(1, 0).rotate(start).translate(center) ); } @@ -69,20 +69,20 @@ private void setCoordinate(int i, Coordinate c) { points.getCoordinate(i).setY(c.getY()); } - public Coordinate getCenter() { + public Coordinate getLeft() { return points.getCoordinate(0); } - public void setCenter(Coordinate center) { - setCoordinate(0, center); + public void setLeft(Coordinate left) { + setCoordinate(0, left); } - public Coordinate getLeft() { + public Coordinate getCenter() { return points.getCoordinate(1); } - public void setLeft(Coordinate left) { - setCoordinate(1, left); + public void setCenter(Coordinate center) { + setCoordinate(1, center); } public Coordinate getRight() { @@ -152,6 +152,6 @@ public boolean inView(Coordinate coordinate) { */ @Override public GeometryAngle copy() { - return new GeometryAngle(factory, getRight().copy(), getCenter().copy(), getLeft().copy()); + return new GeometryAngle(factory, getLeft().copy(), getCenter().copy(), getRight().copy()); } } diff --git a/src/main/java/com/treasure/hunt/strategy/hider/impl/MaxAreaAngularHintStrategy.java b/src/main/java/com/treasure/hunt/strategy/hider/impl/MaxAreaAngularHintStrategy.java index e5eba5a1..00c62b49 100644 --- a/src/main/java/com/treasure/hunt/strategy/hider/impl/MaxAreaAngularHintStrategy.java +++ b/src/main/java/com/treasure/hunt/strategy/hider/impl/MaxAreaAngularHintStrategy.java @@ -271,7 +271,7 @@ private AngleHint generateHint(int samples, Point origin) { Point right = gf.createPoint(new Coordinate(origin.getX() - (orth.x - origin.getX()), origin.getY() - (orth.y - origin.getY()))); Point left = gf.createPoint(orth); - AngleHint ooBHint = new AngleHint(right.getCoordinate(), origin.getCoordinate(), left.getCoordinate()); + AngleHint ooBHint = new AngleHint(left.getCoordinate(), origin.getCoordinate(), right.getCoordinate()); return ooBHint; } @@ -285,8 +285,8 @@ private AngleHint generateHint(int samples, Point origin) { double angle = twoPi * (i / samples); dX = Math.cos(angle); dY = Math.sin(angle); - p1 = gf.createPoint(new Coordinate(origin.getX() + dX, origin.getY() + dY)); - p2 = gf.createPoint(new Coordinate(origin.getX() - dX, origin.getY() - dY)); + p1 = gf.createPoint(new Coordinate(origin.getX() - dX, origin.getY() - dY)); + p2 = gf.createPoint(new Coordinate(origin.getX() + dX, origin.getY() + dY)); hint = new AngleHint(p1.getCoordinate(), origin.getCoordinate(), p2.getCoordinate()); diff --git a/src/main/java/com/treasure/hunt/strategy/hider/impl/UserControlledAngleHintHider.java b/src/main/java/com/treasure/hunt/strategy/hider/impl/UserControlledAngleHintHider.java index 250c2ed9..f2312b66 100644 --- a/src/main/java/com/treasure/hunt/strategy/hider/impl/UserControlledAngleHintHider.java +++ b/src/main/java/com/treasure/hunt/strategy/hider/impl/UserControlledAngleHintHider.java @@ -60,7 +60,7 @@ private AngleHint createAngleDialog(Coordinate middle) { Coordinate angleLeft = new Coordinate(x2, y2); Coordinate angleRight = new Coordinate(x, y); checkAngle(angleLeft, angleRight, middle); - return new AngleHint(angleRight, middle, angleLeft); + return new AngleHint(angleLeft, middle, angleRight); } catch (NumberFormatException e) { JOptionPane.showConfirmDialog(null, "Please enter valid numbers", "Error", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); } catch (WrongAngleException e) { diff --git a/src/main/java/com/treasure/hunt/strategy/hint/impl/AngleHint.java b/src/main/java/com/treasure/hunt/strategy/hint/impl/AngleHint.java index 35109f6d..aa9257f5 100644 --- a/src/main/java/com/treasure/hunt/strategy/hint/impl/AngleHint.java +++ b/src/main/java/com/treasure/hunt/strategy/hint/impl/AngleHint.java @@ -20,8 +20,8 @@ public class AngleHint extends Hint { GeometryAngle geometryAngle; - public AngleHint(Coordinate right, Coordinate center, Coordinate left) { - this(new GeometryAngle(JTSUtils.GEOMETRY_FACTORY, right, center, left)); + public AngleHint(Coordinate left, Coordinate center, Coordinate right) { + this(new GeometryAngle(JTSUtils.GEOMETRY_FACTORY, left, center, right)); } public AngleHint(GeometryAngle angle) { diff --git a/src/main/java/com/treasure/hunt/strategy/hint/impl/HalfPlaneHint.java b/src/main/java/com/treasure/hunt/strategy/hint/impl/HalfPlaneHint.java index dc9f6e47..67781fc6 100644 --- a/src/main/java/com/treasure/hunt/strategy/hint/impl/HalfPlaneHint.java +++ b/src/main/java/com/treasure/hunt/strategy/hint/impl/HalfPlaneHint.java @@ -26,7 +26,7 @@ public class HalfPlaneHint extends AngleHint { private Coordinate center; public HalfPlaneHint(Coordinate center, Coordinate halfPlanePoint, Direction direction) { - super(null, center, halfPlanePoint); + super(halfPlanePoint, center, null); this.direction = direction; this.center = center; this.halfPlanePoint = halfPlanePoint; diff --git a/src/main/java/com/treasure/hunt/utils/JTSUtils.java b/src/main/java/com/treasure/hunt/utils/JTSUtils.java index 07712fbb..aa2d6f09 100644 --- a/src/main/java/com/treasure/hunt/utils/JTSUtils.java +++ b/src/main/java/com/treasure/hunt/utils/JTSUtils.java @@ -78,8 +78,8 @@ public static Coordinate middleOfAngleHint(AngleHint angleHint) { * @param left closing line of the angle * @return {@link Coordinate} going through the middle of the angle */ - public static Coordinate middleOfAngleHint(Coordinate right, Coordinate center, Coordinate left) { - final GeometryAngle angle = new GeometryAngle(GEOMETRY_FACTORY, right, center, left); + public static Coordinate middleOfAngleHint(Coordinate left, Coordinate center, Coordinate right) { + final GeometryAngle angle = new GeometryAngle(GEOMETRY_FACTORY, left, center, right); return angle .rightVector() .rotate(angle.extend() / 2) @@ -169,8 +169,8 @@ public static boolean pointInAngle(GeometryAngle geometryAngle, Coordinate coord * @param coordinate the {@link Coordinate}, we want to know, whether it lies in the given angle. * @return {@code true}, if {@code coordinate} lies in the given angle. {@code false}, otherwise. */ - public static boolean pointInAngle(Coordinate right, Coordinate center, Coordinate left, Coordinate coordinate) { - final GeometryAngle geometryAngle = new GeometryAngle(GEOMETRY_FACTORY, right, center, left); + public static boolean pointInAngle(Coordinate left, Coordinate center, Coordinate right, Coordinate coordinate) { + final GeometryAngle geometryAngle = new GeometryAngle(GEOMETRY_FACTORY, left, center, right); GeometryAngle treasureGeometryAngle = geometryAngle.copy(); treasureGeometryAngle.setRight(coordinate); diff --git a/src/test/java/com/treasure/hunt/utils/JTSUtilsMiddleOfAngleHintTest.java b/src/test/java/com/treasure/hunt/utils/JTSUtilsMiddleOfAngleHintTest.java index 12205366..31c485a3 100644 --- a/src/test/java/com/treasure/hunt/utils/JTSUtilsMiddleOfAngleHintTest.java +++ b/src/test/java/com/treasure/hunt/utils/JTSUtilsMiddleOfAngleHintTest.java @@ -66,42 +66,42 @@ void shift() { */ @Test void test90Degrees1() { - eq(normNE, JTSUtils.middleOfAngleHint(E, C, N)); + eq(normNE, JTSUtils.middleOfAngleHint(N, C, E)); } @Test void test90Degrees2() { - eq(E, JTSUtils.middleOfAngleHint(SE, C, NE)); + eq(E, JTSUtils.middleOfAngleHint(NE, C, SE)); } @Test void test90Degrees3() { - eq(normSE, JTSUtils.middleOfAngleHint(S, C, E)); + eq(normSE, JTSUtils.middleOfAngleHint(E, C, S)); } @Test void test90Degrees4() { - eq(S, JTSUtils.middleOfAngleHint(SW, C, SE)); + eq(S, JTSUtils.middleOfAngleHint(SE, C, SW)); } @Test void test90Degrees5() { - eq(normSW, JTSUtils.middleOfAngleHint(W, C, S)); + eq(normSW, JTSUtils.middleOfAngleHint(S, C, W)); } @Test void test90Degrees6() { - eq(W, JTSUtils.middleOfAngleHint(NW, C, SW)); + eq(W, JTSUtils.middleOfAngleHint(SW, C, NW)); } @Test void test90Degrees7() { - eq(normNW, JTSUtils.middleOfAngleHint(N, C, W)); + eq(normNW, JTSUtils.middleOfAngleHint(W, C, N)); } @Test void test90Degrees8() { - eq(N, JTSUtils.middleOfAngleHint(NE, C, NW)); + eq(N, JTSUtils.middleOfAngleHint(NW, C, NE)); } /** @@ -111,50 +111,50 @@ void test90Degrees8() { */ @Test void test180Degrees1() { - eq(N, JTSUtils.middleOfAngleHint(E, C, W)); - neq(S, JTSUtils.middleOfAngleHint(E, C, W)); + eq(N, JTSUtils.middleOfAngleHint(W, C, E)); + neq(S, JTSUtils.middleOfAngleHint(W, C, E)); } @Test void test180Degrees2() { - eq(normNE, JTSUtils.middleOfAngleHint(SE, C, NW)); - neq(normSW, JTSUtils.middleOfAngleHint(SE, C, NW)); + eq(normNE, JTSUtils.middleOfAngleHint(NW, C, SE)); + neq(normSW, JTSUtils.middleOfAngleHint(NW, C, SE)); } @Test void test180Degrees3() { - eq(E, JTSUtils.middleOfAngleHint(S, C, N)); - neq(W, JTSUtils.middleOfAngleHint(S, C, N)); + eq(E, JTSUtils.middleOfAngleHint(N, C, S)); + neq(W, JTSUtils.middleOfAngleHint(N, C, S)); } @Test void test180Degrees4() { - eq(normSE, JTSUtils.middleOfAngleHint(SW, C, NE)); - neq(normNW, JTSUtils.middleOfAngleHint(SW, C, NE)); + eq(normSE, JTSUtils.middleOfAngleHint(NE, C, SW)); + neq(normNW, JTSUtils.middleOfAngleHint(NE, C, SW)); } @Test void test180Degrees5() { - eq(S, JTSUtils.middleOfAngleHint(W, C, E)); - neq(N, JTSUtils.middleOfAngleHint(W, C, E)); + eq(S, JTSUtils.middleOfAngleHint(E, C, W)); + neq(N, JTSUtils.middleOfAngleHint(E, C, W)); } @Test void test180Degrees6() { - eq(normSW, JTSUtils.middleOfAngleHint(NW, C, SE)); - neq(normNE, JTSUtils.middleOfAngleHint(NW, C, SE)); + eq(normSW, JTSUtils.middleOfAngleHint(SE, C, NW)); + neq(normNE, JTSUtils.middleOfAngleHint(SE, C, NW)); } @Test void test180Degrees7() { - eq(W, JTSUtils.middleOfAngleHint(N, C, S)); - neq(E, JTSUtils.middleOfAngleHint(N, C, S)); + eq(W, JTSUtils.middleOfAngleHint(S, C, N)); + neq(E, JTSUtils.middleOfAngleHint(S, C, N)); } @Test void test180Degrees8() { - eq(normNW, JTSUtils.middleOfAngleHint(NE, C, SW)); - neq(normSE, JTSUtils.middleOfAngleHint(NE, C, SW)); + eq(normNW, JTSUtils.middleOfAngleHint(SW, C, NE)); + neq(normSE, JTSUtils.middleOfAngleHint(SW, C, NE)); } /** @@ -164,41 +164,41 @@ void test180Degrees8() { */ @Test void test270Degrees1() { - eq(normSW, JTSUtils.middleOfAngleHint(N, C, E)); + eq(normSW, JTSUtils.middleOfAngleHint(E, C, N)); } @Test void test270Degrees2() { - eq(W, JTSUtils.middleOfAngleHint(NE, C, SE)); + eq(W, JTSUtils.middleOfAngleHint(SE, C, NE)); } @Test void test270Degrees3() { - eq(normNW, JTSUtils.middleOfAngleHint(E, C, S)); + eq(normNW, JTSUtils.middleOfAngleHint(S, C, E)); } @Test void test270Degrees4() { - eq(N, JTSUtils.middleOfAngleHint(SE, C, SW)); + eq(N, JTSUtils.middleOfAngleHint(SW, C, SE)); } @Test void test270Degrees5() { - eq(normNE, JTSUtils.middleOfAngleHint(S, C, W)); + eq(normNE, JTSUtils.middleOfAngleHint(W, C, S)); } @Test void test270Degrees6() { - eq(E, JTSUtils.middleOfAngleHint(SW, C, NW)); + eq(E, JTSUtils.middleOfAngleHint(NW, C, SW)); } @Test void test270Degrees7() { - eq(normSE, JTSUtils.middleOfAngleHint(W, C, N)); + eq(normSE, JTSUtils.middleOfAngleHint(N, C, W)); } @Test void test270Degrees8() { - eq(S, JTSUtils.middleOfAngleHint(NW, C, NE)); + eq(S, JTSUtils.middleOfAngleHint(NE, C, NW)); } } diff --git a/src/test/java/com/treasure/hunt/utils/JTSUtilsPointInAngleTest.java b/src/test/java/com/treasure/hunt/utils/JTSUtilsPointInAngleTest.java index 204eff0c..e5d16160 100644 --- a/src/test/java/com/treasure/hunt/utils/JTSUtilsPointInAngleTest.java +++ b/src/test/java/com/treasure/hunt/utils/JTSUtilsPointInAngleTest.java @@ -60,27 +60,27 @@ void pointInAngle3() { private boolean inUpperRightQuadrant(Coordinate coordinate) { return JTSUtils.pointInAngle( - new Coordinate(1, 0), - new Coordinate(0, 0), new Coordinate(0, 1), + new Coordinate(0, 0), + new Coordinate(1, 0), coordinate ); } private boolean inUpperHalfPlane(Coordinate coordinate) { return JTSUtils.pointInAngle( - new Coordinate(1, 0), - new Coordinate(0, 0), new Coordinate(-1, 0), + new Coordinate(0, 0), + new Coordinate(1, 0), coordinate ); } private boolean inLowerHalfPlane(Coordinate coordinate) { return JTSUtils.pointInAngle( - new Coordinate(-1, 0), - new Coordinate(0, 0), new Coordinate(1, 0), + new Coordinate(0, 0), + new Coordinate(-1, 0), coordinate ); } diff --git a/src/test/java/com/treasure/hunt/utils/JTSUtilsTest.java b/src/test/java/com/treasure/hunt/utils/JTSUtilsTest.java index f0299a67..4c427062 100644 --- a/src/test/java/com/treasure/hunt/utils/JTSUtilsTest.java +++ b/src/test/java/com/treasure/hunt/utils/JTSUtilsTest.java @@ -58,134 +58,134 @@ void shift() { @Test void test90Degrees1() { - eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(E, C, N))); + eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(N, C, E))); } @Test void test90Degrees2() { - eq(E, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NE))); + eq(E, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SE))); } @Test void test90Degrees3() { - eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(S, C, E))); + eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(E, C, S))); } @Test void test90Degrees4() { - eq(S, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, SE))); + eq(S, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, SW))); } @Test void test90Degrees5() { - eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(W, C, S))); + eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(S, C, W))); } @Test void test90Degrees6() { - eq(W, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SW))); + eq(W, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NW))); } @Test void test90Degrees7() { - eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(N, C, W))); + eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(W, C, N))); } @Test void test90Degrees8() { - eq(N, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, NW))); + eq(N, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, NE))); } @Test void test180Degrees1() { - eq(N, JTSUtils.middleOfAngleHint(createAngleHint(E, C, W))); - neq(S, JTSUtils.middleOfAngleHint(createAngleHint(E, C, W))); + eq(N, JTSUtils.middleOfAngleHint(createAngleHint(W, C, E))); + neq(S, JTSUtils.middleOfAngleHint(createAngleHint(W, C, E))); } @Test void test180Degrees2() { - eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NW))); - neq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NW))); + eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SE))); + neq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SE))); } @Test void test180Degrees3() { - eq(E, JTSUtils.middleOfAngleHint(createAngleHint(S, C, N))); - neq(W, JTSUtils.middleOfAngleHint(createAngleHint(S, C, N))); + eq(E, JTSUtils.middleOfAngleHint(createAngleHint(N, C, S))); + neq(W, JTSUtils.middleOfAngleHint(createAngleHint(N, C, S))); } @Test void test180Degrees4() { - eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NE))); - neq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NE))); + eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SW))); + neq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SW))); } @Test void test180Degrees5() { - eq(S, JTSUtils.middleOfAngleHint(createAngleHint(W, C, E))); - neq(N, JTSUtils.middleOfAngleHint(createAngleHint(W, C, E))); + eq(S, JTSUtils.middleOfAngleHint(createAngleHint(E, C, W))); + neq(N, JTSUtils.middleOfAngleHint(createAngleHint(E, C, W))); } @Test void test180Degrees6() { - eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SE))); - neq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SE))); + eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NW))); + neq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NW))); } @Test void test180Degrees7() { - eq(W, JTSUtils.middleOfAngleHint(createAngleHint(N, C, S))); - neq(E, JTSUtils.middleOfAngleHint(createAngleHint(N, C, S))); + eq(W, JTSUtils.middleOfAngleHint(createAngleHint(S, C, N))); + neq(E, JTSUtils.middleOfAngleHint(createAngleHint(S, C, N))); } @Test void test180Degrees8() { - eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SW))); - neq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SW))); + eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NE))); + neq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NE))); } @Test void test270Degrees1() { - eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(N, C, E))); + eq(normSW, JTSUtils.middleOfAngleHint(createAngleHint(E, C, N))); } @Test void test270Degrees2() { - eq(W, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, SE))); + eq(W, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, NE))); } @Test void test270Degrees3() { - eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(E, C, S))); + eq(normNW, JTSUtils.middleOfAngleHint(createAngleHint(S, C, E))); } @Test void test270Degrees4() { - eq(N, JTSUtils.middleOfAngleHint(createAngleHint(SE, C, SW))); + eq(N, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, SE))); } @Test void test270Degrees5() { - eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(S, C, W))); + eq(normNE, JTSUtils.middleOfAngleHint(createAngleHint(W, C, S))); } @Test void test270Degrees6() { - eq(E, JTSUtils.middleOfAngleHint(createAngleHint(SW, C, NW))); + eq(E, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, SW))); } @Test void test270Degrees7() { - eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(W, C, N))); + eq(normSE, JTSUtils.middleOfAngleHint(createAngleHint(N, C, W))); } @Test void test270Degrees8() { - eq(S, JTSUtils.middleOfAngleHint(createAngleHint(NW, C, NE))); + eq(S, JTSUtils.middleOfAngleHint(createAngleHint(NE, C, NW))); } - private AngleHint createAngleHint(Coordinate c1, Coordinate c2, Coordinate c3) { - return new AngleHint(c1, c2, c3); + private AngleHint createAngleHint(Coordinate left, Coordinate center, Coordinate right) { + return new AngleHint(left, center, right); } private void eq(Coordinate expected, Coordinate actual) {