diff options
author | Sven Gothel <[email protected]> | 2023-09-03 08:31:24 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2023-09-03 08:31:24 +0200 |
commit | 47233ea7014e34adca8a5c1d2323a57e9de1c7fa (patch) | |
tree | 8911ce16673237d6c6c568a5e4a68874c4ccb877 /src/test | |
parent | e6087583dc06c823f54bb6206af2acb0e2119b4c (diff) |
FloatUtil.isEqual(..): Rename raw {isEqual->isEqualRaw}(a,b) varianr w/o EPSILON; Add isEqual(a,b) w/ default EPSILON; Use it where applicable
Also add isEqual2(a,b) w/o corner cases (NaN, Inf) used for comparison in Graph Outline, OutlineShape and later GraphUI Shape.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java | 4 | ||||
-rw-r--r-- | src/test/com/jogamp/opengl/test/junit/jogl/math/TestFloatUtil01NOUI.java | 70 |
2 files changed, 37 insertions, 37 deletions
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java b/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java index 83ecf7380..feb9b6f46 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/math/Matrix4fb.java @@ -977,13 +977,13 @@ public class Matrix4fb { public final Matrix4fb setToRotation(final Quaternion q) { // pre-multiply scaled-reciprocal-magnitude to reduce multiplications final float norm = q.magnitudeSquared(); - if ( FloatUtil.isZero(norm, FloatUtil.EPSILON) ) { + if ( FloatUtil.isZero(norm) ) { // identity matrix -> srecip = 0f loadIdentity(); return this; } final float srecip; - if ( FloatUtil.isEqual(1f, norm, FloatUtil.EPSILON) ) { + if ( FloatUtil.isEqual(1f, norm) ) { srecip = 2f; } else { srecip = 2.0f / norm; 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 909b94a90..1c2b32fcb 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 @@ -72,7 +72,7 @@ public class TestFloatUtil01NOUI extends JunitTracer { }
private void dumpTestNE(final int tstNum, final int exp, final float a, final float b) {
final float delta = a-b;
- final boolean equal = FloatUtil.isEqual(a, b);
+ final boolean equal = FloatUtil.isEqualRaw(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);
@@ -136,7 +136,7 @@ public class TestFloatUtil01NOUI extends JunitTracer { dumpTestNE(i++, 0, 0f, 0f+Float.MIN_VALUE);
}
private void testEqualsNoEpsilon(final int tstNum, final boolean exp, final float a, final float b) {
- final boolean equal = FloatUtil.isEqual(a, b);
+ final boolean equal = FloatUtil.isEqualRaw(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);
@@ -223,7 +223,7 @@ public class TestFloatUtil01NOUI extends JunitTracer { dumpTestNE(i++, 0, 0f, 0f+Float.MIN_VALUE);
}
private void testCompareNoEpsilon(final int tstNum, final int exp, final float a, final float b) {
- final boolean equal = FloatUtil.isEqual(a, b);
+ final boolean equal = FloatUtil.isEqualRaw(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);
@@ -238,42 +238,42 @@ public class TestFloatUtil01NOUI extends JunitTracer { public void test05bCompareWithMachEpsilon() {
test05CompareWithEpsilon(50, MACH_EPSILON);
}
- private void test05CompareWithEpsilon(int i, final float 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);
+ 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(final int tstNum, final int 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);
+ private void testCompareWithEpsilon(final int tstNum, final int 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("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);
+ Assert.assertEquals("Compare failed a: "+a+", b: "+b+" within "+epsilon, exp, comp);
}
|