Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bring geometry angle in correct order (left, center, right) #153

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/main/java/com/treasure/hunt/jts/geom/GeometryAngle.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>Angle</code>
* @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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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)
);
}

Expand All @@ -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() {
Expand Down Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Expand All @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/treasure/hunt/utils/JTSUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand All @@ -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));
}

/**
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
Expand Down
Loading