From 0ffabf1419ab39a88eb7de35e8f34bdb185ddfbb Mon Sep 17 00:00:00 2001 From: Christoph Dietze Date: Tue, 12 Feb 2013 22:10:04 +0100 Subject: [PATCH] mirrorAngle(HALF_PI) should be -HALFPI rather than HALF_PI --- src/main/java/pythagoras/f/MathUtil.java | 2 +- src/test/java/pythagoras/f/MathUtilTest.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/test/java/pythagoras/f/MathUtilTest.java diff --git a/src/main/java/pythagoras/f/MathUtil.java b/src/main/java/pythagoras/f/MathUtil.java index 3cf325e..133df38 100644 --- a/src/main/java/pythagoras/f/MathUtil.java +++ b/src/main/java/pythagoras/f/MathUtil.java @@ -169,7 +169,7 @@ public class MathUtil * Returns the mirror angle of the specified angle (assumed to be in [-pi, +pi]). */ public static float mirrorAngle (float a) { - return (a > 0f ? FloatMath.PI : -FloatMath.PI) - a; + return a + (a > 0f ? -FloatMath.PI : FloatMath.PI); } /** diff --git a/src/test/java/pythagoras/f/MathUtilTest.java b/src/test/java/pythagoras/f/MathUtilTest.java new file mode 100644 index 0000000..5111d8a --- /dev/null +++ b/src/test/java/pythagoras/f/MathUtilTest.java @@ -0,0 +1,19 @@ +// +// Pythagoras - a collection of geometry classes +// http://github.com/samskivert/pythagoras + +package pythagoras.f; + +import org.junit.*; +import static org.junit.Assert.*; + +/** + * Tests parts of the {@link MathUtil} class. + */ +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); + } +}