Reads data from boat XML file
- Creates marks for building CompoundMarks (formerly Markers) - Rearranged Boat constructor and removed velocity #story[782]
This commit is contained in:
@@ -4,17 +4,13 @@ package seng302;
|
||||
import javafx.application.Application;
|
||||
import javafx.stage.Stage;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RaceXMLReader;
|
||||
import seng302.DataInput.RegattaDataSource;
|
||||
import seng302.DataInput.RegattaXMLReader;
|
||||
import seng302.DataInput.*;
|
||||
import seng302.Model.Event;
|
||||
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -39,9 +35,10 @@ public class App extends Application {
|
||||
@Override
|
||||
public void start(Stage primaryStage) {
|
||||
try {
|
||||
RaceDataSource raceData = new RaceXMLReader("raceXML/bermuda_AC35.xml");
|
||||
RaceDataSource raceData = new RaceXMLReader("mockXML/raceTest.xml");
|
||||
RegattaDataSource regattaData = new RegattaXMLReader("mockXML/regattaTest.xml");
|
||||
Event raceEvent = new Event(raceData, regattaData);
|
||||
BoatDataSource boatData = new BoatXMLReader("mockXML/boatTest.xml");
|
||||
Event raceEvent = new Event(raceData, regattaData, boatData);
|
||||
raceEvent.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -159,7 +159,7 @@ public class BoatData {
|
||||
private void appendStoweName(Element boat, int i) {
|
||||
//StoweName attribute
|
||||
Attr attrStoweName = doc.createAttribute("StoweName");
|
||||
attrStoweName.setValue(boatData.get(i).getAbbrev());
|
||||
attrStoweName.setValue(boatData.get(i).getCountry());
|
||||
boat.setAttributeNode(attrStoweName);
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ public class BoatData {
|
||||
private void appendShortName(Element boat, int i) {
|
||||
//ShortName attribute
|
||||
Attr attrShortName = doc.createAttribute("ShortName");
|
||||
attrShortName.setValue(boatData.get(i).getAbbrev());
|
||||
attrShortName.setValue(boatData.get(i).getCountry());
|
||||
boat.setAttributeNode(attrShortName);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.w3c.dom.Element;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.Exceptions.InvalidRaceDataException;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.CompoundMarker;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
@@ -151,9 +151,9 @@ public class RaceData {
|
||||
Element compoundMarkSeqElement = doc.createElement("CompoundMarkSequence");
|
||||
|
||||
int i = 1;
|
||||
for (Marker marker : dataSource.getMarkers()) {
|
||||
for (CompoundMarker compoundMarker : dataSource.getCompoundMarkers()) {
|
||||
|
||||
courseElement.appendChild(createCompoundMarker(marker, i));
|
||||
courseElement.appendChild(createCompoundMarker(compoundMarker, i));
|
||||
compoundMarkSeqElement.appendChild(createCornerElement(i));
|
||||
i++;
|
||||
}
|
||||
@@ -177,21 +177,21 @@ public class RaceData {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a compound marker holding one or two marks,and a sequence number
|
||||
* Creates a compound compoundMarker holding one or two marks,and a sequence number
|
||||
*
|
||||
* @param marker marker
|
||||
* @param compoundMarker compoundMarker
|
||||
* @param i sequence number
|
||||
* @return Element compound mark element
|
||||
*/
|
||||
private Element createCompoundMarker(Marker marker, int i) {
|
||||
private Element createCompoundMarker(CompoundMarker compoundMarker, int i) {
|
||||
Element compoundMarkElement = doc.createElement("CompoundMark");
|
||||
compoundMarkElement.setAttribute("CompoundMarkID", i + "");
|
||||
compoundMarkElement.setAttribute("Name", marker.getName());
|
||||
compoundMarkElement.setAttribute("Name", compoundMarker.getName());
|
||||
|
||||
compoundMarkElement.appendChild(createMark(marker.getMark1()));
|
||||
compoundMarkElement.appendChild(createMark(compoundMarker.getMark1()));
|
||||
|
||||
if (!(marker.getMark1().equals(marker.getMark2()))) {
|
||||
compoundMarkElement.appendChild(createMark(marker.getMark2()));
|
||||
if (!(compoundMarker.getMark1().equals(compoundMarker.getMark2()))) {
|
||||
compoundMarkElement.appendChild(createMark(compoundMarker.getMark2()));
|
||||
}
|
||||
|
||||
return compoundMarkElement;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.Mark;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -9,5 +10,5 @@ import java.util.List;
|
||||
*/
|
||||
public interface BoatDataSource {
|
||||
List<Boat> getBoats();
|
||||
List<Boat> getMarkerBoats();
|
||||
List<Mark> getMarkerBoats();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,111 @@
|
||||
package seng302.DataInput;
|
||||
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.Mark;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
*/
|
||||
public class BoatXMLReader extends XMLReader implements BoatDataSource {
|
||||
private final Map<Integer, Boat> boatMap = new HashMap<>();
|
||||
private final Map<Integer, Mark> markerMap = new HashMap<>();
|
||||
|
||||
public BoatXMLReader(String filePath) throws ParserConfigurationException, SAXException, IOException {
|
||||
this(filePath, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* COnstructor for Boat XML
|
||||
*
|
||||
* @param filePath file path to read
|
||||
* @param read whether or not to read and store the files straight away.
|
||||
* @throws IOException error
|
||||
* @throws SAXException error
|
||||
* @throws ParserConfigurationException error
|
||||
*/
|
||||
public BoatXMLReader(String filePath, boolean read) throws IOException, SAXException, ParserConfigurationException {
|
||||
super(filePath);
|
||||
if (read) {
|
||||
read();
|
||||
}
|
||||
}
|
||||
|
||||
public void read() {
|
||||
readSettings();
|
||||
readShapes();
|
||||
readBoats();
|
||||
}
|
||||
|
||||
private void readBoats() {
|
||||
Element nBoats = (Element) doc.getElementsByTagName("Boats").item(0);
|
||||
for (int i = 0; i < nBoats.getChildNodes().getLength(); i++) {
|
||||
Node boat = nBoats.getChildNodes().item(i);
|
||||
if (boat.getNodeName().equals("Boat")) {
|
||||
readSingleBoat(boat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignored data
|
||||
*/
|
||||
private void readShapes() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignored data
|
||||
*/
|
||||
private void readSettings() {
|
||||
|
||||
}
|
||||
|
||||
private boolean isYachtNode(Node boatNode) {
|
||||
return boatNode.getAttributes().getNamedItem("Type").getTextContent().toLowerCase().equals("yacht");
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the information about one boat
|
||||
* Ignored values: ShapeID, StoweName, HullNum, Skipper, Type
|
||||
*/
|
||||
private void readSingleBoat(Node boatNode) {
|
||||
Boat boat;
|
||||
String country = null;
|
||||
int sourceID = Integer.parseInt(boatNode.getAttributes().getNamedItem("SourceID").getTextContent());
|
||||
String name = boatNode.getAttributes().getNamedItem("BoatName").getTextContent();
|
||||
String shortName = boatNode.getAttributes().getNamedItem("ShortName").getTextContent();
|
||||
if (exists(boatNode, "Country")) country = boatNode.getAttributes().getNamedItem("Country").getTextContent();
|
||||
|
||||
if (isYachtNode(boatNode)) {
|
||||
if (country != null) {
|
||||
boat = new Boat(sourceID, name, country);
|
||||
} else {
|
||||
boat = new Boat(sourceID, name, shortName);
|
||||
}
|
||||
boatMap.put(sourceID, boat);
|
||||
} else {
|
||||
Mark mark = new Mark(name);
|
||||
markerMap.put(sourceID, mark);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Boat> getBoats() {
|
||||
return new ArrayList<>(boatMap.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mark> getMarkerBoats() {
|
||||
return new ArrayList<>(markerMap.values());
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ package seng302.DataInput;
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
import seng302.Model.CompoundMarker;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface RaceDataSource {
|
||||
|
||||
List<GPSCoordinate> getBoundary();
|
||||
|
||||
List<Marker> getMarkers();
|
||||
List<CompoundMarker> getCompoundMarkers();
|
||||
|
||||
int getRaceId();
|
||||
|
||||
|
||||
@@ -6,9 +6,9 @@ import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import seng302.Model.Boat;
|
||||
import seng302.Model.CompoundMarker;
|
||||
import seng302.Model.GPSCoordinate;
|
||||
import seng302.Model.Leg;
|
||||
import seng302.Model.Marker;
|
||||
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
@@ -27,7 +27,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
private GPSCoordinate mark, startPt1, startPt2, finishPt1, finishPt2, leewardPt1, leewardPt2, windwardPt1, windwardPt2;
|
||||
private GPSCoordinate mapTopLeft, mapBottomRight;
|
||||
private List<GPSCoordinate> boundary = new ArrayList<>();
|
||||
private List<Marker> markers = new ArrayList<>();
|
||||
private List<CompoundMarker> compoundMarkers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Constractor for Race XML
|
||||
@@ -86,10 +86,9 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
|
||||
for (int i = 0; i < nBoats.getLength(); i++) {
|
||||
String name = getTextValueOfNode((Element) nBoats.item(i), "name");
|
||||
String abbrev = getTextValueOfNode((Element) nBoats.item(i), "abbr");
|
||||
double velo = Double.parseDouble(getTextValueOfNode((Element) nBoats.item(i), "speed"));
|
||||
String country = getTextValueOfNode((Element) nBoats.item(i), "abbr");
|
||||
int sourceID = Integer.parseInt(getTextValueOfNode((Element) nBoats.item(i), "sourceID"));
|
||||
Boat boat = new Boat(name, velo, abbrev, sourceID);
|
||||
Boat boat = new Boat(sourceID, name, country);
|
||||
boat.setCurrentPosition(startPt1);
|
||||
if (legs.size() > 0) {
|
||||
boat.setCurrentLeg(legs.get(0));
|
||||
@@ -107,8 +106,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
NodeList nMarkers = doc.getElementsByTagName("marker");
|
||||
|
||||
for (int i = 0; i < nMarkers.getLength(); i++) {
|
||||
Marker marker = getMarker((Element) nMarkers.item(i));
|
||||
if (marker.getName() != null) markers.add(marker);
|
||||
CompoundMarker compoundMarker = getMarker((Element) nMarkers.item(i));
|
||||
if (compoundMarker.getName() != null) compoundMarkers.add(compoundMarker);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,10 +121,10 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
for (int i = 0; i < nLegs.getLength(); i++) {
|
||||
String label = getTextValueOfNode((Element) nLegs.item(i), "name");
|
||||
NodeList start = ((Element) nLegs.item(i)).getElementsByTagName("start");
|
||||
Marker startMarker = getMarker(start);
|
||||
CompoundMarker startCompoundMarker = getMarker(start);
|
||||
NodeList finish = ((Element) nLegs.item(i)).getElementsByTagName("finish");
|
||||
Marker finishMarker = getMarker(finish);
|
||||
legs.add(new Leg(label, startMarker, finishMarker, i));
|
||||
CompoundMarker finishCompoundMarker = getMarker(finish);
|
||||
legs.add(new Leg(label, startCompoundMarker, finishCompoundMarker, i));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,7 +204,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
* @param start base nodelist this should be the tag that contains <coordinate></coordinate>
|
||||
* @return
|
||||
*/
|
||||
private Marker getMarker(NodeList start) {
|
||||
private CompoundMarker getMarker(NodeList start) {
|
||||
return getMarker(start, 0);
|
||||
}
|
||||
|
||||
@@ -216,7 +215,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
* @param startIndex index in the node that has the coordinate tag
|
||||
* @return
|
||||
*/
|
||||
private Marker getMarker(NodeList start, int startIndex) {
|
||||
private CompoundMarker getMarker(NodeList start, int startIndex) {
|
||||
return getMarker(start, startIndex, 0);
|
||||
}
|
||||
|
||||
@@ -228,7 +227,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
* @param nodeIndex coordinate index
|
||||
* @return
|
||||
*/
|
||||
private Marker getMarker(NodeList start, int startIndex, int nodeIndex) {
|
||||
private CompoundMarker getMarker(NodeList start, int startIndex, int nodeIndex) {
|
||||
NodeList nodeList = ((Element) start.item(startIndex)).getElementsByTagName("marker");
|
||||
Element marker = (Element) nodeList.item(nodeIndex);
|
||||
return getMarker(marker);
|
||||
@@ -240,7 +239,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
* @param markerNode marker to turn into coordinates
|
||||
* @return
|
||||
*/
|
||||
private Marker getMarker(Element markerNode) {
|
||||
private CompoundMarker getMarker(Element markerNode) {
|
||||
|
||||
NodeList nCoordinates = markerNode.getElementsByTagName("coordinate");
|
||||
|
||||
@@ -252,7 +251,7 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
side2 = side1;
|
||||
}
|
||||
NodeList name = markerNode.getElementsByTagName("name");
|
||||
return name.getLength() == 1 ? new Marker(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new Marker(side1, side2);
|
||||
return name.getLength() == 1 ? new CompoundMarker(getTextValueOfNode((Element) markerNode, "name"), side1, side2) : new CompoundMarker(side1, side2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -363,8 +362,8 @@ public class RaceXMLReader extends XMLReader implements RaceDataSource {
|
||||
return raceID;
|
||||
}
|
||||
|
||||
public List<Marker> getMarkers() {
|
||||
return markers;
|
||||
public List<CompoundMarker> getCompoundMarkers() {
|
||||
return compoundMarkers;
|
||||
}
|
||||
|
||||
public String getRaceType() {
|
||||
|
||||
@@ -2,6 +2,7 @@ package seng302.DataInput;
|
||||
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
@@ -60,4 +61,8 @@ public abstract class XMLReader {
|
||||
return n.getAttribute(attr);
|
||||
}
|
||||
|
||||
protected boolean exists(Node node, String attribute) {
|
||||
return node.getAttributes().getNamedItem(attribute) != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Boat {
|
||||
private String name;
|
||||
private double velocity;
|
||||
private double scaledVelocity;
|
||||
private String abbrev;
|
||||
private String country;
|
||||
private int sourceID;
|
||||
private Leg currentLeg;
|
||||
private double distanceTravelledInLeg;
|
||||
@@ -22,14 +22,13 @@ public class Boat {
|
||||
/**
|
||||
* Boat initialiser which keeps all of the information of the boat.
|
||||
*
|
||||
* @param name Name of the Boat.
|
||||
* @param velocity Speed in m/s that the boat travels at.
|
||||
* @param abbrev nam abbreviation
|
||||
* @param sourceID id of boat
|
||||
* @param name Name of the Boat.
|
||||
* @param country nam abbreviation
|
||||
*/
|
||||
public Boat(String name, double velocity, String abbrev, int sourceID) {
|
||||
this.velocity = velocity;
|
||||
this.abbrev = abbrev;
|
||||
public Boat(int sourceID, String name, String country) {
|
||||
this.velocity = 5; // TODO - please dont commit
|
||||
this.country = this.country;
|
||||
this.name = name;
|
||||
this.sourceID = sourceID;
|
||||
}
|
||||
@@ -42,8 +41,8 @@ public class Boat {
|
||||
public double calculateAzimuth() {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
GPSCoordinate start = currentLeg.getStartMarker().getAverageGPSCoordinate();
|
||||
GPSCoordinate end = currentLeg.getEndMarker().getAverageGPSCoordinate();
|
||||
GPSCoordinate start = currentLeg.getStartCompoundMarker().getAverageGPSCoordinate();
|
||||
GPSCoordinate end = currentLeg.getEndCompoundMarker().getAverageGPSCoordinate();
|
||||
|
||||
calc.setStartingGeographicPoint(start.getLongitude(), start.getLatitude());
|
||||
calc.setDestinationGeographicPoint(end.getLongitude(), end.getLatitude());
|
||||
@@ -90,12 +89,12 @@ public class Boat {
|
||||
this.scaledVelocity = scaledVelocity;
|
||||
}
|
||||
|
||||
public String getAbbrev() {
|
||||
return abbrev;
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public void setAbbrev(String abbrev) {
|
||||
this.abbrev = abbrev;
|
||||
public void setCountry(String country) {
|
||||
this.country = country;
|
||||
}
|
||||
|
||||
public int getSourceID() {
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@ import java.awt.geom.Point2D;
|
||||
/**
|
||||
* Created by esa46 on 29/03/17.
|
||||
*/
|
||||
public class Marker {
|
||||
public class CompoundMarker {
|
||||
|
||||
private GPSCoordinate averageGPSCoordinate;
|
||||
private GPSCoordinate mark1;
|
||||
@@ -14,7 +14,7 @@ public class Marker {
|
||||
private String name;
|
||||
private boolean doubleMarker = false;
|
||||
|
||||
public Marker(GPSCoordinate mark1) {
|
||||
public CompoundMarker(GPSCoordinate mark1) {
|
||||
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark1;
|
||||
@@ -22,7 +22,7 @@ public class Marker {
|
||||
|
||||
}
|
||||
|
||||
public Marker(GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
public CompoundMarker(GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
|
||||
this.mark1 = mark1;
|
||||
this.mark2 = mark2;
|
||||
@@ -30,7 +30,7 @@ public class Marker {
|
||||
|
||||
}
|
||||
|
||||
public Marker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
public CompoundMarker(String name, GPSCoordinate mark1, GPSCoordinate mark2) {
|
||||
|
||||
this.name = name;
|
||||
this.mark1 = mark1;
|
||||
@@ -3,6 +3,7 @@ package seng302.Model;
|
||||
import seng302.Data.BoatData;
|
||||
import seng302.Data.RaceData;
|
||||
import seng302.Data.RegattaData;
|
||||
import seng302.DataInput.BoatDataSource;
|
||||
import seng302.DataInput.RaceDataSource;
|
||||
import seng302.DataInput.RegattaDataSource;
|
||||
import seng302.Exceptions.InvalidBoatDataException;
|
||||
@@ -24,12 +25,14 @@ public class Event {
|
||||
|
||||
RaceDataSource raceDataSource;
|
||||
RegattaDataSource regattaDataSource;
|
||||
BoatDataSource boatDataSource;
|
||||
|
||||
MockOutput mockOutput;
|
||||
|
||||
public Event(RaceDataSource raceData, RegattaDataSource regattaData) {
|
||||
public Event(RaceDataSource raceData, RegattaDataSource regattaData, BoatDataSource boatDataSource) {
|
||||
this.raceDataSource = raceData;
|
||||
this.regattaDataSource = regattaData;
|
||||
this.boatDataSource = boatDataSource;
|
||||
try {
|
||||
mockOutput = new MockOutput();
|
||||
new Thread(mockOutput).start();
|
||||
|
||||
@@ -10,8 +10,8 @@ import seng302.Constants;
|
||||
public class Leg {
|
||||
private String name; //nautical miles
|
||||
private double distance;
|
||||
private Marker startMarker;
|
||||
private Marker endMarker;
|
||||
private CompoundMarker startCompoundMarker;
|
||||
private CompoundMarker endCompoundMarker;
|
||||
private int legNumber;
|
||||
|
||||
/**
|
||||
@@ -22,10 +22,10 @@ public class Leg {
|
||||
* @param end marker
|
||||
* @param number Leg's position in race
|
||||
*/
|
||||
public Leg(String name, Marker start, Marker end, int number) {
|
||||
public Leg(String name, CompoundMarker start, CompoundMarker end, int number) {
|
||||
this.name = name;
|
||||
this.startMarker = start;
|
||||
this.endMarker = end;
|
||||
this.startCompoundMarker = start;
|
||||
this.endCompoundMarker = end;
|
||||
this.legNumber = number;
|
||||
calculateDistance();
|
||||
}
|
||||
@@ -69,20 +69,20 @@ public class Leg {
|
||||
}
|
||||
|
||||
|
||||
public Marker getStartMarker() {
|
||||
return startMarker;
|
||||
public CompoundMarker getStartCompoundMarker() {
|
||||
return startCompoundMarker;
|
||||
}
|
||||
|
||||
public void setStartMarker(Marker startMarker) {
|
||||
this.startMarker = startMarker;
|
||||
public void setStartCompoundMarker(CompoundMarker startCompoundMarker) {
|
||||
this.startCompoundMarker = startCompoundMarker;
|
||||
}
|
||||
|
||||
public Marker getEndMarker() {
|
||||
return endMarker;
|
||||
public CompoundMarker getEndCompoundMarker() {
|
||||
return endCompoundMarker;
|
||||
}
|
||||
|
||||
public void setEndMarker(Marker endMarker) {
|
||||
this.endMarker = endMarker;
|
||||
public void setEndCompoundMarker(CompoundMarker endCompoundMarker) {
|
||||
this.endCompoundMarker = endCompoundMarker;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,8 +92,8 @@ public class Leg {
|
||||
|
||||
GeodeticCalculator calc = new GeodeticCalculator();
|
||||
//Load start and end of leg
|
||||
GPSCoordinate startMarker = this.startMarker.getAverageGPSCoordinate();
|
||||
GPSCoordinate endMarker = this.endMarker.getAverageGPSCoordinate();
|
||||
GPSCoordinate startMarker = this.startCompoundMarker.getAverageGPSCoordinate();
|
||||
GPSCoordinate endMarker = this.endCompoundMarker.getAverageGPSCoordinate();
|
||||
calc.setStartingGeographicPoint(startMarker.getLongitude(), startMarker.getLatitude());
|
||||
calc.setDestinationGeographicPoint(endMarker.getLongitude(), endMarker.getLatitude());
|
||||
this.distance = calc.getOrthodromicDistance() / Constants.NMToMetersConversion;
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package seng302.Model;
|
||||
|
||||
/**
|
||||
* Created by cbt24 on 10/05/17.
|
||||
*/
|
||||
public class Mark {
|
||||
private String name;
|
||||
|
||||
public Mark(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
@@ -216,17 +216,17 @@ public class Race implements Runnable {
|
||||
public void initialiseBoats() {
|
||||
Leg officialStart = legs.get(0);
|
||||
String name = officialStart.getName();
|
||||
Marker endMarker = officialStart.getEndMarker();
|
||||
CompoundMarker endCompoundMarker = officialStart.getEndCompoundMarker();
|
||||
|
||||
ArrayList<Marker> startMarkers = getSpreadStartingPositions();
|
||||
ArrayList<CompoundMarker> startCompoundMarkers = getSpreadStartingPositions();
|
||||
for (int i = 0; i < startingBoats.size(); i++) {
|
||||
Boat boat = startingBoats.get(i);
|
||||
if (boat != null) {
|
||||
boat.setScaledVelocity(boat.getVelocity() * scaleFactor);
|
||||
Leg startLeg = new Leg(name, 0);
|
||||
boat.setCurrentPosition(startMarkers.get(i).getAverageGPSCoordinate());
|
||||
startLeg.setStartMarker(startMarkers.get(i));
|
||||
startLeg.setEndMarker(endMarker);
|
||||
boat.setCurrentPosition(startCompoundMarkers.get(i).getAverageGPSCoordinate());
|
||||
startLeg.setStartCompoundMarker(startCompoundMarkers.get(i));
|
||||
startLeg.setEndCompoundMarker(endCompoundMarker);
|
||||
startLeg.calculateDistance();
|
||||
boat.setCurrentLeg(startLeg);
|
||||
boat.setHeading(boat.calculateHeading());
|
||||
@@ -239,27 +239,27 @@ public class Race implements Runnable {
|
||||
*
|
||||
* @return list of starting positions
|
||||
*/
|
||||
public ArrayList<Marker> getSpreadStartingPositions() {
|
||||
public ArrayList<CompoundMarker> getSpreadStartingPositions() {
|
||||
|
||||
int nBoats = startingBoats.size();
|
||||
Marker marker = legs.get(0).getStartMarker();
|
||||
CompoundMarker compoundMarker = legs.get(0).getStartCompoundMarker();
|
||||
|
||||
GeodeticCalculator initialCalc = new GeodeticCalculator();
|
||||
initialCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||
initialCalc.setDestinationGeographicPoint(marker.getMark2().getLongitude(), marker.getMark2().getLatitude());
|
||||
initialCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude());
|
||||
initialCalc.setDestinationGeographicPoint(compoundMarker.getMark2().getLongitude(), compoundMarker.getMark2().getLatitude());
|
||||
|
||||
double azimuth = initialCalc.getAzimuth();
|
||||
double distanceBetweenMarkers = initialCalc.getOrthodromicDistance();
|
||||
double distanceBetweenBoats = distanceBetweenMarkers / (nBoats + 1);
|
||||
|
||||
GeodeticCalculator positionCalc = new GeodeticCalculator();
|
||||
positionCalc.setStartingGeographicPoint(marker.getMark1().getLongitude(), marker.getMark1().getLatitude());
|
||||
ArrayList<Marker> positions = new ArrayList<>();
|
||||
positionCalc.setStartingGeographicPoint(compoundMarker.getMark1().getLongitude(), compoundMarker.getMark1().getLatitude());
|
||||
ArrayList<CompoundMarker> positions = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < nBoats; i++) {
|
||||
positionCalc.setDirection(azimuth, distanceBetweenBoats);
|
||||
Point2D position = positionCalc.getDestinationGeographicPoint();
|
||||
positions.add(new Marker(new GPSCoordinate(position.getY(), position.getX())));
|
||||
positions.add(new CompoundMarker(new GPSCoordinate(position.getY(), position.getX())));
|
||||
|
||||
positionCalc = new GeodeticCalculator();
|
||||
positionCalc.setStartingGeographicPoint(position);
|
||||
@@ -302,7 +302,7 @@ public class Race implements Runnable {
|
||||
//update boat's distance travelled
|
||||
boat.setDistanceTravelledInLeg(totalDistanceTravelled);
|
||||
//Calculate boat's new position by adding the distance travelled onto the start point of the leg
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartMarker().getAverageGPSCoordinate(),
|
||||
boat.setCurrentPosition(calculatePosition(boat.getCurrentLeg().getStartCompoundMarker().getAverageGPSCoordinate(),
|
||||
totalDistanceTravelled, boat.calculateAzimuth()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
<leg>
|
||||
<name>Start to Mark 1</name>
|
||||
<start>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.296577</latitude>
|
||||
<longitude>-64.854304</longitude>
|
||||
@@ -57,29 +57,29 @@
|
||||
<latitude>32.293771</latitude>
|
||||
<longitude>-64.855242</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Mark 1 to Leeward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
@@ -88,13 +88,13 @@
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Leeward Gate to Windward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
@@ -103,10 +103,10 @@
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
<longitude>-64.850045</longitude>
|
||||
@@ -115,13 +115,13 @@
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Windward Gate to Leeward Gate</name>
|
||||
<start>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
<longitude>-64.850045</longitude>
|
||||
@@ -130,10 +130,10 @@
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
@@ -142,13 +142,13 @@
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</finish>
|
||||
</leg>
|
||||
<leg>
|
||||
<name>Leeward Gate to Finish</name>
|
||||
<start>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
<longitude>-64.835249</longitude>
|
||||
@@ -157,10 +157,10 @@
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</start>
|
||||
<finish>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<coordinate>
|
||||
<latitude>32.317379</latitude>
|
||||
<longitude>-64.839291</longitude>
|
||||
@@ -169,7 +169,7 @@
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</finish>
|
||||
</leg>
|
||||
</legs>
|
||||
@@ -220,7 +220,7 @@
|
||||
<longitude>-64.849184</longitude>
|
||||
</coordinate>
|
||||
</boundaries>
|
||||
<marker>
|
||||
<compoundMark>
|
||||
<name>Start Line</name>
|
||||
<coordinate>
|
||||
<latitude>32.296577</latitude>
|
||||
@@ -230,15 +230,15 @@
|
||||
<latitude>32.293771</latitude>
|
||||
<longitude>-64.855242</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
</compoundMark>
|
||||
<compoundMark>
|
||||
<name>Mark</name>
|
||||
<coordinate>
|
||||
<latitude>32.293039</latitude>
|
||||
<longitude>-64.843983</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
</compoundMark>
|
||||
<compoundMark>
|
||||
<name>Windward Gate</name>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
@@ -248,8 +248,8 @@
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
</compoundMark>
|
||||
<compoundMark>
|
||||
<name>Leeward Gate</name>
|
||||
<coordinate>
|
||||
<latitude>32.309693</latitude>
|
||||
@@ -259,8 +259,8 @@
|
||||
<latitude>32.308046</latitude>
|
||||
<longitude>-64.831785</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
</compoundMark>
|
||||
<compoundMark>
|
||||
<name>Windward Gate</name>
|
||||
<coordinate>
|
||||
<latitude>32.284680</latitude>
|
||||
@@ -270,8 +270,8 @@
|
||||
<latitude>32.280164</latitude>
|
||||
<longitude>-64.847591</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
<marker>
|
||||
</compoundMark>
|
||||
<compoundMark>
|
||||
<name>Finish Line</name>
|
||||
<coordinate>
|
||||
<latitude>32.317379</latitude>
|
||||
@@ -281,6 +281,6 @@
|
||||
<latitude>32.317257</latitude>
|
||||
<longitude>-64.836260</longitude>
|
||||
</coordinate>
|
||||
</marker>
|
||||
</compoundMark>
|
||||
</course>
|
||||
</race>
|
||||
|
||||
Reference in New Issue
Block a user