Merge branch 'Development' into story_64_sails

# Conflicts:
#	racevisionGame/src/main/java/mock/model/commandFactory/CommandFactory.java
#	racevisionGame/src/main/java/visualiser/model/ResizableRaceCanvas.java
#	racevisionGame/src/test/java/mock/model/MockBoatTest.java
This commit is contained in:
Joseph Gardner
2017-08-10 11:56:09 +12:00
24 changed files with 1593 additions and 44 deletions
@@ -5,6 +5,7 @@ import org.w3c.dom.Element;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import shared.enums.RoundingType;
import shared.enums.XMLFileType;
import shared.exceptions.InvalidRaceDataException;
import shared.exceptions.XMLReaderException;
@@ -316,6 +317,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
return element.getAttribute("Name");
}
private String getCompoundMarkRounding(Element element){return element.getAttribute("Rounding");}
/**
* Populates list of legs given CompoundMarkSequence element and referenced CompoundMark elements.
@@ -334,12 +337,19 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
//Gets the ID number of this corner element.
int cornerID = getCompoundMarkID(cornerElement);
//gets the Rounding of this corner element
String cornerRounding = getCompoundMarkRounding(cornerElement);
//Gets the CompoundMark associated with this corner.
CompoundMark lastCompoundMark = this.compoundMarkMap.get(cornerID);
//The name of the leg is the name of the first compoundMark in the leg.
String legName = lastCompoundMark.getName();
//Sets the rounding type of this compound mark
lastCompoundMark.setRoundingType(RoundingType.getValueOf(cornerRounding));
//For each following corner, create a leg between cornerN and cornerN+1.
for(int i = 1; i < corners.getLength(); i++) {
@@ -349,9 +359,15 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
//Gets the ID number of this corner element.
cornerID = getCompoundMarkID(cornerElement);
//gets the Rounding of this corner element
cornerRounding = getCompoundMarkRounding(cornerElement);
//Gets the CompoundMark associated with this corner.
CompoundMark currentCompoundMark = this.compoundMarkMap.get(cornerID);
//Sets the rounding type of this compound mark
currentCompoundMark.setRoundingType(RoundingType.valueOf(cornerRounding));
//Create a leg from these two adjacent compound marks.
Leg leg = new Leg(legName, lastCompoundMark, currentCompoundMark, i - 1);
legs.add(leg);
@@ -0,0 +1,49 @@
package shared.enums;
/**
* Enum for the types of rounding that can be done
*/
public enum RoundingType {
/**
* This is means it must be rounded port side
*/
Port,
/**
* This is means it must be rounded starboard side
*/
Starboard,
/**
* The boat within the compound mark with the SeqID
* of 1 should be rounded to starboard and the boat
* within the compound mark with the SeqID of 2 should
* be rounded to port.
*/
SP,
/**
* The boat within the compound mark with the SeqID
* of 1 should be rounded to port and the boat
* within the compound mark with the SeqID of 2 should
* be rounded to starboard.
*
* opposite of SP
*/
PS;
public static RoundingType getValueOf(String value) {
switch (value) {
case "Port":
return RoundingType.Port;
case "Starboard":
return RoundingType.Starboard;
case "SP":
return RoundingType.Port;
case "PS":
return RoundingType.Starboard;
default:
return null;
}
}
}
@@ -1,6 +1,8 @@
package shared.model;
import shared.enums.RoundingType;
/**
* Represents a compound mark - that is, either one or two individual marks which form a single compound mark.
*/
@@ -31,6 +33,11 @@ public class CompoundMark {
*/
private GPSCoordinate averageGPSCoordinate;
/**
* The side that the mark must be rounded on
*/
private RoundingType roundingType;
/**
* Constructs a compound mark from a single mark.
@@ -141,4 +148,107 @@ public class CompoundMark {
return averageCoordinate;
}
/**
* Used to get how this mark should be rounded
* @return rounding type for mark
*/
public RoundingType getRoundingType() {
return roundingType;
}
/**
* Used to set the type of rounding for this mark
* @param roundingType rounding type to set
*/
public void setRoundingType(RoundingType roundingType) {
this.roundingType = roundingType;
}
/**
* Used to find the mark that is to be rounded at a gate when approaching from the south
* will also give the single mark if there is only one
* @param bearing the bearing a boat will approach form
* @return the mark to round
*/
public Mark getMarkForRounding(Bearing bearing){
Mark westMostMark;
Mark eastMostMark;
Mark northMostMark;
Mark southMostMark;
//check to see if there are two marks
if (mark2 == null){
return mark1;
}
//finds the mark furthest west and east
if(this.getMark1Position().getLatitude() > this.getMark2Position().getLatitude()){
westMostMark = this.mark1;
eastMostMark = this.mark2;
}else{
westMostMark = this.mark2;
eastMostMark = this.mark1;
}
//finds the mark furthest north and south
if(this.getMark1Position().getLongitude() > this.getMark2Position().getLongitude()){
northMostMark = this.mark1;
southMostMark = this.mark2;
}else{
northMostMark = this.mark2;
southMostMark = this.mark1;
}
if (bearing.degrees() > 315 || bearing.degrees() <= 45){
//north
switch (this.getRoundingType()){
case SP:
case Port:
return westMostMark;
case PS:
case Starboard:
return eastMostMark;
default:return null;
}
}else if(bearing.degrees() > 45 && bearing.degrees() <= 135){
//east
switch (this.getRoundingType()){
case SP:
case Port:
return northMostMark;
case PS:
case Starboard:
return southMostMark;
default:return null;
}
}else if(bearing.degrees() > 135 && bearing.degrees() <= 225){
//south
switch (this.getRoundingType()){
case SP:
case Port:
return eastMostMark;
case PS:
case Starboard:
return westMostMark;
default:return null;
}
}else if(bearing.degrees() > 225 && bearing.degrees() <= 315){
//west
switch (this.getRoundingType()){
case SP:
case Port:
return southMostMark;
case PS:
case Starboard:
return northMostMark;
default:return null;
}
}else{
return null;
}
}
}
@@ -142,7 +142,7 @@ public class GPSCoordinate {
* @param coordinate The coordinate to test.
* @return true if a line from the point intersects the two boundary points
*/
private static boolean intersects(GPSCoordinate boundaryA, GPSCoordinate boundaryB, GPSCoordinate coordinate) {
public static boolean intersects(GPSCoordinate boundaryA, GPSCoordinate boundaryB, GPSCoordinate coordinate) {
double boundaryALat = boundaryA.getLatitude();
double boundaryALon = boundaryA.getLongitude();
double boundaryBLat = boundaryB.getLatitude();
@@ -22,7 +22,6 @@ public class Mark {
private GPSCoordinate position;
/**
* Constructs a mark with a given source ID, name, and position.
* @param sourceID The source ID of the mark.
@@ -241,7 +241,7 @@ public abstract class Race {
* @param windBearing New wind bearing.
* @param windSpeedKnots New wind speed, in knots.
*/
protected void setWind(Bearing windBearing, double windSpeedKnots) {
public void setWind(Bearing windBearing, double windSpeedKnots) {
Wind wind = new Wind(windBearing, windSpeedKnots);
setWind(wind);
}
@@ -250,7 +250,7 @@ public abstract class Race {
* Updates the race to have a specified wind (bearing and speed).
* @param wind New wind.
*/
protected void setWind(Wind wind) {
public void setWind(Wind wind) {
this.raceWind.setValue(wind);
}
@@ -332,6 +332,13 @@ public abstract class Race {
return lastFps;
}
/**
* Returns the legs of this race
* @return list of legs
*/
public List<Leg> getLegs() {
return legs;
}
/**
* Increments the FPS counter, and adds timePeriod milliseconds to our FPS reset timer.