Mock.Race:

Fixed an issue in updatePositions(...) where unconstrained bounds could be passed into the calculateVMG function (e.g., lower = -182391, upper = 188221), but they need to be in the interval [0, 360).

Mock.Polars:
Added more test cases. Still working on getting the assertions correct.
Refactored and bugfixed the calculateVMG(...) function. There were a few bugs (and ugly "fixes") because we didn't bother enforcing a strict interval on the lower and upper bound angles.
Also added a few more comments to explain the function better.

#story[873]
This commit is contained in:
fjc40
2017-05-15 18:39:38 +12:00
parent 12b6f49f2e
commit 656212d06d
4 changed files with 201 additions and 78 deletions
@@ -45,7 +45,7 @@ public class PolarsTest {
double calcVMGAngle1 = calcVMG1.getBearing();
double calcVMGSpeed1 = calcVMG1.getSpeed();
System.out.println("VMG speed = " + calcVMGSpeed1 + " , VMG angle = " + calcVMGAngle1);//TEMP DEBUG REMOVE
System.out.println("Test 1 VMG speed = " + calcVMGSpeed1 + " , VMG angle = " + calcVMGAngle1);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle1, vmgAngle1, angleEpsilon);
@@ -64,7 +64,8 @@ public class PolarsTest {
double calcVMGAngle2 = calcVMG2.getBearing();
double calcVMGSpeed2 = calcVMG2.getSpeed();
System.out.println("VMG speed = " + calcVMGSpeed2 + " , VMG angle = " + calcVMGAngle2);//TEMP DEBUG REMOVE
System.out.println("Test 2 VMG speed = " + calcVMGSpeed2 + " , VMG angle = " + calcVMGAngle2);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle2, vmgAngle2, angleEpsilon);
@@ -83,7 +84,7 @@ public class PolarsTest {
double calcVMGAngle3 = calcVMG3.getBearing();
double calcVMGSpeed3 = calcVMG3.getSpeed();
System.out.println("VMG speed = " + calcVMGSpeed3 + " , VMG angle = " + calcVMGAngle3);//TEMP DEBUG REMOVE
System.out.println("Test 3 VMG speed = " + calcVMGSpeed3 + " , VMG angle = " + calcVMGAngle3);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle3, vmgAngle3, angleEpsilon);
@@ -102,12 +103,107 @@ public class PolarsTest {
double calcVMGAngle4 = calcVMG4.getBearing();
double calcVMGSpeed4 = calcVMG4.getSpeed();
System.out.println("VMG speed = " + calcVMGSpeed4 + " , VMG angle = " + calcVMGAngle4);//TEMP DEBUG REMOVE
System.out.println("Test 4 VMG speed = " + calcVMGSpeed4 + " , VMG angle = " + calcVMGAngle4);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle4, vmgAngle4, angleEpsilon);
//assertEquals(calcVMGSpeed4, vmgSpeed4, speedEpsilon);
//Test 5.
//This test has a bearing bound of [55, 70), which only contains a suboptimal VMG.
double windAngle5 = 5;//TODO
double destAngle5 = 100;
double windSpeed5 = 9;//knots
double vmgAngle5 = 88;
double vmgSpeed5 = 12;
double bearingUpperBound5 = 70;
double bearingLowerBound5 = 55;
VMG calcVMG5 = polars.calculateVMG(windAngle5, windSpeed5, destAngle5, bearingLowerBound5, bearingUpperBound5);
double calcVMGAngle5 = calcVMG5.getBearing();
double calcVMGSpeed5 = calcVMG5.getSpeed();
System.out.println("Test 5 VMG speed = " + calcVMGSpeed5 + " , VMG angle = " + calcVMGAngle5);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle5, vmgAngle5, angleEpsilon);
//assertEquals(calcVMGSpeed5, vmgSpeed5, speedEpsilon);
//assertTrue(calcVMGAngle5 >= bearingLowerBound5);
//assertTrue(calcVMGAngle5 < bearingUpperBound5);
//Test 6.
//This test has a bearing bound of [70, 55), which has a lower bound > upper bound, which is complementary to [55, 70).
double windAngle6 = 5;//TODO
double destAngle6 = 100;
double windSpeed6 = 11;//knots
double vmgAngle6 = 88;
double vmgSpeed6 = 12;
double bearingUpperBound6 = 55;
double bearingLowerBound6 = 70;
VMG calcVMG6 = polars.calculateVMG(windAngle6, windSpeed6, destAngle6, bearingLowerBound6, bearingUpperBound6);
double calcVMGAngle6 = calcVMG6.getBearing();
double calcVMGSpeed6 = calcVMG6.getSpeed();
System.out.println("Test 6 VMG speed = " + calcVMGSpeed6 + " , VMG angle = " + calcVMGAngle6);//TEMP DEBUG REMOVE
//assertEquals(calcVMGAngle6, vmgAngle6, angleEpsilon);
//assertEquals(calcVMGSpeed6, vmgSpeed6, speedEpsilon);
if (bearingLowerBound6 > bearingUpperBound6) {
assertTrue((calcVMGAngle6 >= bearingLowerBound6) || (calcVMGAngle6 <= bearingUpperBound6));
} else {
assertTrue(calcVMGAngle6 >= bearingLowerBound6);
assertTrue(calcVMGAngle6 < bearingUpperBound6);
}
//Test 7.
//This test has a bearing bound of [340, 5), which has a lower bound > upper bound, which is complementary to [5, 340).
double windAngle7 = 340;
double destAngle7 = 30;
double windSpeed7 = 7;//knots
double vmgAngle7 = 5;
double vmgSpeed7 = 11;
double bearingUpperBound7 = 5;
double bearingLowerBound7 = 340;
VMG calcVMG7 = polars.calculateVMG(windAngle7, windSpeed7, destAngle7, bearingLowerBound7, bearingUpperBound7);
double calcVMGAngle7 = calcVMG7.getBearing();
double calcVMGSpeed7 = calcVMG7.getSpeed();
assertEquals(calcVMGAngle7, vmgAngle7, angleEpsilon);
assertEquals(calcVMGSpeed7, vmgSpeed7, speedEpsilon);
if (bearingLowerBound7 > bearingUpperBound7) {
assertTrue((calcVMGAngle7 >= bearingLowerBound7) || (calcVMGAngle7 <= bearingUpperBound7));
} else {
assertTrue(calcVMGAngle7 >= bearingLowerBound7);
assertTrue(calcVMGAngle7 < bearingUpperBound7);
}
//Test 8.
//This test has a bearing bound of [340, 5), which has a lower bound > upper bound, which is complementary to [5, 340). Due to the wind, dest angles, and bearing bounds, it cannot actually find a VMG > 0 (valid VMGs will actually be in the angle interval [10, 190]), so it will return the VMG(angle=0, speed=0).
double windAngle8 = 5;
double destAngle8 = 100;
double windSpeed8 = 7;//knots
double vmgAngle8 = 0;
double vmgSpeed8 = 0;
double bearingUpperBound8 = 5;
double bearingLowerBound8 = 340;
VMG calcVMG8 = polars.calculateVMG(windAngle8, windSpeed8, destAngle8, bearingLowerBound8, bearingUpperBound8);
double calcVMGAngle8 = calcVMG8.getBearing();
double calcVMGSpeed8 = calcVMG8.getSpeed();
assertEquals(calcVMGAngle8, vmgAngle8, 0);
assertEquals(calcVMGSpeed8, vmgSpeed8, 0);
}
}