Change new mirrorAngle to mirrorAngleOrigin, improved javadocs.
The old mirrorAngle mirrors around the "y-axis" (PI/2 or -PI/2 as appropriate) which is necessary for other code (particularly angularDifference) to work correctly. The new mirrorAngleOrigin mirrors around the "x-axis" (zero).
This commit is contained in:
@@ -166,9 +166,20 @@ public class MathUtil
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]).
|
||||
* Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]). The angle is
|
||||
* mirrored around the PI/2 if it is positive, and -PI/2 if it is negative. One can visualize
|
||||
* this as mirroring around the "y-axis".
|
||||
*/
|
||||
public static float mirrorAngle (float a) {
|
||||
return (a > 0f ? FloatMath.PI : -FloatMath.PI) - a;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]). The angle is
|
||||
* mirrored around the origin (zero degrees). One can visualize this as mirroring around the
|
||||
* "x-axis".
|
||||
*/
|
||||
public static float mirrorAngleOrigin (float a) {
|
||||
return a + (a > 0f ? -FloatMath.PI : FloatMath.PI);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,27 @@ import static org.junit.Assert.*;
|
||||
*/
|
||||
public class MathUtilTest
|
||||
{
|
||||
@Test public void testMirrorAngle() {
|
||||
assertEquals(-MathUtil.HALF_PI, MathUtil.mirrorAngle(MathUtil.HALF_PI), MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.HALF_PI, MathUtil.mirrorAngle(-MathUtil.HALF_PI), MathUtil.EPSILON);
|
||||
public static final float PI = FloatMath.PI;
|
||||
public static final float PI2 = FloatMath.PI/2;
|
||||
public static final float PI4 = FloatMath.PI/4;
|
||||
public static final float PI8 = FloatMath.PI/8;
|
||||
|
||||
@Test public void testLerpa() {
|
||||
assertEquals(MathUtil.lerpa(PI4, -PI4, 0.25f), PI8, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(PI4, -PI4, 0.75f), -PI8, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(-PI4, PI4, 0.25f), -PI8, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(-PI4, PI4, 0.75f), PI8, MathUtil.EPSILON);
|
||||
// make sure we lerp the shortest route around the circle
|
||||
assertEquals(MathUtil.lerpa(3*PI4, PI4, 0.5f), PI2, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(PI4, 3*PI4, 0.5f), PI2, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(-3*PI4, -PI4, 0.5f), -PI2, MathUtil.EPSILON);
|
||||
assertEquals(MathUtil.lerpa(-PI4, -3*PI4, 0.5f), -PI2, MathUtil.EPSILON);
|
||||
|
||||
assertEquals(MathUtil.lerpa(3*PI4, -3*PI4, 0.5f), -PI, MathUtil.EPSILON);
|
||||
}
|
||||
|
||||
@Test public void testMirrorAngleOrigin() {
|
||||
assertEquals(-PI2, MathUtil.mirrorAngleOrigin(PI2), MathUtil.EPSILON);
|
||||
assertEquals(PI2, MathUtil.mirrorAngleOrigin(-PI2), MathUtil.EPSILON);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user