summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2014-03-15 16:54:34 +0100
committerSven Gothel <[email protected]>2014-03-15 16:54:34 +0100
commit101567f5f16d91a13c8067764d5e14eefb2b9936 (patch)
treedd53040810d4728182962a6a6dc6ae96427741cf /src/test
parent06fbb390d28bc247945931699e1d59bdd76230c6 (diff)
FloatUtil/VectorUtil: Enhance isEqual/compare w/ and w/o epsilon, add unit tests - Cleanup VectorUtil (vec2/3 naming, remove dedundant functions)
Diffstat (limited to 'src/test')
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java236
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/math/TestQuaternion01NOUI.java104
2 files changed, 286 insertions, 54 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java
index 370cb4a2f..aeceff981 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java
@@ -28,6 +28,10 @@
package com.jogamp.opengl.test.junit.jogl.math;
+
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.FixMethodOrder;
import org.junit.runners.MethodSorters;
@@ -38,11 +42,239 @@ import com.jogamp.opengl.math.FloatUtil;
public class TestFloatUtil01NOUI {
static final float MACH_EPSILON = FloatUtil.getMachineEpsilon();
- @Test
- public void test01Epsilon() {
+ static boolean deltaMachEpsLEQEpsilon;
+ static boolean deltaFixedEpsLEQEpsilon;
+
+ @BeforeClass
+ public static void test00Epsilon() {
+ System.err.println();
System.err.println("Machine Epsilon: "+MACH_EPSILON);
System.err.println("Fixed Epsilon: "+FloatUtil.EPSILON+", diff "+Math.abs(MACH_EPSILON-FloatUtil.EPSILON));
+ System.err.println("Float MIN: "+Float.MIN_VALUE);
+
+ final float deltaMachEpsMin = Math.abs(MACH_EPSILON-Float.MIN_VALUE);
+ deltaMachEpsLEQEpsilon = FloatUtil.compare(deltaMachEpsMin, MACH_EPSILON) <= 0;
+
+ final float deltaFixedEpsMin = Math.abs(MACH_EPSILON-Float.MIN_VALUE);
+ deltaFixedEpsLEQEpsilon = FloatUtil.compare(deltaFixedEpsMin, MACH_EPSILON) <= 0;
+
+ System.err.println("deltaMachEpsMin "+deltaMachEpsMin+", deltaMachEpsLEQEpsilon "+deltaMachEpsLEQEpsilon);
+ System.err.println("deltaFixedEpsMin "+deltaFixedEpsMin+", deltaFixedEpsLEQEpsilon "+deltaFixedEpsLEQEpsilon);
+ }
+
+ private void dumpTestWE(int tstNum, int expWE, final float a, final float b, final float EPSILON) {
+ final float delta = a-b;
+ final boolean equalWE = FloatUtil.isEqual(a, b, EPSILON);
+ final int compWE = FloatUtil.compare(a, b, EPSILON);
+ final String msgWE = ( expWE != compWE ) ? "**** mismatch ****" : " OK";
+ System.err.println("Print.WE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", exp "+expWE+", equal "+equalWE+", comp "+compWE+" - "+msgWE+", epsilon "+EPSILON);
+ }
+ private void dumpTestNE(int tstNum, int exp, final float a, final float b) {
+ final float delta = a-b;
+ final boolean equal = FloatUtil.isEqual(a, b);
+ final int comp = FloatUtil.compare(a, b);
+ final String msg = ( exp != comp ) ? "**** mismatch ****" : " OK";
+ System.err.println("Print.NE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", exp "+exp+", equal "+equal+", comp "+comp+" - "+msg);
+ }
+
+ @Test
+ public void test01aZeroWithFixedEpsilon() {
+ testZeroWithEpsilon(10, FloatUtil.EPSILON);
+ }
+ @Test
+ public void test01bZeroWithMachEpsilon() {
+ testZeroWithEpsilon(100, MACH_EPSILON);
+ }
+ private void testZeroWithEpsilon(int i, final float EPSILON) {
+ System.err.println();
+ testZeroWithEpsilon(i++, true, 0f, EPSILON);
+ testZeroWithEpsilon(i++, true, 0f-EPSILON/2f, EPSILON);
+ testZeroWithEpsilon(i++, true, 0f+EPSILON/2f, EPSILON);
+ testZeroWithEpsilon(i++, true, 0f-Float.MIN_VALUE, EPSILON);
+ testZeroWithEpsilon(i++, true, 0f+Float.MIN_VALUE, EPSILON);
+ testZeroWithEpsilon(i++, true, -0f, EPSILON);
+ testZeroWithEpsilon(i++, true, +0f, EPSILON);
+
+ testZeroWithEpsilon(i++, false, 0f+EPSILON+Float.MIN_VALUE, EPSILON);
+ testZeroWithEpsilon(i++, false, 0f-EPSILON-Float.MIN_VALUE, EPSILON);
+
+ // Unpredicted .. accuracy beyond epsilon, or deltaMachEpsLEQEpsilon or deltaFixedEpsLEQEpsilon;
+ dumpTestWE(i++, 1, 0f, 0f+EPSILON-Float.MIN_VALUE, EPSILON);
+ dumpTestWE(i++, 1, 0f, 0f-EPSILON+Float.MIN_VALUE, EPSILON);
+ }
+ private void testZeroWithEpsilon(int tstNum, boolean exp, final float a, final float EPSILON) {
+ final boolean zero = FloatUtil.isZero(a, EPSILON);
+ final float delta = a-0f;
+ System.err.println("Zero."+tstNum+": a: "+a+", -> d "+delta+", exp "+exp+", zero "+zero+", epsilon "+EPSILON);
+ Assert.assertEquals("Zero failed a: "+a+" within "+EPSILON, exp, zero);
+ }
+
+ @Test
+ public void test02EqualsNoEpsilon() {
+ int i=0;
+ System.err.println();
+ testEqualsNoEpsilon(i++, true, 0f, 0f);
+
+ testEqualsNoEpsilon(i++, true, Float.MAX_VALUE, Float.MAX_VALUE);
+ testEqualsNoEpsilon(i++, true, Float.MIN_VALUE, Float.MIN_VALUE);
+ testEqualsNoEpsilon(i++, true, Float.MIN_NORMAL, Float.MIN_NORMAL);
+ testEqualsNoEpsilon(i++, true, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
+ testEqualsNoEpsilon(i++, true, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
+ testEqualsNoEpsilon(i++, true, Float.NaN, Float.NaN);
+ testEqualsNoEpsilon(i++, false, -0f, 0f);
+ testEqualsNoEpsilon(i++, false, 0f, -0f);
+
+ // Unpredicted .. accuracy beyond epsilon, or deltaMachEpsLEQEpsilon or deltaFixedEpsLEQEpsilon;
+ dumpTestNE(i++, 0, 1f, 1f-MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 0f, 0f-MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 1f, 1f+MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 0f, 0f+MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 1f, 1f-Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 0f, 0f-Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 1f, 1f+Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 0f, 0f+Float.MIN_VALUE);
+ }
+ private void testEqualsNoEpsilon(int tstNum, boolean exp, final float a, final float b) {
+ final boolean equal = FloatUtil.isEqual(a, b);
+ final int comp = FloatUtil.compare(a, b);
+ final float delta = a-b;
+ System.err.println("Equal.NE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", exp "+exp+", equal "+equal+", comp "+comp);
+ Assert.assertEquals("Compare failed a: "+a+", b: "+b, exp, 0==comp);
+ Assert.assertEquals("Equal failed a: "+a+", b: "+b, exp, equal);
+ }
+
+ @Test
+ public void test03aEqualsWithFixedEpsilon() {
+ testEqualsWithEpsilon(10, FloatUtil.EPSILON);
}
+ @Test
+ public void test03bEqualsWithMachEpsilon() {
+ testEqualsWithEpsilon(50, MACH_EPSILON);
+ }
+ private void testEqualsWithEpsilon(int i, final float EPSILON) {
+ System.err.println();
+ testEqualsWithEpsilon(i++, true, 0f, 0f, EPSILON);
+ testEqualsWithEpsilon(i++, true, 1f, 1f-EPSILON/2f, EPSILON);
+ testEqualsWithEpsilon(i++, true, 1f, 1f+EPSILON/2f, EPSILON);
+ testEqualsWithEpsilon(i++, true, 1f, 1f-Float.MIN_VALUE, EPSILON);
+ testEqualsWithEpsilon(i++, true, 1f, 1f+Float.MIN_VALUE, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.MAX_VALUE, Float.MAX_VALUE, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.MIN_VALUE, Float.MIN_VALUE, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.MIN_NORMAL, Float.MIN_NORMAL, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, EPSILON);
+ testEqualsWithEpsilon(i++, true, Float.NaN, Float.NaN, EPSILON);
+ testEqualsWithEpsilon(i++, true, -0f, 0f, EPSILON);
+ testEqualsWithEpsilon(i++, true, 0f, -0f, EPSILON);
+
+ testEqualsWithEpsilon(i++, false, 1f, 1f+EPSILON+Float.MIN_VALUE, EPSILON);
+ testEqualsWithEpsilon(i++, false, 1f, 1f-EPSILON-Float.MIN_VALUE, EPSILON);
+
+ // Unpredicted .. accuracy beyond epsilon, or deltaMachEpsLEQEpsilon or deltaFixedEpsLEQEpsilon;
+ dumpTestWE(i++, 1, 1f, 1f+EPSILON-Float.MIN_VALUE, EPSILON);
+ dumpTestWE(i++, 1, 1f, 1f-EPSILON+Float.MIN_VALUE, EPSILON);
+ }
+ private void testEqualsWithEpsilon(int tstNum, boolean exp, final float a, final float b, final float EPSILON) {
+ final boolean equal = FloatUtil.isEqual(a, b, EPSILON);
+ final int comp = FloatUtil.compare(a, b, EPSILON);
+ final float delta = a-b;
+ System.err.println("Equal.WE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", exp "+exp+", equal "+equal+", comp "+comp);
+ Assert.assertEquals("Compare failed a: "+a+", b: "+b+" within "+EPSILON, exp, 0==comp);
+ Assert.assertEquals("Equal failed a: "+a+", b: "+b+" within "+EPSILON, exp, equal);
+ }
+
+ @Test
+ public void test04CompareNoEpsilon() {
+ int i=0;
+ System.err.println();
+ testCompareNoEpsilon(i++, 0, 0f, 0f);
+ testCompareNoEpsilon(i++, 0, Float.MAX_VALUE, Float.MAX_VALUE);
+ testCompareNoEpsilon(i++, 0, Float.MIN_VALUE, Float.MIN_VALUE);
+ testCompareNoEpsilon(i++, 0, Float.MIN_NORMAL, Float.MIN_NORMAL);
+ testCompareNoEpsilon(i++, 0, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY);
+ testCompareNoEpsilon(i++, 0, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY);
+ testCompareNoEpsilon(i++, 0, Float.NaN, Float.NaN);
+
+ testCompareNoEpsilon(i++, 1, 1f, 0f);
+ testCompareNoEpsilon(i++, -1, 0f, 1f);
+ testCompareNoEpsilon(i++, 1, 0f, -1f);
+ testCompareNoEpsilon(i++, -1, -1f, 0f);
+
+ testCompareNoEpsilon(i++, 1, Float.MAX_VALUE, Float.MIN_VALUE);
+ testCompareNoEpsilon(i++, -1, Float.MIN_VALUE, Float.MAX_VALUE);
+ testCompareNoEpsilon(i++, 1, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY);
+ testCompareNoEpsilon(i++, -1, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY);
+
+ testCompareNoEpsilon(i++, -1, 0f, Float.NaN);
+ testCompareNoEpsilon(i++, 1, Float.NaN, 0f);
+
+ testCompareNoEpsilon(i++, -1, -0f, 0f);
+ testCompareNoEpsilon(i++, 1, 0f, -0f);
+
+ // Unpredicted .. accuracy beyond epsilon, or deltaMachEpsLEQEpsilon or deltaFixedEpsLEQEpsilon;
+ dumpTestNE(i++, 0, 1f, 1f-MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 0f, 0f-MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 1f, 1f+MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 0f, 0f+MACH_EPSILON/2f);
+ dumpTestNE(i++, 0, 1f, 1f-Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 0f, 0f-Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 1f, 1f+Float.MIN_VALUE);
+ dumpTestNE(i++, 0, 0f, 0f+Float.MIN_VALUE);
+ }
+ private void testCompareNoEpsilon(int tstNum, final int exp, final float a, final float b) {
+ final boolean equal = FloatUtil.isEqual(a, b);
+ final int comp = FloatUtil.compare(a, b);
+ final float delta = a-b;
+ System.err.println("Comp.NE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", equal "+equal+", comp: exp "+exp+" has "+comp);
+ Assert.assertEquals("Compare failed a: "+a+", b: "+b, exp, comp);
+ }
+
+ @Test
+ public void test05aCompareWithFixedEpsilon() {
+ test05CompareWithEpsilon(10, FloatUtil.EPSILON);
+ }
+ @Test
+ public void test05bCompareWithMachEpsilon() {
+ test05CompareWithEpsilon(50, MACH_EPSILON);
+ }
+ private void test05CompareWithEpsilon(int i, final float EPSILON) {
+ System.err.println();
+ testCompareWithEpsilon(i++, 0, 0f, 0f, EPSILON);
+ testCompareWithEpsilon(i++, 0, 1f, 1f-EPSILON/2f, EPSILON);
+ testCompareWithEpsilon(i++, 0, 1f, 1f+EPSILON/2f, EPSILON);
+ testCompareWithEpsilon(i++, 0, 1f, 1f-Float.MIN_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, 0, 1f, 1f+Float.MIN_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.MAX_VALUE, Float.MAX_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.MIN_VALUE, Float.MIN_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.MIN_NORMAL, Float.MIN_NORMAL, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, EPSILON);
+ testCompareWithEpsilon(i++, 0, Float.NaN, Float.NaN, EPSILON);
+
+ testCompareWithEpsilon(i++, 1, 1f, 0f, EPSILON);
+ testCompareWithEpsilon(i++, -1, 0f, 1f, EPSILON);
+ testCompareWithEpsilon(i++, 1, 0f, -1f, EPSILON);
+ testCompareWithEpsilon(i++, -1, -1f, 0f, EPSILON);
+
+ testCompareWithEpsilon(i++, 1, Float.MAX_VALUE, Float.MIN_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, -1, Float.MIN_VALUE, Float.MAX_VALUE, EPSILON);
+ testCompareWithEpsilon(i++, 1, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, EPSILON);
+ testCompareWithEpsilon(i++, -1, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, EPSILON);
+
+ testCompareWithEpsilon(i++, -1, 0f,Float.NaN, EPSILON);
+ testCompareWithEpsilon(i++, 1, Float.NaN, 0f, EPSILON);
+
+ testCompareWithEpsilon(i++, 0, -0f, 0f, EPSILON);
+ testCompareWithEpsilon(i++, 0, 0f, -0f, EPSILON);
+ }
+ private void testCompareWithEpsilon(int tstNum, final int exp, final float a, final float b, float EPSILON) {
+ final boolean equal = FloatUtil.isEqual(a, b, EPSILON);
+ final int comp = FloatUtil.compare(a, b, EPSILON);
+ final float delta = a-b;
+ System.err.println("Comp.WE."+tstNum+": a: "+a+", b: "+b+" -> d "+delta+", equal "+equal+", comp: exp "+exp+" has "+comp);
+ Assert.assertEquals("Compare failed a: "+a+", b: "+b+" within "+EPSILON, exp, comp);
+ }
+
public static void main(String args[]) {
org.junit.runner.JUnitCore.main(TestFloatUtil01NOUI.class.getName());
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestQuaternion01NOUI.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestQuaternion01NOUI.java
index 0f47f5889..19758539b 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/math/TestQuaternion01NOUI.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/TestQuaternion01NOUI.java
@@ -123,10 +123,10 @@ public class TestQuaternion01NOUI {
quat1.rotateVector(vecOut1, 0, ONE, 0);
quat2.rotateVector(vecOut2, 0, ONE, 0);
Assert.assertArrayEquals(vecOut1, vecOut2, FloatUtil.EPSILON);
- Assert.assertEquals(0f, Math.abs( VectorUtil.distance(vecOut1, vecOut2) ), FloatUtil.EPSILON );
+ Assert.assertEquals(0f, Math.abs( VectorUtil.vec3Distance(vecOut1, vecOut2) ), FloatUtil.EPSILON );
quat1.rotateVector(vecOut1, 0, UNIT_Z, 0);
- Assert.assertEquals(0f, Math.abs( VectorUtil.distance(NEG_UNIT_Y, vecOut1) ), FloatUtil.EPSILON );
+ Assert.assertEquals(0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Y, vecOut1) ), FloatUtil.EPSILON );
quat2.setFromAngleAxis(FloatUtil.HALF_PI, ZERO, tmpV3f);
Assert.assertEquals(QUAT_IDENT, quat2);
@@ -159,19 +159,19 @@ public class TestQuaternion01NOUI {
quat.setFromVectors(UNIT_Z, NEG_UNIT_Z, tmp0V3f, tmp1V3f);
quat.rotateVector(vecOut, 0, UNIT_Z, 0);
// System.err.println("vecOut: "+Arrays.toString(vecOut));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_Z, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Z, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
quat.setFromVectors(UNIT_X, NEG_UNIT_X, tmp0V3f, tmp1V3f);
quat.rotateVector(vecOut, 0, UNIT_X, 0);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
quat.setFromVectors(UNIT_Y, NEG_UNIT_Y, tmp0V3f, tmp1V3f);
quat.rotateVector(vecOut, 0, UNIT_Y, 0);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_Y, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Y, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
quat.setFromVectors(ONE, NEG_ONE, tmp0V3f, tmp1V3f);
quat.rotateVector(vecOut, 0, ONE, 0);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_ONE, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_ONE, vecOut) ), Quaternion.ALLOWED_DEVIANCE );
quat.setFromVectors(ZERO, ZERO, tmp0V3f, tmp1V3f);
Assert.assertEquals(QUAT_IDENT, quat);
@@ -230,17 +230,17 @@ public class TestQuaternion01NOUI {
Assert.assertEquals(1.0f, quat.magnitude(), FloatUtil.EPSILON);
final float[] v2 = quat.rotateVector(new float[3], 0, UNIT_X, 0);
- Assert.assertEquals(0f, Math.abs(VectorUtil.distance(NEG_UNIT_Z, v2)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs(VectorUtil.vec3Distance(NEG_UNIT_Z, v2)), FloatUtil.EPSILON);
quat.setFromEuler(0, 0, -FloatUtil.HALF_PI);
Assert.assertEquals(1.0f, quat.magnitude(), FloatUtil.EPSILON);
quat.rotateVector(v2, 0, UNIT_X, 0);
- Assert.assertEquals(0f, Math.abs(VectorUtil.distance(NEG_UNIT_Y, v2)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs(VectorUtil.vec3Distance(NEG_UNIT_Y, v2)), FloatUtil.EPSILON);
quat.setFromEuler(FloatUtil.HALF_PI, 0, 0);
Assert.assertEquals(1.0f, quat.magnitude(), FloatUtil.EPSILON);
quat.rotateVector(v2, 0, UNIT_Y, 0);
- Assert.assertEquals(0f, Math.abs(VectorUtil.distance(UNIT_Z, v2)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs(VectorUtil.vec3Distance(UNIT_Z, v2)), FloatUtil.EPSILON);
}
@Test
@@ -278,13 +278,13 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, UNIT_Y, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(UNIT_Z, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(UNIT_Z, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
}
quat.setFromMatrix(mat1, 0);
quat.rotateVector(vecHas, 0, UNIT_Y, 0);
// System.err.println("exp0 "+Arrays.toString(UNIT_Z));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(UNIT_Z, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(UNIT_Z, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
quat.toMatrix(mat2, 0);
// System.err.println(FloatUtil.matrixToString(null, null, "%10.5f", mat1, 0, mat2, 0, 4, 4, false).toString());
@@ -292,7 +292,7 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, NEG_ONE, 0);
FloatUtil.multMatrixVecf(mat2, NEG_ONE_v4, vecOut2);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
//
// 180 degrees rotation on X
@@ -312,13 +312,13 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, UNIT_Y, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_Y, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Y, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
}
quat.setFromMatrix(mat1, 0);
quat.rotateVector(vecHas, 0, UNIT_Y, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_Y));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_Y, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Y, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
quat.toMatrix(mat2, 0);
// System.err.println(FloatUtil.matrixToString(null, null, "%10.5f", mat1, 0, mat2, 0, 4, 4, false).toString());
@@ -326,7 +326,7 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, ONE, 0);
FloatUtil.multMatrixVecf(mat2, ONE_v4, vecOut2);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
//
// 180 degrees rotation on Y
@@ -346,13 +346,13 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
}
quat.setFromMatrix(mat1, 0);
quat.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
quat.toMatrix(mat2, 0);
// System.err.println(FloatUtil.matrixToString(null, "matr-rot", "%10.5f", mat1, 0, mat2, 0, 4, 4, false).toString());
@@ -360,7 +360,7 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, NEG_ONE, 0);
FloatUtil.multMatrixVecf(mat2, NEG_ONE_v4, vecOut2);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
//
// 180 degrees rotation on Z
@@ -380,13 +380,13 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
}
quat.setFromMatrix(mat1, 0);
quat.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecHas) ), Quaternion.ALLOWED_DEVIANCE );
quat.toMatrix(mat2, 0);
// System.err.println(FloatUtil.matrixToString(null, "matr-rot", "%10.5f", mat1, 0, mat2, 0, 4, 4, false).toString());
@@ -394,7 +394,7 @@ public class TestQuaternion01NOUI {
quat.rotateVector(vecHas, 0, ONE, 0);
FloatUtil.multMatrixVecf(mat2, ONE_v4, vecOut2);
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecHas, vecOut2) ), Quaternion.ALLOWED_DEVIANCE );
//
// Test Matrix-Columns
@@ -413,19 +413,19 @@ public class TestQuaternion01NOUI {
quat.copyMatrixColumn(0, vecCol, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp));
// System.err.println("has0 "+Arrays.toString(vecCol));
- Assert.assertEquals(0f, Math.abs( VectorUtil.distance(vecExp, vecCol)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs( VectorUtil.vec3Distance(vecExp, vecCol)), FloatUtil.EPSILON);
FloatUtil.copyMatrixColumn(mat1, 0, 1, vecExp, 0);
quat.copyMatrixColumn(1, vecCol, 0);
// System.err.println("exp1 "+Arrays.toString(vecExp));
// System.err.println("has1 "+Arrays.toString(vecCol));
- Assert.assertEquals(0f, Math.abs( VectorUtil.distance(vecExp, vecCol)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs( VectorUtil.vec3Distance(vecExp, vecCol)), FloatUtil.EPSILON);
FloatUtil.copyMatrixColumn(mat1, 0, 2, vecExp, 0);
quat.copyMatrixColumn(2, vecCol, 0);
// System.err.println("exp2 "+Arrays.toString(vecExp));
// System.err.println("has2 "+Arrays.toString(vecCol));
- Assert.assertEquals(0f, Math.abs( VectorUtil.distance(vecExp, vecCol)), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, Math.abs( VectorUtil.vec3Distance(vecExp, vecCol)), FloatUtil.EPSILON);
quat.set(0f, 0f, 0f, 0f);
Assert.assertArrayEquals(UNIT_X, quat.copyMatrixColumn(0, vecCol, 0), FloatUtil.EPSILON);
@@ -563,18 +563,18 @@ public class TestQuaternion01NOUI {
final float[] vecOut = new float[3];
quat2.rotateVector(vecOut, 0, UNIT_Z, 0);
- Assert.assertTrue( Math.abs( VectorUtil.distance(UNIT_X, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertTrue( Math.abs( VectorUtil.vec3Distance(UNIT_X, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
quat2.setFromAngleNormalAxis(FloatUtil.HALF_PI, UNIT_Y); // 90 degr on Y
quat1.mult(quat1); // q1 = q1 * q1 -> 2 * 45 degr -> 90 degr on Y
quat1.mult(quat2); // q1 = q1 * q2 -> 2 * 90 degr -> 180 degr on Y
quat1.rotateVector(vecOut, 0, UNIT_Z, 0);
- Assert.assertTrue( Math.abs( VectorUtil.distance(NEG_UNIT_Z, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertTrue( Math.abs( VectorUtil.vec3Distance(NEG_UNIT_Z, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
quat2.setFromEuler(0f, FloatUtil.HALF_PI, 0f);
quat1.mult(quat2); // q1 = q1 * q2 = q1 * rotMat(0, 90degr, 0)
quat1.rotateVector(vecOut, 0, UNIT_Z, 0);
- Assert.assertTrue( Math.abs( VectorUtil.distance(NEG_UNIT_X, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertTrue( Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecOut)) <= Quaternion.ALLOWED_DEVIANCE);
}
@Test
@@ -645,7 +645,7 @@ public class TestQuaternion01NOUI {
// put together matrix, then apply to vector, so YZX
worker.rotateByAngleY(FloatUtil.QUARTER_PI).rotateByAngleZ(FloatUtil.PI).rotateByAngleX(FloatUtil.HALF_PI);
quat.rotateVector(vecExp, 0, vecExp, 0);
- Assert.assertEquals(0f, VectorUtil.distance(vecExp, vecRot), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(vecExp, vecRot), FloatUtil.EPSILON);
// test axis rotation methods against general purpose
// X AXIS
@@ -655,7 +655,7 @@ public class TestQuaternion01NOUI {
worker.setIdentity().rotateByAngleNormalAxis(FloatUtil.QUARTER_PI, 1f, 0f, 0f).rotateVector(vecRot, 0, vecRot, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp)+", len "+VectorUtil.length(vecExp));
// System.err.println("has0 "+Arrays.toString(vecRot)+", len "+VectorUtil.length(vecRot));
- Assert.assertEquals(0f, VectorUtil.distance(vecExp, vecRot), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(vecExp, vecRot), FloatUtil.EPSILON);
// Y AXIS
vecExp = new float[] { 1f, 1f, 1f };
@@ -664,7 +664,7 @@ public class TestQuaternion01NOUI {
worker.setIdentity().rotateByAngleNormalAxis(FloatUtil.QUARTER_PI, 0f, 1f, 0f).rotateVector(vecRot, 0, vecRot, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp));
// System.err.println("has0 "+Arrays.toString(vecRot));
- Assert.assertEquals(0f, VectorUtil.distance(vecExp, vecRot), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(vecExp, vecRot), FloatUtil.EPSILON);
// Z AXIS
vecExp = new float[] { 1f, 1f, 1f };
@@ -673,7 +673,7 @@ public class TestQuaternion01NOUI {
worker.setIdentity().rotateByAngleNormalAxis(FloatUtil.QUARTER_PI, 0f, 0f, 1f).rotateVector(vecRot, 0, vecRot, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp));
// System.err.println("has0 "+Arrays.toString(vecRot));
- Assert.assertEquals(0f, VectorUtil.distance(vecExp, vecRot), FloatUtil.EPSILON);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(vecExp, vecRot), FloatUtil.EPSILON);
quat.set(worker);
worker.rotateByAngleNormalAxis(0f, 0f, 0f, 0f);
@@ -716,7 +716,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_Z, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecExp, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecExp, vecHas)), Quaternion.ALLOWED_DEVIANCE);
// delta == 100%
quat2.setIdentity().rotateByAngleZ(FloatUtil.PI); // angle: 180 degrees, axis Z
@@ -725,7 +725,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(NEG_UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(NEG_UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(NEG_UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
quat2.setIdentity().rotateByAngleZ(FloatUtil.PI); // angle: 180 degrees, axis Z
// System.err.println("Slerp #03: 1/2 * 180 degrees Z");
@@ -733,7 +733,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(UNIT_Y));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(UNIT_Y, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(UNIT_Y, vecHas)), Quaternion.ALLOWED_DEVIANCE);
// delta == 0%
quat2.setIdentity().rotateByAngleZ(FloatUtil.PI); // angle: 180 degrees, axis Z
@@ -742,7 +742,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
// a==b
quat2.setIdentity();
@@ -751,7 +751,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_X, 0);
// System.err.println("exp0 "+Arrays.toString(UNIT_X));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(UNIT_X, vecHas)), Quaternion.ALLOWED_DEVIANCE);
// negative dot product
vecExp = new float[] { 0f, -FloatUtil.sin(FloatUtil.QUARTER_PI), FloatUtil.sin(FloatUtil.QUARTER_PI) };
@@ -762,7 +762,7 @@ public class TestQuaternion01NOUI {
quatS.rotateVector(vecHas, 0, UNIT_Y, 0);
// System.err.println("exp0 "+Arrays.toString(vecExp));
// System.err.println("has0 "+Arrays.toString(vecHas));
- Assert.assertEquals( 0f, Math.abs( VectorUtil.distance(vecExp, vecHas)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals( 0f, Math.abs( VectorUtil.vec3Distance(vecExp, vecHas)), Quaternion.ALLOWED_DEVIANCE);
}
@@ -778,37 +778,37 @@ public class TestQuaternion01NOUI {
if( DEBUG ) System.err.println("LookAt #01");
VectorUtil.copyVec3(direction, 0, NEG_UNIT_X, 0);
final Quaternion quat = new Quaternion().setLookAt(direction, UNIT_Y, xAxis, yAxis, zAxis);
- Assert.assertEquals(0f, VectorUtil.distance(direction, quat.rotateVector(vecHas, 0, UNIT_Z, 0)), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(direction, quat.rotateVector(vecHas, 0, UNIT_Z, 0)), Quaternion.ALLOWED_DEVIANCE);
if( DEBUG ) System.err.println("LookAt #02");
- VectorUtil.normalize(VectorUtil.copyVec3(direction, 0, ONE, 0));
+ VectorUtil.normalizeVec3(VectorUtil.copyVec3(direction, 0, ONE, 0));
quat.setLookAt(direction, UNIT_Y, xAxis, yAxis, zAxis);
if( DEBUG )System.err.println("quat0 "+quat);
quat.rotateVector(vecHas, 0, UNIT_Z, 0);
if( DEBUG ) {
- System.err.println("xAxis "+Arrays.toString(xAxis)+", len "+VectorUtil.length(xAxis));
- System.err.println("yAxis "+Arrays.toString(yAxis)+", len "+VectorUtil.length(yAxis));
- System.err.println("zAxis "+Arrays.toString(zAxis)+", len "+VectorUtil.length(zAxis));
- System.err.println("exp0 "+Arrays.toString(direction)+", len "+VectorUtil.length(direction));
- System.err.println("has0 "+Arrays.toString(vecHas)+", len "+VectorUtil.length(vecHas));
+ System.err.println("xAxis "+Arrays.toString(xAxis)+", len "+VectorUtil.vec3Length(xAxis));
+ System.err.println("yAxis "+Arrays.toString(yAxis)+", len "+VectorUtil.vec3Length(yAxis));
+ System.err.println("zAxis "+Arrays.toString(zAxis)+", len "+VectorUtil.vec3Length(zAxis));
+ System.err.println("exp0 "+Arrays.toString(direction)+", len "+VectorUtil.vec3Length(direction));
+ System.err.println("has0 "+Arrays.toString(vecHas)+", len "+VectorUtil.vec3Length(vecHas));
}
// Assert.assertEquals(0f, VectorUtil.distance(direction, quat.rotateVector(vecHas, 0, UNIT_Z, 0)), Quaternion.ALLOWED_DEVIANCE);
- Assert.assertEquals(0f, VectorUtil.distance(direction, vecHas), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(direction, vecHas), Quaternion.ALLOWED_DEVIANCE);
if( DEBUG )System.err.println("LookAt #03");
- VectorUtil.normalize(VectorUtil.copyVec3(direction, 0, new float[] { -1f, 2f, -1f }, 0));
+ VectorUtil.normalizeVec3(VectorUtil.copyVec3(direction, 0, new float[] { -1f, 2f, -1f }, 0));
quat.setLookAt(direction, UNIT_Y, xAxis, yAxis, zAxis);
if( DEBUG )System.err.println("quat0 "+quat);
quat.rotateVector(vecHas, 0, UNIT_Z, 0);
if( DEBUG ) {
- System.err.println("xAxis "+Arrays.toString(xAxis)+", len "+VectorUtil.length(xAxis));
- System.err.println("yAxis "+Arrays.toString(yAxis)+", len "+VectorUtil.length(yAxis));
- System.err.println("zAxis "+Arrays.toString(zAxis)+", len "+VectorUtil.length(zAxis));
- System.err.println("exp0 "+Arrays.toString(direction)+", len "+VectorUtil.length(direction));
- System.err.println("has0 "+Arrays.toString(vecHas)+", len "+VectorUtil.length(vecHas));
+ System.err.println("xAxis "+Arrays.toString(xAxis)+", len "+VectorUtil.vec3Length(xAxis));
+ System.err.println("yAxis "+Arrays.toString(yAxis)+", len "+VectorUtil.vec3Length(yAxis));
+ System.err.println("zAxis "+Arrays.toString(zAxis)+", len "+VectorUtil.vec3Length(zAxis));
+ System.err.println("exp0 "+Arrays.toString(direction)+", len "+VectorUtil.vec3Length(direction));
+ System.err.println("has0 "+Arrays.toString(vecHas)+", len "+VectorUtil.vec3Length(vecHas));
}
// Assert.assertEquals(0f, VectorUtil.distance(direction, quat.rotateVector(vecHas, 0, UNIT_Z, 0)), Quaternion.ALLOWED_DEVIANCE);
- Assert.assertEquals(0f, VectorUtil.distance(direction, vecHas), Quaternion.ALLOWED_DEVIANCE);
+ Assert.assertEquals(0f, VectorUtil.vec3Distance(direction, vecHas), Quaternion.ALLOWED_DEVIANCE);
}
public static void main(String args[]) {