mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 06:18:44 +00:00
Merged GeoUtility and GeometryUtils classes
#story[1047]
This commit is contained in:
@@ -27,7 +27,7 @@ import javafx.stage.Stage;
|
|||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
import javafx.util.Duration;
|
import javafx.util.Duration;
|
||||||
import javafx.util.StringConverter;
|
import javafx.util.StringConverter;
|
||||||
import seng302.utilities.GeometryUtils;
|
import seng302.utilities.GeoUtility;
|
||||||
import seng302.controllers.annotations.Annotation;
|
import seng302.controllers.annotations.Annotation;
|
||||||
import seng302.controllers.annotations.ImportantAnnotationController;
|
import seng302.controllers.annotations.ImportantAnnotationController;
|
||||||
import seng302.controllers.annotations.ImportantAnnotationDelegate;
|
import seng302.controllers.annotations.ImportantAnnotationDelegate;
|
||||||
@@ -444,7 +444,7 @@ public class RaceViewController extends Thread implements ImportantAnnotationDel
|
|||||||
|
|
||||||
Point2D boatCurrentPos = new Point2D(bg.getBoatLayoutX(), bg.getBoatLayoutY());
|
Point2D boatCurrentPos = new Point2D(bg.getBoatLayoutX(), bg.getBoatLayoutY());
|
||||||
Point2D gateMidPoint = markPoint1.midpoint(markPoint2);
|
Point2D gateMidPoint = markPoint1.midpoint(markPoint2);
|
||||||
Integer lineFuncResult = GeometryUtils.lineFunction(boatCurrentPos, gateMidPoint, markPoint2);
|
Integer lineFuncResult = GeoUtility.lineFunction(boatCurrentPos, gateMidPoint, markPoint2);
|
||||||
Line rightLayline = new Line();
|
Line rightLayline = new Line();
|
||||||
Line leftLayline = new Line();
|
Line leftLayline = new Line();
|
||||||
if (lineFuncResult == 1) {
|
if (lineFuncResult == 1) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import javafx.scene.shape.Line;
|
|||||||
import javafx.scene.shape.Polygon;
|
import javafx.scene.shape.Polygon;
|
||||||
import javafx.scene.transform.Rotate;
|
import javafx.scene.transform.Rotate;
|
||||||
import seng302.models.Yacht;
|
import seng302.models.Yacht;
|
||||||
import seng302.utilities.GeometryUtils;
|
import seng302.utilities.GeoUtility;
|
||||||
import seng302.controllers.CanvasController;
|
import seng302.controllers.CanvasController;
|
||||||
import seng302.models.mark.GateMark;
|
import seng302.models.mark.GateMark;
|
||||||
import seng302.models.mark.Mark;
|
import seng302.models.mark.Mark;
|
||||||
@@ -246,11 +246,11 @@ public class BoatGroup extends Group {
|
|||||||
Point2D nextMarkPoint2 = canvasController.findScaledXY(nextMark2.getLatitude(), nextMark2.getLongitude());
|
Point2D nextMarkPoint2 = canvasController.findScaledXY(nextMark2.getLatitude(), nextMark2.getLongitude());
|
||||||
|
|
||||||
Point2D boatCurrentPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
Point2D boatCurrentPoint = new Point2D(boatPoly.getLayoutX(), boatPoly.getLayoutY());
|
||||||
Point2D windTestPoint = GeometryUtils.makeArbitraryVectorPoint(nextMarkPoint1, windAngle, 10d);
|
Point2D windTestPoint = GeoUtility.makeArbitraryVectorPoint(nextMarkPoint1, windAngle, 10d);
|
||||||
|
|
||||||
|
|
||||||
Integer boatLineFuncResult = GeometryUtils.lineFunction(nextMarkPoint1, nextMarkPoint2, boatCurrentPoint);
|
Integer boatLineFuncResult = GeoUtility.lineFunction(nextMarkPoint1, nextMarkPoint2, boatCurrentPoint);
|
||||||
Integer windLineFuncResult = GeometryUtils.lineFunction(nextMarkPoint1, nextMarkPoint2, windTestPoint);
|
Integer windLineFuncResult = GeoUtility.lineFunction(nextMarkPoint1, nextMarkPoint2, windTestPoint);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.utilities;
|
package seng302.utilities;
|
||||||
|
|
||||||
|
import javafx.geometry.Point2D;
|
||||||
|
|
||||||
public class GeoUtility {
|
public class GeoUtility {
|
||||||
|
|
||||||
private static double EARTH_RADIUS = 6378.137;
|
private static double EARTH_RADIUS = 6378.137;
|
||||||
@@ -77,4 +79,55 @@ public class GeoUtility {
|
|||||||
|
|
||||||
return new GeoPoint(Math.toDegrees(endLat), Math.toDegrees(endLng));
|
return new GeoPoint(Math.toDegrees(endLat), Math.toDegrees(endLng));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Performs the line function on two points of a line and a test point to test which side of the line that point is
|
||||||
|
* on. If the return value is
|
||||||
|
* return 1, then the point is on one side of the line,
|
||||||
|
* return -1 then the point is on the other side of the line
|
||||||
|
* return 0 then the point is exactly on the line.
|
||||||
|
* @param linePoint1 One point of the line
|
||||||
|
* @param linePoint2 Second point of the line
|
||||||
|
* @param testPoint The point to test with this line
|
||||||
|
* @return A return value indicating which side of the line the point is on
|
||||||
|
*/
|
||||||
|
public static Integer lineFunction(Point2D linePoint1, Point2D linePoint2, Point2D testPoint) {
|
||||||
|
|
||||||
|
Double x = testPoint.getX();
|
||||||
|
Double y = testPoint.getY();
|
||||||
|
Double x1 = linePoint1.getX();
|
||||||
|
Double y1 = linePoint1.getY();
|
||||||
|
Double x2 = linePoint2.getX();
|
||||||
|
Double y2 = linePoint2.getY();
|
||||||
|
|
||||||
|
Double result = (x - x1)*(y2 - y1) - (y - y1)*(x2 - x1); //Line function
|
||||||
|
|
||||||
|
if (result > 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (result < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Given a point and a vector (angle and vector length) Will create a new point, that vector away from the origin
|
||||||
|
* point
|
||||||
|
* @param originPoint The point with which to use as the base for our vector addition
|
||||||
|
* @param angleInDeg (DEGREES) The angle at which our new point is being created (in degrees!)
|
||||||
|
* @param vectorLength The length out on this angle from the origin point to create the new point
|
||||||
|
* @return a Point2D
|
||||||
|
*/
|
||||||
|
public static Point2D makeArbitraryVectorPoint(Point2D originPoint, Double angleInDeg, Double vectorLength) {
|
||||||
|
|
||||||
|
Double endPointX = originPoint.getX() + vectorLength * Math.cos(Math.toRadians(angleInDeg));
|
||||||
|
Double endPointY = originPoint.getY() + vectorLength * Math.sin(Math.toRadians(angleInDeg));
|
||||||
|
|
||||||
|
return new Point2D(endPointX, endPointY);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,63 +0,0 @@
|
|||||||
package seng302.utilities;
|
|
||||||
|
|
||||||
import javafx.geometry.Point2D;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Class for performing geometric calculations on the canvas
|
|
||||||
* Created by wmu16 on 24/05/17.
|
|
||||||
*/
|
|
||||||
public final class GeometryUtils {
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Performs the line function on two points of a line and a test point to test which side of the line that point is
|
|
||||||
* on. If the return value is
|
|
||||||
* return 1, then the point is on one side of the line,
|
|
||||||
* return -1 then the point is on the other side of the line
|
|
||||||
* return 0 then the point is exactly on the line.
|
|
||||||
* @param linePoint1 One point of the line
|
|
||||||
* @param linePoint2 Second point of the line
|
|
||||||
* @param testPoint The point to test with this line
|
|
||||||
* @return A return value indicating which side of the line the point is on
|
|
||||||
*/
|
|
||||||
public static Integer lineFunction(Point2D linePoint1, Point2D linePoint2, Point2D testPoint) {
|
|
||||||
|
|
||||||
Double x = testPoint.getX();
|
|
||||||
Double y = testPoint.getY();
|
|
||||||
Double x1 = linePoint1.getX();
|
|
||||||
Double y1 = linePoint1.getY();
|
|
||||||
Double x2 = linePoint2.getX();
|
|
||||||
Double y2 = linePoint2.getY();
|
|
||||||
|
|
||||||
Double result = (x - x1)*(y2 - y1) - (y - y1)*(x2 - x1); //Line function
|
|
||||||
|
|
||||||
if (result > 0) {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
else if (result < 0) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Given a point and a vector (angle and vector length) Will create a new point, that vector away from the origin
|
|
||||||
* point
|
|
||||||
* @param originPoint The point with which to use as the base for our vector addition
|
|
||||||
* @param angleInDeg (DEGREES) The angle at which our new point is being created (in degrees!)
|
|
||||||
* @param vectorLength The length out on this angle from the origin point to create the new point
|
|
||||||
* @return a Point2D
|
|
||||||
*/
|
|
||||||
public static Point2D makeArbitraryVectorPoint(Point2D originPoint, Double angleInDeg, Double vectorLength) {
|
|
||||||
|
|
||||||
Double endPointX = originPoint.getX() + vectorLength * Math.cos(Math.toRadians(angleInDeg));
|
|
||||||
Double endPointY = originPoint.getY() + vectorLength * Math.sin(Math.toRadians(angleInDeg));
|
|
||||||
|
|
||||||
return new Point2D(endPointX, endPointY);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -3,7 +3,7 @@ package seng302;
|
|||||||
import javafx.geometry.Point2D;
|
import javafx.geometry.Point2D;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.utilities.GeometryUtils;
|
import seng302.utilities.GeoUtility;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
@@ -35,9 +35,9 @@ public class TestGeoUtils {
|
|||||||
@Test
|
@Test
|
||||||
public void testLineFunction() {
|
public void testLineFunction() {
|
||||||
|
|
||||||
Integer lineFunctionResult1 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint1);
|
Integer lineFunctionResult1 = GeoUtility.lineFunction(linePoint1, linePoint2, arbitraryPoint1);
|
||||||
Integer lineFunctionResult2 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint2);
|
Integer lineFunctionResult2 = GeoUtility.lineFunction(linePoint1, linePoint2, arbitraryPoint2);
|
||||||
Integer lineFunctionResult3 = GeometryUtils.lineFunction(linePoint1, linePoint2, arbitraryPoint3);
|
Integer lineFunctionResult3 = GeoUtility.lineFunction(linePoint1, linePoint2, arbitraryPoint3);
|
||||||
|
|
||||||
//Point1 and Point2 are on opposite sides
|
//Point1 and Point2 are on opposite sides
|
||||||
assertEquals(Math.abs(lineFunctionResult1), Math.abs(lineFunctionResult2));
|
assertEquals(Math.abs(lineFunctionResult1), Math.abs(lineFunctionResult2));
|
||||||
@@ -51,13 +51,13 @@ public class TestGeoUtils {
|
|||||||
public void testMakeArbitraryVectorPoint() {
|
public void testMakeArbitraryVectorPoint() {
|
||||||
|
|
||||||
//Make a point (1,0) from point (0,0)
|
//Make a point (1,0) from point (0,0)
|
||||||
Point2D newPoint = GeometryUtils.makeArbitraryVectorPoint(linePoint1, 0d, 1d);
|
Point2D newPoint = GeoUtility.makeArbitraryVectorPoint(linePoint1, 0d, 1d);
|
||||||
Point2D expected = new Point2D(1,0);
|
Point2D expected = new Point2D(1,0);
|
||||||
|
|
||||||
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
|
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
|
||||||
assertEquals(expected.getY(), newPoint.getY(), 1E-6);
|
assertEquals(expected.getY(), newPoint.getY(), 1E-6);
|
||||||
|
|
||||||
newPoint = GeometryUtils.makeArbitraryVectorPoint(linePoint1, 90d, 1d);
|
newPoint = GeoUtility.makeArbitraryVectorPoint(linePoint1, 90d, 1d);
|
||||||
expected = new Point2D(0, 1);
|
expected = new Point2D(0, 1);
|
||||||
|
|
||||||
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
|
assertEquals(expected.getX(), newPoint.getX(), 1E-6);
|
||||||
|
|||||||
Reference in New Issue
Block a user