Created a setWind(bearing, knots) in Race, which updates the Wind with new values.

MockRace now uses Wind.
VisualiserRace now uses Wind.
#story[1093]
main
fjc40 9 years ago
parent 5af3053537
commit 99f3310d8b

@ -99,10 +99,8 @@ public class MockRace extends Race {
this.shrinkBoundary = GPSCoordinate.getShrinkBoundary(this.boundary); this.shrinkBoundary = GPSCoordinate.getShrinkBoundary(this.boundary);
//Wind.
this.windSpeed = 12; this.setWind(Bearing.fromDegrees(180), 12);
this.windDirection = Bearing.fromDegrees(180);
} }
@ -288,8 +286,8 @@ public class MockRace extends Race {
//Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class. //Convert wind direction and speed to ints. //TODO this conversion should be done inside the racestatus class.
int windDirectionInt = AC35UnitConverter.encodeHeading(this.windDirection.degrees()); int windDirectionInt = AC35UnitConverter.encodeHeading(this.getWindDirection().degrees());
int windSpeedInt = (int) (this.windSpeed * Constants.KnotsToMMPerSecond); int windSpeedInt = (int) (this.getWindSpeed() * Constants.KnotsToMMPerSecond);
//Create race status object, and send it. //Create race status object, and send it.
RaceStatus raceStatus = new RaceStatus( RaceStatus raceStatus = new RaceStatus(
@ -576,7 +574,12 @@ public class MockRace extends Race {
//Find the VMG inside these bounds. //Find the VMG inside these bounds.
VMG bestVMG = boat.getPolars().calculateVMG(this.windDirection, this.windSpeed, boat.calculateBearingToNextMarker(), lowerAcceptableBound, upperAcceptableBound); VMG bestVMG = boat.getPolars().calculateVMG(
this.getWindDirection(),
this.getWindSpeed(),
boat.calculateBearingToNextMarker(),
lowerAcceptableBound,
upperAcceptableBound);
return bestVMG; return bestVMG;
@ -884,7 +887,9 @@ public class MockRace extends Race {
*/ */
protected void initialiseWindDirection() { protected void initialiseWindDirection() {
//Set the starting bearing. //Set the starting bearing.
this.windDirection = Bearing.fromDegrees(MockRace.windBaselineBearing.degrees()); this.setWind(
Bearing.fromDegrees(MockRace.windBaselineBearing.degrees()),
this.getWindSpeed() );
} }
@ -892,28 +897,34 @@ public class MockRace extends Race {
* Changes the wind direction randomly, while keeping it within [windLowerBound, windUpperBound]. * Changes the wind direction randomly, while keeping it within [windLowerBound, windUpperBound].
*/ */
protected void changeWindDirection() { protected void changeWindDirection() {
//TODO this wind generation could probably be moved to its own object?
//Randomly add or remove 0.5 degrees. //Randomly add or remove 0.5 degrees.
int r = new Random().nextInt(changeWind) + 1; int r = new Random().nextInt(changeWind) + 1;
double newWindBearingDegrees = this.getWindDirection().degrees();
if (r == 1) { if (r == 1) {
//Add 0.5 degrees to the wind bearing. //Add 0.5 degrees to the wind bearing.
this.windDirection.setDegrees(this.windDirection.degrees() + 0.5); newWindBearingDegrees += 0.5;
} else if (r == 2) { } else if (r == 2) {
//Minus 0.5 degrees from the wind bearing. //Minus 0.5 degrees from the wind bearing.
this.windDirection.setDegrees(this.windDirection.degrees() - 0.5); newWindBearingDegrees -= 0.5;
} }
//Ensure that the wind is in the correct bounds. //Ensure that the wind is in the correct bounds.
if (this.windDirection.degrees() > MockRace.windUpperBound.degrees()) { if (newWindBearingDegrees > MockRace.windUpperBound.degrees()) {
this.windDirection.setBearing(MockRace.windUpperBound); newWindBearingDegrees = MockRace.windUpperBound.degrees();
} else if (this.windDirection.degrees() < MockRace.windLowerBound.degrees()) { } else if (newWindBearingDegrees < MockRace.windLowerBound.degrees()) {
this.windDirection.setBearing(MockRace.windLowerBound); newWindBearingDegrees = MockRace.windLowerBound.degrees();
} }
this.setWind(
Bearing.fromDegrees(newWindBearingDegrees),
this.getWindSpeed() );
} }

@ -166,8 +166,7 @@ public abstract class Race implements Runnable {
this.raceType = raceDataSource.getRaceType(); this.raceType = raceDataSource.getRaceType();
//Wind. //Wind.
Wind wind = new Wind(Bearing.fromDegrees(0), 0); this.setWind(Bearing.fromDegrees(0), 0);
this.raceWind.setValue(wind);
} }
@ -248,6 +247,18 @@ public abstract class Race implements Runnable {
return regattaName; return regattaName;
} }
/**
* Updates the race to have a specified wind bearing and speed.
* @param windBearing New wind bearing.
* @param windSpeedKnots New wind speed, in knots.
*/
protected void setWind(Bearing windBearing, double windSpeedKnots) {
Wind wind = new Wind(windBearing, windSpeedKnots);
this.raceWind.setValue(wind);
}
/** /**
* Returns the wind bearing. * Returns the wind bearing.
* @return The wind bearing. * @return The wind bearing.

@ -311,11 +311,10 @@ public class VisualiserRace extends Race {
//Race status enum. //Race status enum.
this.raceStatusEnum = RaceStatusEnum.fromByte(raceStatus.getRaceStatus()); this.raceStatusEnum = RaceStatusEnum.fromByte(raceStatus.getRaceStatus());
//Wind bearing. //Wind.
this.windDirection.setDegrees(raceStatus.getScaledWindDirection()); this.setWind(
Bearing.fromDegrees(raceStatus.getScaledWindDirection()),
//Wind speed. raceStatus.getWindSpeedKnots() );
this.windSpeed = raceStatus.getWindSpeedKnots();
//Current race time. //Current race time.
this.raceClock.setUTCTime(raceStatus.getCurrentTime()); this.raceClock.setUTCTime(raceStatus.getCurrentTime());

Loading…
Cancel
Save