mirror of
https://github.com/michaelrausch/Party-Parrots-At-Sea.git
synced 2026-05-09 14:28:43 +00:00
Merge branch 'master' into refactor-file-parser
# Conflicts: # src/main/java/seng302/models/GateMark.java
This commit is contained in:
@@ -43,7 +43,7 @@
|
|||||||
<transformer
|
<transformer
|
||||||
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
<Main-Class>seng302.models.App</Main-Class>
|
<Main-Class>seng302.App</Main-Class>
|
||||||
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
<X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
|
||||||
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
<X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
|
||||||
</manifestEntries>
|
</manifestEntries>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ public class App extends Application
|
|||||||
primaryStage.setTitle("RaceVision");
|
primaryStage.setTitle("RaceVision");
|
||||||
primaryStage.setScene(new Scene(root));
|
primaryStage.setScene(new Scene(root));
|
||||||
|
|
||||||
//OldApp.main(); // Run this to show how positions are updated
|
seng302.models.OldApp.main(); // Run this to show how positions are updated
|
||||||
|
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a boat in the race.
|
* Represents a boat in the race.
|
||||||
*/
|
*/
|
||||||
@@ -10,6 +12,7 @@ public class Boat {
|
|||||||
private double lat; // Boats position
|
private double lat; // Boats position
|
||||||
private double lon; // -
|
private double lon; // -
|
||||||
private double distanceToNextMark;
|
private double distanceToNextMark;
|
||||||
|
private Color color;
|
||||||
|
|
||||||
public Boat(String teamName) {
|
public Boat(String teamName) {
|
||||||
this.teamName = teamName;
|
this.teamName = teamName;
|
||||||
@@ -17,6 +20,7 @@ public class Boat {
|
|||||||
this.lat = 0.0;
|
this.lat = 0.0;
|
||||||
this.lon = 0.0;
|
this.lon = 0.0;
|
||||||
this.distanceToNextMark = 0.0;
|
this.distanceToNextMark = 0.0;
|
||||||
|
this.color = Colors.getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -89,4 +93,8 @@ public class Boat {
|
|||||||
public double getLongitude(){
|
public double getLongitude(){
|
||||||
return this.lon;
|
return this.lon;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Color getColor() {
|
||||||
|
return color;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package seng302.models;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ryan_ on 16/03/2017.
|
||||||
|
*/
|
||||||
|
public enum Colors {
|
||||||
|
RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE;
|
||||||
|
|
||||||
|
static Integer index = 0;
|
||||||
|
|
||||||
|
public static Color getColor() {
|
||||||
|
index++;
|
||||||
|
if (index > 6) {
|
||||||
|
index = 1;
|
||||||
|
}
|
||||||
|
return Color.valueOf(values()[index-1].toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
@@ -11,8 +13,8 @@ public class Event {
|
|||||||
private Double time; // Time the event occurs
|
private Double time; // Time the event occurs
|
||||||
private Boat boat;
|
private Boat boat;
|
||||||
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
private boolean isFinishingEvent = false; // This event occurs when a boat finishes the race
|
||||||
private Mark mark1; // This mark
|
private SingleMark singleMark1; // This mark
|
||||||
private Mark mark2; // Next Mark
|
private SingleMark singleMark2; // Next SingleMark
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,12 +24,12 @@ public class Event {
|
|||||||
* @param eventTime, what time the event happens
|
* @param eventTime, what time the event happens
|
||||||
* @param eventBoat, the boat that the event belongs to
|
* @param eventBoat, the boat that the event belongs to
|
||||||
*/
|
*/
|
||||||
public Event(Double eventTime, Boat eventBoat, Mark mark1, Mark mark2) {
|
public Event(Double eventTime, Boat eventBoat, SingleMark singleMark1, SingleMark singleMark2) {
|
||||||
this.time = eventTime;
|
this.time = eventTime;
|
||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
//this.leg = eventLeg;
|
//this.leg = eventLeg;
|
||||||
this.mark1 = mark1;
|
this.singleMark1 = singleMark1;
|
||||||
this.mark2 = mark2;
|
this.singleMark2 = singleMark2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,10 +39,10 @@ public class Event {
|
|||||||
* @param eventTime, what time the event happens
|
* @param eventTime, what time the event happens
|
||||||
* @param eventBoat, the boat that the event belongs to
|
* @param eventBoat, the boat that the event belongs to
|
||||||
*/
|
*/
|
||||||
public Event(Double eventTime, Boat eventBoat, Mark mark1) {
|
public Event(Double eventTime, Boat eventBoat, SingleMark singleMark1) {
|
||||||
this.time = eventTime;
|
this.time = eventTime;
|
||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
this.mark1 = mark1;
|
this.singleMark1 = singleMark1;
|
||||||
this.isFinishingEvent = true;
|
this.isFinishingEvent = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,13 +91,6 @@ public class Event {
|
|||||||
this.boat = eventBoat;
|
this.boat = eventBoat;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the boat in this event passes
|
|
||||||
* the marker.
|
|
||||||
*/
|
|
||||||
public void boatPassedMarker() {
|
|
||||||
this.mark1.addBoat(boat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if this event is the boat finishing the race
|
* Returns true if this event is the boat finishing the race
|
||||||
@@ -114,22 +109,32 @@ public class Event {
|
|||||||
if (this.isFinishingEvent) {
|
if (this.isFinishingEvent) {
|
||||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " finished the race");
|
||||||
}
|
}
|
||||||
|
System.out.println(this.getDistanceBetweenMarks());
|
||||||
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.mark1.getName() + " going heading " + this.getBoatHeading() + "°");
|
return (this.getTimeString() + ", " + this.getBoat().getTeamName() + " passed " + this.singleMark1.getName() + " going heading " + this.getBoatHeading() + "°");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the distance between the two marks
|
* @return the distance between the two marks
|
||||||
*/
|
*/
|
||||||
public double getDistanceBetweenMarks(){
|
public double getDistanceBetweenMarks(){
|
||||||
return Math.sqrt(Math.pow(mark1.getLatitude()-mark2.getLatitude(), 2) + Math.pow(mark1.getLongitude()-mark2.getLongitude(), 2));
|
//return Math.sqrt(Math.pow(singleMark1.getLatitude()-singleMark2.getLatitude(), 2) + Math.pow(singleMark1.getLongitude()-singleMark2.getLongitude(), 2));
|
||||||
|
double earth_radius = 6378.137;
|
||||||
|
double dLat = this.singleMark2.getLatitude() * Math.PI / 180 - this.singleMark1.getLatitude() * Math.PI / 180;
|
||||||
|
double dLon = this.singleMark2.getLongitude() * Math.PI / 180 - this.singleMark1.getLongitude() * Math.PI / 180;
|
||||||
|
|
||||||
|
double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(this.singleMark1.getLatitude() * Math.PI / 180) * Math.sin(dLon/2) * Math.sin(dLon/2);
|
||||||
|
|
||||||
|
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
|
||||||
|
double d = earth_radius * c;
|
||||||
|
|
||||||
|
return d * 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the boats heading
|
* @return the boats heading
|
||||||
*/
|
*/
|
||||||
public double getBoatHeading(){
|
public double getBoatHeading(){
|
||||||
double bearing = Math.atan2(mark2.getLatitude() - mark1.getLatitude(), mark2.getLongitude() - mark1.getLongitude());
|
double bearing = Math.atan2(singleMark2.getLatitude() - singleMark1.getLatitude(), singleMark2.getLongitude() - singleMark1.getLongitude());
|
||||||
if (bearing < 0) {
|
if (bearing < 0) {
|
||||||
bearing += Math.PI * 2;
|
bearing += Math.PI * 2;
|
||||||
}
|
}
|
||||||
@@ -140,15 +145,15 @@ public class Event {
|
|||||||
* Get the mark the event happened on
|
* Get the mark the event happened on
|
||||||
* @return the mark
|
* @return the mark
|
||||||
*/
|
*/
|
||||||
public Mark getMark(){
|
public SingleMark getMark(){
|
||||||
return this.mark1;
|
return this.singleMark1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the next mark
|
* Get the next mark
|
||||||
* @return the next mark
|
* @return the next mark
|
||||||
*/
|
*/
|
||||||
public Mark getNextMark(){
|
public SingleMark getNextMark(){
|
||||||
return this.mark2;
|
return this.singleMark2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by ptg19 on 16/03/17.
|
|
||||||
*/
|
|
||||||
public class GateMark {
|
|
||||||
private double lat;
|
|
||||||
private double lon;
|
|
||||||
private Mark mark1;
|
|
||||||
private Mark mark2;
|
|
||||||
|
|
||||||
public Mark getMark1() {
|
|
||||||
return mark1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Mark getMark2() {
|
|
||||||
return mark2;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
|
|
||||||
public GateMark(String name, Mark mark1, Mark mark2, double lat, double lon) {
|
|
||||||
this.lat = lat;
|
|
||||||
this.lon = lon;
|
|
||||||
this.mark1 = mark1;
|
|
||||||
this.mark2 = mark2;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GateMark(String name, Mark mark1, Mark mark2) {
|
|
||||||
this.mark1 = mark1;
|
|
||||||
this.mark2 = mark2;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the leg of a race.
|
* Represents the leg of a race.
|
||||||
*/
|
*/
|
||||||
@@ -7,19 +9,19 @@ public class Leg {
|
|||||||
private int heading;
|
private int heading;
|
||||||
private int distance;
|
private int distance;
|
||||||
private boolean isFinishingLeg;
|
private boolean isFinishingLeg;
|
||||||
private Mark startingMark;
|
private SingleMark startingSingleMark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new leg
|
* Create a new leg
|
||||||
*
|
*
|
||||||
* @param heading, the magnetic heading of this leg
|
* @param heading, the magnetic heading of this leg
|
||||||
* @param distance, the total distance of this leg in meters
|
* @param distance, the total distance of this leg in meters
|
||||||
* @param mark, the mark this leg starts on
|
* @param singleMark, the singleMark this leg starts on
|
||||||
*/
|
*/
|
||||||
public Leg(int heading, int distance, Mark mark) {
|
public Leg(int heading, int distance, SingleMark singleMark) {
|
||||||
this.heading = heading;
|
this.heading = heading;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
this.startingMark = mark;
|
this.startingSingleMark = singleMark;
|
||||||
this.isFinishingLeg = false;
|
this.isFinishingLeg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +35,7 @@ public class Leg {
|
|||||||
public Leg(int heading, int distance, String markerName) {
|
public Leg(int heading, int distance, String markerName) {
|
||||||
this.heading = heading;
|
this.heading = heading;
|
||||||
this.distance = distance;
|
this.distance = distance;
|
||||||
this.startingMark = new Mark(markerName);
|
this.startingSingleMark = new SingleMark(markerName);
|
||||||
this.isFinishingLeg = false;
|
this.isFinishingLeg = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,30 +70,25 @@ public class Leg {
|
|||||||
/**
|
/**
|
||||||
* Returns the marker this leg started on
|
* Returns the marker this leg started on
|
||||||
*/
|
*/
|
||||||
public Mark getMarker() {
|
public SingleMark getMarker() {
|
||||||
return this.startingMark;
|
return this.startingSingleMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the mark this leg starts on
|
* Set the singleMark this leg starts on
|
||||||
*/
|
*/
|
||||||
public void setMarker(Mark mark) {
|
public void setMarker(SingleMark singleMark) {
|
||||||
this.startingMark = mark;
|
this.startingSingleMark = singleMark;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the name of the marker this leg started on
|
* Returns the name of the marker this leg started on
|
||||||
*/
|
*/
|
||||||
public String getMarkerLabel() {
|
public String getMarkerLabel() {
|
||||||
return this.startingMark.getName();
|
return this.startingSingleMark.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tell the marker that the boat has passed it
|
|
||||||
*/
|
|
||||||
public void addBoatToMarker(Boat boat) {
|
|
||||||
this.startingMark.addBoat(boat);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specify whether or not the race finishes on this leg
|
* Specify whether or not the race finishes on this leg
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
package seng302.models;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the marker at the beginning of a leg
|
|
||||||
*/
|
|
||||||
public class Mark {
|
|
||||||
private double lat;
|
|
||||||
private double lon;
|
|
||||||
private String name;
|
|
||||||
private ArrayList<Boat> boatOrder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a marker
|
|
||||||
*
|
|
||||||
* @param name, the name of the marker*
|
|
||||||
* @param lat, the latitude of the marker
|
|
||||||
* @param lon, the longitude of the marker
|
|
||||||
*/
|
|
||||||
public Mark(String name, double lat, double lon){
|
|
||||||
this.name = name;
|
|
||||||
this.lat = lat;
|
|
||||||
this.lon = lon;
|
|
||||||
this.boatOrder = new ArrayList<Boat>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the marker at the beginning of a leg
|
|
||||||
*
|
|
||||||
* @param name, the name of the marker
|
|
||||||
*/
|
|
||||||
public Mark(String name){
|
|
||||||
this.name = name;
|
|
||||||
this.lat = 0;
|
|
||||||
this.lon = 0;
|
|
||||||
this.boatOrder = new ArrayList<Boat>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name){
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
public String getName(){
|
|
||||||
return this.name;
|
|
||||||
}
|
|
||||||
public void addBoat(Boat boat){
|
|
||||||
this.boatOrder.add(boat);
|
|
||||||
}
|
|
||||||
public Boat[] getBoats(){
|
|
||||||
return this.boatOrder.toArray(new Boat[this.boatOrder.size()]);
|
|
||||||
}
|
|
||||||
public double getLatitude(){
|
|
||||||
return this.lat;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLongitude(){
|
|
||||||
return this.lon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -55,11 +57,11 @@ public class OldApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add marks to race in order
|
// Add marks to race in order
|
||||||
race.addMark(new Mark("Start", 32.296038,-64.854401 ));
|
race.addMark(new SingleMark("Start", 32.296038,-64.854401 ));
|
||||||
race.addMark(new Mark("Mid Mark", 32.292881,-64.843231 ));
|
race.addMark(new SingleMark("Mid SingleMark", 32.292881,-64.843231 ));
|
||||||
race.addMark(new Mark("Leeward Gate", 32.283808,-64.850012 ));
|
race.addMark(new SingleMark("Leeward Gate", 32.283808,-64.850012 ));
|
||||||
race.addMark(new Mark("Windward Gate", 32.309908,-64.833665 ));
|
race.addMark(new SingleMark("Windward Gate", 32.309908,-64.833665 ));
|
||||||
race.addMark(new Mark("Finish", 32.318439,-64.837367 ));
|
race.addMark(new SingleMark("Finish", 32.318439,-64.837367 ));
|
||||||
|
|
||||||
return race;
|
return race;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package seng302.models;
|
package seng302.models;
|
||||||
|
|
||||||
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
import java.lang.reflect.Array;
|
import java.lang.reflect.Array;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
@@ -10,7 +12,7 @@ public class Race {
|
|||||||
private ArrayList<Boat> boats; // The boats in the race
|
private ArrayList<Boat> boats; // The boats in the race
|
||||||
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
|
private ArrayList<Boat> finishingOrder; // The order in which the boats finish the race
|
||||||
private PriorityQueue<Event> events; // The events that occur in the race
|
private PriorityQueue<Event> events; // The events that occur in the race
|
||||||
private ArrayList<Mark> marks; // Marks in the race
|
private ArrayList<SingleMark> singleMarks; // Marks in the race
|
||||||
private int numberOfBoats = 0;
|
private int numberOfBoats = 0;
|
||||||
private long startTime = 0;
|
private long startTime = 0;
|
||||||
private double timeScale = 1;
|
private double timeScale = 1;
|
||||||
@@ -21,7 +23,7 @@ public class Race {
|
|||||||
public Race() {
|
public Race() {
|
||||||
this.boats = new ArrayList<Boat>();
|
this.boats = new ArrayList<Boat>();
|
||||||
this.finishingOrder = new ArrayList<Boat>();
|
this.finishingOrder = new ArrayList<Boat>();
|
||||||
this.marks = new ArrayList<Mark>();
|
this.singleMarks = new ArrayList<SingleMark>();
|
||||||
|
|
||||||
// create a priority queue with a custom Comparator to order events
|
// create a priority queue with a custom Comparator to order events
|
||||||
this.events = new PriorityQueue<Event>(new Comparator<Event>() {
|
this.events = new PriorityQueue<Event>(new Comparator<Event>() {
|
||||||
@@ -140,21 +142,21 @@ public class Race {
|
|||||||
|
|
||||||
for (Boat boat : this.boats) {
|
for (Boat boat : this.boats) {
|
||||||
double totalDistance = 0;
|
double totalDistance = 0;
|
||||||
int numberOfMarks = this.marks.size();
|
int numberOfMarks = this.singleMarks.size();
|
||||||
|
|
||||||
for(int i = 0; i < numberOfMarks; i++){
|
for(int i = 0; i < numberOfMarks; i++){
|
||||||
Double time = (Double) (1000 * totalDistance / boat.getVelocity());
|
Double time = (Double) (1000 * totalDistance / boat.getVelocity());
|
||||||
|
|
||||||
// If there are marks after this event
|
// If there are singleMarks after this event
|
||||||
if (i < numberOfMarks-1) {
|
if (i < numberOfMarks-1) {
|
||||||
Event event = new Event(time, boat, marks.get(i), marks.get(i + 1));
|
Event event = new Event(time, boat, singleMarks.get(i), singleMarks.get(i + 1));
|
||||||
events.add(event);
|
events.add(event);
|
||||||
totalDistance += event.getDistanceBetweenMarks();
|
totalDistance += event.getDistanceBetweenMarks();
|
||||||
|
|
||||||
}
|
}
|
||||||
// There are no more marks after this event
|
// There are no more singleMarks after this event
|
||||||
else{
|
else{
|
||||||
Event event = new Event(time, boat, marks.get(i));
|
Event event = new Event(time, boat, singleMarks.get(i));
|
||||||
events.add(event);
|
events.add(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -224,10 +226,10 @@ public class Race {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a mark to the race (in order)
|
* Add a singleMark to the race (in order)
|
||||||
* @param mark, the mark to add
|
* @param singleMark, the singleMark to add
|
||||||
*/
|
*/
|
||||||
public void addMark(Mark mark){
|
public void addMark(SingleMark singleMark){
|
||||||
this.marks.add(mark);
|
this.singleMarks.add(singleMark);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To represent a gate mark which contains two single marks.
|
||||||
|
* Created by ptg19 on 16/03/17.
|
||||||
|
* Modified by Haoming Yin (hyi25) on 17/3/2017.
|
||||||
|
*/
|
||||||
|
public class GateMark extends Mark {
|
||||||
|
|
||||||
|
private SingleMark singleMark1;
|
||||||
|
private SingleMark singleMark2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create an instance of Gate Mark which contains two single mark
|
||||||
|
* @param name the name of the gate mark
|
||||||
|
* @param singleMark1 one single mark inside of the gate mark
|
||||||
|
* @param singleMark2 the second mark inside of the gate mark
|
||||||
|
*/
|
||||||
|
public GateMark(String name, SingleMark singleMark1, SingleMark singleMark2) {
|
||||||
|
super(name, MarkType.GATE_MARK);
|
||||||
|
this.singleMark1 = singleMark1;
|
||||||
|
this.singleMark2 = singleMark2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleMark getSingleMark1() {
|
||||||
|
return singleMark1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingleMark1(SingleMark singleMark1) {
|
||||||
|
this.singleMark1 = singleMark1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SingleMark getSingleMark2() {
|
||||||
|
return singleMark2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSingleMark2(SingleMark singleMark2) {
|
||||||
|
this.singleMark2 = singleMark2;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An abstract class to represent general marks
|
||||||
|
* Created by Haoming Yin (hyi25) on 17/3/17.
|
||||||
|
*/
|
||||||
|
public abstract class Mark {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private MarkType markType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a mark instance by passing its name and type
|
||||||
|
* @param name the name of the mark
|
||||||
|
* @param markType the type of mark. either GATE_MARK or SINGLE_MARK.
|
||||||
|
*/
|
||||||
|
public Mark (String name, MarkType markType) {
|
||||||
|
this.name = name;
|
||||||
|
this.markType = markType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MarkType getMarkType() {
|
||||||
|
return markType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkType(MarkType markType) {
|
||||||
|
this.markType = markType;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To represent two types of mark
|
||||||
|
* Created by Haoming Yin (hyi25) on 17/3/17.
|
||||||
|
*/
|
||||||
|
public enum MarkType {
|
||||||
|
SINGLE_MARK, GATE_MARK
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the marker as a single mark
|
||||||
|
*
|
||||||
|
* Created by Haoming Yin (hyi25) on 17/3/2017
|
||||||
|
*/
|
||||||
|
public class SingleMark extends Mark {
|
||||||
|
private double lat;
|
||||||
|
private double lon;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a marker
|
||||||
|
*
|
||||||
|
* @param name, the name of the marker*
|
||||||
|
* @param lat, the latitude of the marker
|
||||||
|
* @param lon, the longitude of the marker
|
||||||
|
*/
|
||||||
|
public SingleMark(String name, double lat, double lon) {
|
||||||
|
super(name, MarkType.SINGLE_MARK);
|
||||||
|
this.lat = lat;
|
||||||
|
this.lon = lon;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the marker at the beginning of a leg
|
||||||
|
*
|
||||||
|
* @param name, the name of the marker
|
||||||
|
*/
|
||||||
|
public SingleMark(String name) {
|
||||||
|
super(name, MarkType.SINGLE_MARK);
|
||||||
|
this.lat = 0;
|
||||||
|
this.lon = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLatitude() {
|
||||||
|
return this.lat;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getLongitude() {
|
||||||
|
return this.lon;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package seng302;
|
||||||
|
|
||||||
|
import javafx.scene.paint.Color;
|
||||||
|
import org.junit.Test;
|
||||||
|
import seng302.models.Boat;
|
||||||
|
import seng302.models.Colors;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by ryan_ on 16/03/2017.
|
||||||
|
*/
|
||||||
|
public class ColorsTest {
|
||||||
|
@Test
|
||||||
|
public void testNextColor() {
|
||||||
|
List<Boat> boats = new ArrayList<>();
|
||||||
|
boats.add(new Boat("Team 1"));
|
||||||
|
boats.add(new Boat("Team 2"));
|
||||||
|
boats.add(new Boat("Team 3"));
|
||||||
|
boats.add(new Boat("Team 4"));
|
||||||
|
boats.add(new Boat("Team 5"));
|
||||||
|
boats.add(new Boat("Team 6"));
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
List<Color> enumColors = new ArrayList<>();
|
||||||
|
while (count < 6) {
|
||||||
|
Color color = Colors.getColor();
|
||||||
|
enumColors.add(color);
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Color> boatColors = new ArrayList<>();
|
||||||
|
for (Boat boat : boats) {
|
||||||
|
Color color = boat.getColor();
|
||||||
|
boatColors.add(color);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(enumColors, boatColors);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@ package seng302;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.models.Boat;
|
import seng302.models.Boat;
|
||||||
import seng302.models.Event;
|
import seng302.models.Event;
|
||||||
import seng302.models.Mark;
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -16,14 +16,14 @@ public class EventTest {
|
|||||||
@Test
|
@Test
|
||||||
public void getTimeString() throws Exception {
|
public void getTimeString() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
Boat boat = new Boat("testBoat");
|
||||||
Event event = new Event(1231242.2, boat, new Mark("mark1"), new Mark("mark2"));
|
Event event = new Event(1231242.2, boat, new SingleMark("mark1"), new SingleMark("mark2"));
|
||||||
assertEquals("20:31:242", event.getTimeString());
|
assertEquals("20:31:242", event.getTimeString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBoatHeading() throws Exception {
|
public void testBoatHeading() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
Boat boat = new Boat("testBoat");
|
||||||
Event event = new Event(1231242.2, boat, new Mark("mark1", 142.5, 122.1), new Mark("mark2", 121.9,99.2));
|
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
|
||||||
|
|
||||||
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
|
assertEquals(event.getBoatHeading(), 221.9733862944651, 1e-15);
|
||||||
}
|
}
|
||||||
@@ -31,8 +31,8 @@ public class EventTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDistanceBetweenMarks() throws Exception {
|
public void testDistanceBetweenMarks() throws Exception {
|
||||||
Boat boat = new Boat("testBoat");
|
Boat boat = new Boat("testBoat");
|
||||||
Event event = new Event(1231242.2, boat, new Mark("mark1", 142.5, 122.1), new Mark("mark2", 121.9,99.2));
|
Event event = new Event(1231242.2, boat, new SingleMark("mark1", 142.5, 122.1), new SingleMark("mark2", 121.9,99.2));
|
||||||
|
|
||||||
assertEquals(event.getDistanceBetweenMarks(), 30.80211031731429, 1e-15);
|
assertEquals(event.getDistanceBetweenMarks(), 339059.653830461, 1e-15);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package seng302;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import seng302.models.Leg;
|
import seng302.models.Leg;
|
||||||
import seng302.models.Mark;
|
import seng302.models.mark.SingleMark;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
@@ -17,25 +17,25 @@ public class LegTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLegCreationUsingMarkerLabel() {
|
public void testLegCreationUsingMarkerLabel() {
|
||||||
Leg leg = new Leg(010, 100, "Mark");
|
Leg leg = new Leg(010, 100, "SingleMark");
|
||||||
|
|
||||||
assertEquals(leg.getHeading(), 010);
|
assertEquals(leg.getHeading(), 010);
|
||||||
assertEquals(leg.getDistance(), 100);
|
assertEquals(leg.getDistance(), 100);
|
||||||
assertEquals(leg.getMarkerLabel(), "Mark");
|
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||||
assertEquals(leg.getIsFinishingLeg(), false);
|
assertEquals(leg.getIsFinishingLeg(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test creation of the leg by providing a
|
* Test creation of the leg by providing a
|
||||||
* Mark object
|
* SingleMark object
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testLegCreation() {
|
public void testLegCreation() {
|
||||||
Leg leg = new Leg(010, 100, new Mark("Mark"));
|
Leg leg = new Leg(010, 100, new SingleMark("SingleMark"));
|
||||||
|
|
||||||
assertEquals(leg.getHeading(), 010);
|
assertEquals(leg.getHeading(), 010);
|
||||||
assertEquals(leg.getDistance(), 100);
|
assertEquals(leg.getDistance(), 100);
|
||||||
assertEquals(leg.getMarkerLabel(), "Mark");
|
assertEquals(leg.getMarkerLabel(), "SingleMark");
|
||||||
assertEquals(leg.getIsFinishingLeg(), false);
|
assertEquals(leg.getIsFinishingLeg(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ public class LegTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testSetFinishLeg() {
|
public void testSetFinishLeg() {
|
||||||
Leg leg = new Leg(010, 100, "Mark");
|
Leg leg = new Leg(010, 100, "SingleMark");
|
||||||
|
|
||||||
leg.setFinishingLeg(true);
|
leg.setFinishingLeg(true);
|
||||||
assertEquals(leg.getIsFinishingLeg(), true);
|
assertEquals(leg.getIsFinishingLeg(), true);
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package seng302.models.mark;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Haoming on 17/3/17.
|
||||||
|
*/
|
||||||
|
public class MarkTest {
|
||||||
|
|
||||||
|
private SingleMark singleMark1;
|
||||||
|
private SingleMark singleMark2;
|
||||||
|
private GateMark gateMark;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
this.singleMark1 = new SingleMark("testMark_SM1", 12.23234, -34.342);
|
||||||
|
this.singleMark2 = new SingleMark("testMark_SM2", 12.23239, -34.352);
|
||||||
|
this.gateMark = new GateMark("testMark_GM", singleMark1, singleMark2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getName() throws Exception {
|
||||||
|
assertEquals("testMark_SM1", this.singleMark1.getName());
|
||||||
|
assertEquals("testMark_GM", this.gateMark.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMarkType() throws Exception {
|
||||||
|
assertTrue(this.singleMark2.getMarkType() == MarkType.SINGLE_MARK);
|
||||||
|
assertTrue(this.gateMark.getMarkType() == MarkType.GATE_MARK);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getMarkContent() throws Exception {
|
||||||
|
assertEquals(12.23234, this.singleMark1.getLatitude(), 1e-10);
|
||||||
|
assertEquals(-34.342, this.singleMark1.getLongitude(), 1e-10);
|
||||||
|
assertEquals("testMark_SM1", this.gateMark.getSingleMark1().getName());
|
||||||
|
assertEquals(-34.352, this.gateMark.getSingleMark2().getLongitude(), 1e-10);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user