Fixed WindCommand not updating downwind command when moving upwind.
#story[1096]
This commit is contained in:
@@ -12,12 +12,10 @@ public class WindCommand implements Command {
|
|||||||
private MockBoat boat;
|
private MockBoat boat;
|
||||||
private int direction;
|
private int direction;
|
||||||
|
|
||||||
private double offset = 3.0;
|
|
||||||
|
|
||||||
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
public WindCommand(MockRace race, MockBoat boat, boolean upwind) {
|
||||||
this.race = race;
|
this.race = race;
|
||||||
this.boat = boat;
|
this.boat = boat;
|
||||||
this.direction = upwind? 1 : -1;
|
this.direction = upwind? -1 : 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -25,7 +23,11 @@ public class WindCommand implements Command {
|
|||||||
double wind = race.getWindDirection().degrees();
|
double wind = race.getWindDirection().degrees();
|
||||||
double heading = boat.getBearing().degrees();
|
double heading = boat.getBearing().degrees();
|
||||||
|
|
||||||
if(wind - heading < 0) offset *= -1 * direction;
|
double offset = 3.0;
|
||||||
|
|
||||||
|
offset *= direction;
|
||||||
|
if(wind - heading < 0) offset *= -1;
|
||||||
|
|
||||||
boat.setBearing(Bearing.fromDegrees(heading + offset));
|
boat.setBearing(Bearing.fromDegrees(heading + offset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,12 +47,12 @@ public class WindCommandTest {
|
|||||||
@Test
|
@Test
|
||||||
public void upwindCommandDecreasesAngle() {
|
public void upwindCommandDecreasesAngle() {
|
||||||
upwind.execute();
|
upwind.execute();
|
||||||
assertEquals(initial - boat.getBearing().degrees(), offset, 1e-5);
|
assertEquals(initial - boat.getBearing().degrees(), -offset, 1e-5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void downwindCommandIncreasesAngle() {
|
public void downwindCommandIncreasesAngle() {
|
||||||
downwind.execute();
|
downwind.execute();
|
||||||
assertEquals(boat.getBearing().degrees() - initial, offset, 1e-5);
|
assertEquals(initial - boat.getBearing().degrees(), offset, 1e-5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user