Mock.Polars:

Finished PolarsTest test cases.

Fixed a number of javadoc errors across the codebase.

#story[873]
This commit is contained in:
fjc40
2017-05-17 13:33:34 +12:00
parent 00c9cb2c83
commit be9f19eae5
12 changed files with 171 additions and 107 deletions
@@ -211,8 +211,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
/**
* gets a marker from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @return
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}.
* @return The Marker object constructed from the XML file.
*/
private Marker getMarker(NodeList start) {
return getMarker(start, 0);
@@ -221,9 +221,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
/**
* gets a marker from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}.
* @param startIndex index in the node that has the coordinate tag
* @return
* @return The Marker object constructed from the XML file.
*/
private Marker getMarker(NodeList start, int startIndex) {
return getMarker(start, startIndex, 0);
@@ -232,10 +232,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
/**
* gets a marker from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}.
* @param startIndex index in the node that has the coordinate tag
* @param nodeIndex coordinate index
* @return
* @return The Marker object constructed from the XML file.
*/
private Marker getMarker(NodeList start, int startIndex, int nodeIndex) {
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
@@ -244,10 +244,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
}
/**
* gets a changes a marker to GPS coordinates into a marker
* Constructs a Marker object from an XML element.
*
* @param markerNode marker to turn into coordinates
* @return
* @return The Marker object constructed from the XML element.
*/
private Marker getMarker(Element markerNode) {
@@ -267,8 +267,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
/**
* gets a coordinates from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @return
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}
* @return The GPSCoordinate constructed from the XML file.
*/
private GPSCoordinate getCoordinates(NodeList start) {
return getCoordinates(start, 0);
@@ -277,21 +277,20 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
/**
* gets a coordinates from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}.
* @param startIndex the index the tag containing the coordinate should be in
* @return
* @return The GPSCoordinate constructed from the XML file.
*/
private GPSCoordinate getCoordinates(NodeList start, int startIndex) {
return getCoordinates(start, startIndex, 0);
}
/**
* gets a coordinates from the XML file
*
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
* Gets a GPSCoordinate from the XML file from a specific node and element.
* @param start base nodelist this should be the tag that contains {@literal <coordinate></coordinate>}.
* @param startIndex the index the tag containing the coordinate should be in
* @param nodeIndex The coordinate index
* @return
* @return The GPSCoordinate constructed from the XML file.
*/
private GPSCoordinate getCoordinates(NodeList start, int startIndex, int nodeIndex) {
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("coordinate");
@@ -300,10 +299,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
}
/**
* Returns the coordinate TODO raise exception that runs when the XML is formatted wrongly.
*
* @param coordNode
* @return
* Returns the coordinate object from a coordinate XML element.
* TODO raise exception that runs when the XML is formatted wrongly.
* @param coordNode The XML coordinate element to parse.
* @return The GPSCoordinate constructed from the XML coordinate element.
*/
private GPSCoordinate getCoordinates(Element coordNode) {
@@ -54,7 +54,7 @@ public class RegattaXMLReader extends XMLReader implements RegattaDataSource {
/**
* Create new regatta
* @param attributes
* @param attributes The RegattaConfig element from the XML file.
*/
private void makeRegatta(Element attributes) {
int regattaID = Integer.parseInt(getTextValueOfNode(attributes, "RegattaID"));
@@ -20,9 +20,9 @@ public abstract class XMLReader {
/**
* Read in XML file
* @param filePath filepath for XML file
* @throws ParserConfigurationException
* @throws IOException
* @throws SAXException
* @throws ParserConfigurationException If a document builder cannot be created.
* @throws IOException If any IO errors occur while parsing the XML file.
* @throws SAXException If any parse error occurs while parsing.
*/
public XMLReader(String filePath) throws ParserConfigurationException, IOException, SAXException {
InputStream fXmlFile = getClass().getClassLoader().getResourceAsStream(filePath);
@@ -120,9 +120,9 @@ public class GPSCoordinate {
/**
* Helper function to find if a point is in a boundary
* @param boundaryA
* @param boundaryB
* @param coordinate
* @param boundaryA The first coordinate of the boundary.
* @param boundaryB The second coordinate of the bounary.
* @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) {
+14 -6
View File
@@ -13,12 +13,16 @@ import java.util.*;
*/
public class Polars {
///Internal store of data. Maps pair<windSpeed, windAngle> to boatSpeed.
/**
* Internal store of data. Maps {@literal Pair<windSpeed, windAngle>} to boatSpeed.
*/
private Map<Pair<Double, Double>, Double> polarValues = new HashMap<>();
///Stores a list of angles from the polar table - this is used during the calculateVMG function.
///Maps between windSpeed and a list of angles for that wind speed.
/**
* Stores a list of angles from the polar table - this is used during the calculateVMG function.
* Maps between windSpeed and a list of angles for that wind speed.
*/
private HashMap<Double, List<Double>> polarAngles = new HashMap<>();
@@ -79,9 +83,13 @@ public class Polars {
/**
* Calculates the VMG for a given wind angle, wind speed, and angle to destination. Will only return VMGs that have a true bearing (angle) within a given bound - this is to ensure that you can calculate VMGs without going out of bounds. If you don't care about bearing bounds, simple pass in lower = 0, upper = 360.
* Calculates the VMG for a given wind angle, wind speed, and angle to destination. Will only return VMGs that have a true bearing (angle) within a given bound - this is to ensure that you can calculate VMGs without going out of bounds. If you don't care about bearing bounds, simply pass in lower = 0, upper = 360.
* <br><br>
* The resulting angle of the VMG will be within the interval [bearingLowerBound, bearingUpperBound). Note the exclusive end of interval.
* If the lower bound is greater than the upper bound (e.g., lower = 70, upper = 55), then it checks that VMGAngle >= lower OR VMGAngle < upper (e.g., [70, 55) means angle >= 70, OR angle < 55).
* <br><br>
* If the lower bound is greater than the upper bound (e.g., lower = 70, upper = 55), then it checks that {@literal VMGAngle >= lower OR VMGAngle < upper} (e.g., {@literal [70, 55) means angle >= 70, OR angle < 55}).
* <br><br>
* Returns a VMG with 0 speed and 0 bearing if there are no VMGs with {@literal velocity > 0} in the acceptable bearing bounds.
* @param trueWindAngle The current true wind angle. Interval is [0, 360).
* @param trueWindSpeed The current true wind speed. Knots.
* @param destinationAngle The angle between the boat and the destination point. Interval is [0, 360).
@@ -167,7 +175,7 @@ public class Polars {
double bestVMGAngle = 0;
//Calculate the VMG for all possible angles at this wind speed.
for (double angle = 0; angle < 360; angle += 1) {
for (double angle = 0; angle < 360; angle += 0.1) {
//This is the true bearing of the boat, if it went at the angle against the wind.
//For angle < 90 OR angle > 270, it means that the boat is going into the wind (tacking).
+7 -3
View File
@@ -9,10 +9,14 @@ package seng302.Model;
*/
public class VMG {
///Speed component of the VMG.
/**
* Speed component of the VMG.
*/
private double speed;
///Bearing component of the VMG.
/**
* Bearing component of the VMG.
*/
private double bearing;
@@ -28,7 +32,7 @@ public class VMG {
/**
* Returns the speed component of this VMG object.
* Returns the speed component of this VMG object, measured in.
* @return Speed component of this VMG object.
*/
public double getSpeed() {