Merge remote-tracking branch 'remotes/origin/story68' into Development

This commit is contained in:
hba56
2017-08-07 12:29:56 +12:00
10 changed files with 475 additions and 25 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;
@@ -313,6 +314,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.
@@ -331,12 +334,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++) {
@@ -346,9 +356,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,20 @@ 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;
}
}
@@ -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.