The race is rotated with it's initial rotation in mind

- RaceXMLCreator now checks the bearing of the race with getLineAngle()
- Split some methods into functions so that it is more readable
#story[1096]
main
Fan-Wu Yang 8 years ago
parent 2ce1c0786e
commit fef35d0b00

@ -92,11 +92,42 @@ public class RaceXMLCreator {
return null;
}
public static CompoundMark getWindwardGate(RaceXMLReader reader){
for (CompoundMark mark: reader.getCompoundMarks()){
if (mark.getName().equals("Windward Gate")) return mark;
}
return null;
}
public static CompoundMark getLeewardGate(RaceXMLReader reader){
for (CompoundMark mark: reader.getCompoundMarks()){
if (mark.getName().equals("Leeward Gate")) return mark;
}
return null;
}
public static String alterRaceToWind(String s, double degrees) throws XMLReaderException, InvalidRaceDataException, JAXBException {
RaceXMLReader reader = new RaceXMLReader(s, XMLFileType.ResourcePath);
Race race = copyRace(reader);
double raceOriginalBearing = getLineAngle(getLeewardGate(reader).getMark1Position(), getWindwardGate(reader).getMark1Position());
double degreesToRotate = degrees - raceOriginalBearing;
alterRaceRotation(race, degreesToRotate);
JAXBContext context = JAXBContext.newInstance(Race.class);
Marshaller jaxbMarshaller = context.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(race, sw);
return sw.toString();
}
public static void alterRaceRotation(Race race, double degrees){
GPSCoordinate center = getCenter(race);
for(Race.CourseLimit.Limit limit: race.getCourseLimit().getLimit()){
GPSCoordinate rotatedLim = rotate(center, limitToGPSCoordinate(limit), degrees);
@ -112,15 +143,6 @@ public class RaceXMLCreator {
mark.setTargetLng(String.valueOf(rotatedMark.getLongitude()));
}
}
JAXBContext context = JAXBContext.newInstance(Race.class);
Marshaller jaxbMarshaller = context.createMarshaller();
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
jaxbMarshaller.marshal(race, sw);
return sw.toString();
}
public static GPSCoordinate limitToGPSCoordinate(Race.CourseLimit.Limit limit){
@ -152,5 +174,10 @@ public class RaceXMLCreator {
avgLng = avgLng/race.getCourseLimit().getLimit().size();
return new GPSCoordinate(avgLat, avgLng);
}
public static double getLineAngle(GPSCoordinate coord1, GPSCoordinate coord2){
double dx = coord1.getLongitude() - coord2.getLongitude();
double dy = coord1.getLatitude() - coord2.getLatitude();
return Math.atan2(dy, dx)/Math.PI * 180;
}
}

Loading…
Cancel
Save