Merged with visualiser side of mark boats
#story[881]
This commit is contained in:
@@ -2,8 +2,8 @@ package seng302.Mock;
|
|||||||
|
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.Boat;
|
import seng302.Model.Boat;
|
||||||
import seng302.Model.CompoundMark;
|
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
|
import seng302.Model.Marker;
|
||||||
import seng302.RaceDataSource;
|
import seng302.RaceDataSource;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
@@ -75,7 +75,7 @@ public class StreamedCourse extends Observable implements RaceDataSource {
|
|||||||
return streamedCourseXMLReader.getLegs();
|
return streamedCourseXMLReader.getLegs();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CompoundMark> getMarkers() { return streamedCourseXMLReader.getCompoundMarks(); }
|
public List<Marker> getMarkers() { return streamedCourseXMLReader.getMarkers(); }
|
||||||
|
|
||||||
public List<GPSCoordinate> getBoundary() {
|
public List<GPSCoordinate> getBoundary() {
|
||||||
return streamedCourseXMLReader.getBoundary();
|
return streamedCourseXMLReader.getBoundary();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import seng302.Controllers.RaceController;
|
|||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.Boat;
|
import seng302.Model.Boat;
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
import seng302.Model.CompoundMark;
|
import seng302.Model.Marker;
|
||||||
import seng302.Model.Race;
|
import seng302.Model.Race;
|
||||||
import seng302.Networking.Messages.BoatLocation;
|
import seng302.Networking.Messages.BoatLocation;
|
||||||
import seng302.Networking.Messages.BoatStatus;
|
import seng302.Networking.Messages.BoatStatus;
|
||||||
@@ -25,12 +25,12 @@ public class StreamedRace extends Race {
|
|||||||
public void initialiseBoats() {
|
public void initialiseBoats() {
|
||||||
Leg officialStart = legs.get(0);
|
Leg officialStart = legs.get(0);
|
||||||
String name = officialStart.getName();
|
String name = officialStart.getName();
|
||||||
CompoundMark endCompoundMark = officialStart.getEndCompoundMark();
|
Marker endCompoundMark = officialStart.getEndMarker();
|
||||||
|
|
||||||
for (Boat boat : startingBoats) {
|
for (Boat boat : startingBoats) {
|
||||||
if (boat != null) {
|
if (boat != null) {
|
||||||
Leg startLeg = new Leg(name, 0);
|
Leg startLeg = new Leg(name, 0);
|
||||||
startLeg.setEndCompoundMark(endCompoundMark);
|
startLeg.setEndMarker(endCompoundMark);
|
||||||
boat.setCurrentLeg(startLeg);
|
boat.setCurrentLeg(startLeg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ public class BoatInRace extends Boat {
|
|||||||
public double calculateAzimuth() {
|
public double calculateAzimuth() {
|
||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
GPSCoordinate start = currentLeg.getStartCompoundMark().getAverageGPSCoordinate();
|
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
||||||
GPSCoordinate end = currentLeg.getEndCompoundMark().getAverageGPSCoordinate();
|
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
||||||
|
|
||||||
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
||||||
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import seng302.GPSCoordinate;
|
|||||||
public class Leg {
|
public class Leg {
|
||||||
private final String name; //nautical miles
|
private final String name; //nautical miles
|
||||||
private double distance;
|
private double distance;
|
||||||
private CompoundMark startCompoundMark;
|
private Marker startMarker;
|
||||||
private CompoundMark endCompoundMark;
|
private Marker endMarker;
|
||||||
private final int legNumber;
|
private final int legNumber;
|
||||||
// 1 nautical mile = 1852 meters
|
// 1 nautical mile = 1852 meters
|
||||||
public static final int NM_TO_METERS = 1852;
|
public static final int NM_TO_METERS = 1852;
|
||||||
@@ -23,10 +23,10 @@ public class Leg {
|
|||||||
* @param end marker
|
* @param end marker
|
||||||
* @param number Leg's position in race
|
* @param number Leg's position in race
|
||||||
*/
|
*/
|
||||||
public Leg(String name, CompoundMark start, CompoundMark end, int number) {
|
public Leg(String name, Marker start, Marker end, int number) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.startCompoundMark = start;
|
this.startMarker = start;
|
||||||
this.endCompoundMark = end;
|
this.endMarker = end;
|
||||||
this.legNumber = number;
|
this.legNumber = number;
|
||||||
calculateDistance();
|
calculateDistance();
|
||||||
}
|
}
|
||||||
@@ -71,20 +71,20 @@ public class Leg {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CompoundMark getStartCompoundMark() {
|
public Marker getStartMarker() {
|
||||||
return startCompoundMark;
|
return startMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setStartCompoundMark(CompoundMark startCompoundMark) {
|
public void setStartMarker(Marker startMarker) {
|
||||||
this.startCompoundMark = startCompoundMark;
|
this.startMarker = startMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompoundMark getEndCompoundMark() {
|
public Marker getEndMarker() {
|
||||||
return endCompoundMark;
|
return endMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setEndCompoundMark(CompoundMark endCompoundMark) {
|
public void setEndMarker(Marker endMarker) {
|
||||||
this.endCompoundMark = endCompoundMark;
|
this.endMarker = endMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -94,8 +94,8 @@ public class Leg {
|
|||||||
|
|
||||||
GeodeticCalculator calc = new GeodeticCalculator();
|
GeodeticCalculator calc = new GeodeticCalculator();
|
||||||
//Load start and end of leg
|
//Load start and end of leg
|
||||||
GPSCoordinate startMarker = this.startCompoundMark.getAverageGPSCoordinate();
|
GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate();
|
||||||
GPSCoordinate endMarker = this.endCompoundMark.getAverageGPSCoordinate();
|
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
|
||||||
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
||||||
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
||||||
this.distance = calc.getOrthodromicDistance() / NM_TO_METERS;
|
this.distance = calc.getOrthodromicDistance() / NM_TO_METERS;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package seng302;
|
package seng302;
|
||||||
|
|
||||||
import seng302.Model.Boat;
|
import seng302.Model.Boat;
|
||||||
import seng302.Model.CompoundMark;
|
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
|
import seng302.Model.Marker;
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -13,7 +13,7 @@ import java.util.List;
|
|||||||
public interface RaceDataSource {
|
public interface RaceDataSource {
|
||||||
List<Boat> getBoats();
|
List<Boat> getBoats();
|
||||||
List<Leg> getLegs();
|
List<Leg> getLegs();
|
||||||
List<CompoundMark> getMarkers();
|
List<Marker> getMarkers();
|
||||||
List<GPSCoordinate> getBoundary();
|
List<GPSCoordinate> getBoundary();
|
||||||
|
|
||||||
ZonedDateTime getZonedDateTime();
|
ZonedDateTime getZonedDateTime();
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
for (int i = 0; i < nLegs.getLength(); i++) {
|
for (int i = 0; i < nLegs.getLength(); i++) {
|
||||||
String label = getTextValueOfNode((Element) nLegs.item(i), "name");
|
String label = getTextValueOfNode((Element) nLegs.item(i), "name");
|
||||||
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
|
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
|
||||||
CompoundMark startCompoundMark = getMarker(start);
|
Marker startMarker = getMarker(start);
|
||||||
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
|
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
|
||||||
CompoundMark finishCompoundMark = getMarker(finish);
|
Marker finishMarker = getMarker(finish);
|
||||||
legs.add(new Leg(label, startCompoundMark, finishCompoundMark, i));
|
legs.add(new Leg(label, startMarker, finishMarker, i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
|
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CompoundMark getMarker(NodeList start) {
|
private Marker getMarker(NodeList start) {
|
||||||
return getMarker(start, 0);
|
return getMarker(start, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
* @param startIndex index in the node that has the coordinate tag
|
* @param startIndex index in the node that has the coordinate tag
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CompoundMark getMarker(NodeList start, int startIndex) {
|
private Marker getMarker(NodeList start, int startIndex) {
|
||||||
return getMarker(start, startIndex, 0);
|
return getMarker(start, startIndex, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
* @param nodeIndex coordinate index
|
* @param nodeIndex coordinate index
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CompoundMark getMarker(NodeList start, int startIndex, int nodeIndex) {
|
private Marker getMarker(NodeList start, int startIndex, int nodeIndex) {
|
||||||
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
|
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
|
||||||
Element marker = (Element) nodeList.item(nodeIndex);
|
Element marker = (Element) nodeList.item(nodeIndex);
|
||||||
return getMarker(marker);
|
return getMarker(marker);
|
||||||
@@ -204,7 +204,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
* @param markerNode marker to turn into coordinates
|
* @param markerNode marker to turn into coordinates
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private CompoundMark getMarker(Element markerNode) {
|
private Marker getMarker(Element markerNode) {
|
||||||
|
|
||||||
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
|
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
|
||||||
|
|
||||||
@@ -215,7 +215,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
} else {
|
} else {
|
||||||
side2 = side1;
|
side2 = side1;
|
||||||
}
|
}
|
||||||
return new CompoundMark(side1, side2);
|
return new Marker(side1, side2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CompoundMark> getMarkers() {
|
public List<Marker> getMarkers() {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import org.junit.Ignore;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.GPSCoordinate;
|
import seng302.GPSCoordinate;
|
||||||
import seng302.Model.Leg;
|
import seng302.Model.Leg;
|
||||||
import seng302.Model.CompoundMark;
|
import seng302.Model.Marker;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@ public class StreamedRaceTest {
|
|||||||
GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft();
|
GPSCoordinate topLeft = streamedCourseXMLReader.getMapTopLeft();
|
||||||
GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight();
|
GPSCoordinate bottomRight = streamedCourseXMLReader.getMapBottomRight();
|
||||||
|
|
||||||
for(CompoundMark compoundMark : streamedCourseXMLReader.getCompoundMarks()) {
|
for(Marker compoundMark : streamedCourseXMLReader.getMarkers()) {
|
||||||
GPSCoordinate centre = compoundMark.getAverageGPSCoordinate();
|
GPSCoordinate centre = compoundMark.getAverageGPSCoordinate();
|
||||||
assertTrue(centre.getLatitude() < bottomRight.getLatitude());
|
assertTrue(centre.getLatitude() < bottomRight.getLatitude());
|
||||||
assertTrue(centre.getLatitude() > topLeft.getLatitude());
|
assertTrue(centre.getLatitude() > topLeft.getLatitude());
|
||||||
|
|||||||
@@ -19,18 +19,18 @@ public class BoatInRaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void calculateDueNorthAzimuthReturns0() {
|
public void calculateDueNorthAzimuthReturns0() {
|
||||||
|
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 0, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueSouthAzimuthReturns180() {
|
public void calculateDueSouthAzimuthReturns180() {
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(-50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 180, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -39,9 +39,9 @@ public class BoatInRaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void calculateDueEastAzimuthReturns90() {
|
public void calculateDueEastAzimuthReturns90() {
|
||||||
|
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(0, 50));
|
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), 90, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -49,9 +49,9 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueWestAzimuthReturnsNegative90() {
|
public void calculateDueWestAzimuthReturnsNegative90() {
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(0, -50));
|
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
assertEquals(TEST_BOAT.calculateAzimuth(), -90, 1e-8);
|
||||||
|
|
||||||
@@ -60,9 +60,9 @@ public class BoatInRaceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void calculateDueNorthHeadingReturns0() {
|
public void calculateDueNorthHeadingReturns0() {
|
||||||
|
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 0, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -70,27 +70,27 @@ public class BoatInRaceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueEastHeadingReturns90() {
|
public void calculateDueEastHeadingReturns90() {
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(0, 50));
|
Marker endMarker = new Marker(new GPSCoordinate(0, 50));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 90, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueSouthHeadingReturns180() {
|
public void calculateDueSouthHeadingReturns180() {
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(-50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(-50, 0));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 180, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDueWestHeadingReturns270() {
|
public void calculateDueWestHeadingReturns270() {
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(0, -50));
|
Marker endMarker = new Marker(new GPSCoordinate(0, -50));
|
||||||
Leg start = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg start = new Leg("Start", startMarker, endMarker, 0);
|
||||||
TEST_BOAT.setCurrentLeg(start);
|
TEST_BOAT.setCurrentLeg(start);
|
||||||
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
assertEquals(TEST_BOAT.calculateHeading(), 270, 1e-8);
|
||||||
}
|
}
|
||||||
@@ -117,16 +117,16 @@ public class BoatInRaceTest {
|
|||||||
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
BoatInRace boat = new BoatInRace("Test", 1, Color.ALICEBLUE, "tt");
|
||||||
|
|
||||||
// Construct leg of 0 degrees
|
// Construct leg of 0 degrees
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
Leg leg0deg = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentLeg(leg0deg);
|
boat.setCurrentLeg(leg0deg);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
assertEquals(0, boat.calculateHeading(), 1e-8);
|
assertEquals(0, boat.calculateHeading(), 1e-8);
|
||||||
|
|
||||||
// Construct leg from wake - heading should be 180 degrees
|
// Construct leg from wake - heading should be 180 degrees
|
||||||
Leg leg180deg = new Leg("Start", startCompoundMark, new CompoundMark(boat.getWake()), 0);
|
Leg leg180deg = new Leg("Start", startMarker, new Marker(boat.getWake()), 0);
|
||||||
boat.setCurrentLeg(leg180deg);
|
boat.setCurrentLeg(leg180deg);
|
||||||
|
|
||||||
assertEquals(180, boat.calculateHeading(), 1e-8);
|
assertEquals(180, boat.calculateHeading(), 1e-8);
|
||||||
@@ -138,9 +138,9 @@ public class BoatInRaceTest {
|
|||||||
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
BoatInRace boat = new BoatInRace("Test", 10, Color.ALICEBLUE, "tt");
|
||||||
|
|
||||||
// Construct leg of 0 degrees at 0 N
|
// Construct leg of 0 degrees at 0 N
|
||||||
CompoundMark startCompoundMark = new CompoundMark(ORIGIN_COORDS);
|
Marker startMarker = new Marker(ORIGIN_COORDS);
|
||||||
CompoundMark endCompoundMark = new CompoundMark(new GPSCoordinate(50, 0));
|
Marker endMarker = new Marker(new GPSCoordinate(50, 0));
|
||||||
Leg leg0deg = new Leg("Start", startCompoundMark, endCompoundMark, 0);
|
Leg leg0deg = new Leg("Start", startMarker, endMarker, 0);
|
||||||
boat.setCurrentLeg(leg0deg);
|
boat.setCurrentLeg(leg0deg);
|
||||||
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
boat.setCurrentPosition(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import static seng302.Model.Leg.NM_TO_METERS;
|
|||||||
*/
|
*/
|
||||||
public class LegTest {
|
public class LegTest {
|
||||||
|
|
||||||
private final CompoundMark ORIGIN_CompoundMark = new CompoundMark(new GPSCoordinate(0, 0));
|
private final Marker ORIGIN_Marker = new Marker(new GPSCoordinate(0, 0));
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDistanceHandles5nmNorth() {
|
public void calculateDistanceHandles5nmNorth() {
|
||||||
@@ -22,8 +22,8 @@ public class LegTest {
|
|||||||
calc.setStartingGeographicPoint(0, 0);
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
calc.setDirection(0, 5 * NM_TO_METERS);
|
calc.setDirection(0, 5 * NM_TO_METERS);
|
||||||
|
|
||||||
CompoundMark endCompoundMark = getEndMarker(calc.getDestinationGeographicPoint());
|
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||||
Leg test = new Leg("Test", ORIGIN_CompoundMark, endCompoundMark, 0);
|
Leg test = new Leg("Test", ORIGIN_Marker, endMarker, 0);
|
||||||
assertEquals(test.getDistance(), 5, 1e-8);
|
assertEquals(test.getDistance(), 5, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,8 +33,8 @@ public class LegTest {
|
|||||||
calc.setStartingGeographicPoint(0, 0);
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
calc.setDirection(90, 12 * NM_TO_METERS);
|
calc.setDirection(90, 12 * NM_TO_METERS);
|
||||||
|
|
||||||
CompoundMark endCompoundMark = getEndMarker(calc.getDestinationGeographicPoint());
|
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||||
Leg test = new Leg("Test", ORIGIN_CompoundMark, endCompoundMark, 0);
|
Leg test = new Leg("Test", ORIGIN_Marker, endMarker, 0);
|
||||||
assertEquals(test.getDistance(), 12, 1e-8);
|
assertEquals(test.getDistance(), 12, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,8 +44,8 @@ public class LegTest {
|
|||||||
calc.setStartingGeographicPoint(0, 0);
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
calc.setDirection(180, 0.5 * NM_TO_METERS);
|
calc.setDirection(180, 0.5 * NM_TO_METERS);
|
||||||
|
|
||||||
CompoundMark endCompoundMark = getEndMarker(calc.getDestinationGeographicPoint());
|
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||||
Leg test = new Leg("Test", ORIGIN_CompoundMark, endCompoundMark, 0);
|
Leg test = new Leg("Test", ORIGIN_Marker, endMarker, 0);
|
||||||
assertEquals(test.getDistance(), 0.5, 1e-8);
|
assertEquals(test.getDistance(), 0.5, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,23 +55,23 @@ public class LegTest {
|
|||||||
calc.setStartingGeographicPoint(0, 0);
|
calc.setStartingGeographicPoint(0, 0);
|
||||||
calc.setDirection(-90, 0.1 * NM_TO_METERS);
|
calc.setDirection(-90, 0.1 * NM_TO_METERS);
|
||||||
|
|
||||||
CompoundMark endCompoundMark = getEndMarker(calc.getDestinationGeographicPoint());
|
Marker endMarker = getEndMarker(calc.getDestinationGeographicPoint());
|
||||||
Leg test = new Leg("Test", ORIGIN_CompoundMark, endCompoundMark, 0);
|
Leg test = new Leg("Test", ORIGIN_Marker, endMarker, 0);
|
||||||
assertEquals(test.getDistance(), 0.1, 1e-8);
|
assertEquals(test.getDistance(), 0.1, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void calculateDistanceHandlesZeroDifference() {
|
public void calculateDistanceHandlesZeroDifference() {
|
||||||
|
|
||||||
Leg test = new Leg("Test", ORIGIN_CompoundMark, ORIGIN_CompoundMark, 0);
|
Leg test = new Leg("Test", ORIGIN_Marker, ORIGIN_Marker, 0);
|
||||||
assertEquals(test.getDistance(), 0, 1e-8);
|
assertEquals(test.getDistance(), 0, 1e-8);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompoundMark getEndMarker(Point2D point) {
|
private Marker getEndMarker(Point2D point) {
|
||||||
|
|
||||||
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
|
GPSCoordinate coords = new GPSCoordinate(point.getY(), point.getX());
|
||||||
|
|
||||||
return new CompoundMark(coords);
|
return new Marker(coords);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -8,14 +8,14 @@ import static org.junit.Assert.assertTrue;
|
|||||||
/**
|
/**
|
||||||
* Created by esa46 on 29/03/17.
|
* Created by esa46 on 29/03/17.
|
||||||
*/
|
*/
|
||||||
public class CompoundMarkTest {
|
public class MarkerTest {
|
||||||
|
|
||||||
private final GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
|
private final GPSCoordinate ORIGIN_COORD = new GPSCoordinate(0, 0);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void averageOfSingleMarkAtOriginIsSingleMark() {
|
public void averageOfSingleMarkAtOriginIsSingleMark() {
|
||||||
|
|
||||||
CompoundMark testMark = new CompoundMark(ORIGIN_COORD);
|
Marker testMark = new Marker(ORIGIN_COORD);
|
||||||
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
|
assertTrue(testMark.getAverageGPSCoordinate().equals(ORIGIN_COORD));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ public class CompoundMarkTest {
|
|||||||
public void averageOfSingleMarkIsSingleMark() {
|
public void averageOfSingleMarkIsSingleMark() {
|
||||||
|
|
||||||
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
|
GPSCoordinate testCoord = new GPSCoordinate(20, 25);
|
||||||
CompoundMark testMark = new CompoundMark(testCoord);
|
Marker testMark = new Marker(testCoord);
|
||||||
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
|
assertTrue(testMark.getAverageGPSCoordinate().equals(testCoord));
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ public class CompoundMarkTest {
|
|||||||
public void averageLatOfTwoMarksIsAccurate() {
|
public void averageLatOfTwoMarksIsAccurate() {
|
||||||
|
|
||||||
GPSCoordinate testCoord = new GPSCoordinate(10, 0);
|
GPSCoordinate testCoord = new GPSCoordinate(10, 0);
|
||||||
CompoundMark testMark = new CompoundMark(ORIGIN_COORD, testCoord);
|
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
|
||||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0)));
|
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(5, 0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class CompoundMarkTest {
|
|||||||
public void averageLongOfTwoMarksIsAccurate() {
|
public void averageLongOfTwoMarksIsAccurate() {
|
||||||
|
|
||||||
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
|
GPSCoordinate testCoord = new GPSCoordinate(0, 10);
|
||||||
CompoundMark testMark = new CompoundMark(ORIGIN_COORD, testCoord);
|
Marker testMark = new Marker(ORIGIN_COORD, testCoord);
|
||||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
|
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(0, 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class CompoundMarkTest {
|
|||||||
|
|
||||||
GPSCoordinate testCoord1 = new GPSCoordinate(10, 30);
|
GPSCoordinate testCoord1 = new GPSCoordinate(10, 30);
|
||||||
GPSCoordinate testCoord2 = new GPSCoordinate(30, 60);
|
GPSCoordinate testCoord2 = new GPSCoordinate(30, 60);
|
||||||
CompoundMark testMark = new CompoundMark(testCoord1, testCoord2);
|
Marker testMark = new Marker(testCoord1, testCoord2);
|
||||||
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817)));
|
assertTrue(testMark.getAverageGPSCoordinate().equals(new GPSCoordinate(020.644102, 44.014817)));
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user