aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/com')
-rw-r--r--src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java2
-rw-r--r--src/jogl/classes/com/jogamp/graph/geom/Outline.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java34
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java4
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Quaternion.java16
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Vec2f.java11
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Vec3f.java12
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/Vec4f.java13
-rw-r--r--src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java12
9 files changed, 84 insertions, 22 deletions
diff --git a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
index 1a1bd94dd..644f428cd 100644
--- a/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
+++ b/src/jogl/classes/com/jogamp/graph/curve/OutlineShape.java
@@ -1060,7 +1060,7 @@ public final class OutlineShape implements Comparable<OutlineShape> {
public final int compareTo(final OutlineShape other) {
final float thisSize = getBounds().getSize();
final float otherSize = other.getBounds().getSize();
- if( FloatUtil.isEqual(thisSize, otherSize, FloatUtil.EPSILON) ) {
+ if( FloatUtil.isEqual2(thisSize, otherSize) ) {
return 0;
} else if( thisSize < otherSize ){
return -1;
diff --git a/src/jogl/classes/com/jogamp/graph/geom/Outline.java b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
index a0999baa1..654bd2636 100644
--- a/src/jogl/classes/com/jogamp/graph/geom/Outline.java
+++ b/src/jogl/classes/com/jogamp/graph/geom/Outline.java
@@ -318,7 +318,7 @@ public class Outline implements Comparable<Outline> {
public final int compareTo(final Outline other) {
final float thisSize = getBounds().getSize();
final float otherSize = other.getBounds().getSize();
- if( FloatUtil.isEqual(thisSize, otherSize, FloatUtil.EPSILON) ) {
+ if( FloatUtil.isEqual2(thisSize, otherSize) ) {
return 0;
} else if(thisSize < otherSize){
return -1;
diff --git a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
index 004562767..34a581681 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/FloatUtil.java
@@ -1422,7 +1422,7 @@ public final class FloatUtil {
* </p>
* @see #isEqual(float, float, float)
*/
- public static boolean isEqual(final float a, final float b) {
+ public static boolean isEqualRaw(final float a, final float b) {
// Values are equal (Inf, Nan .. )
return Float.floatToIntBits(a) == Float.floatToIntBits(b);
}
@@ -1449,6 +1449,38 @@ public final class FloatUtil {
}
/**
+ * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}.
+ * <p>
+ * Implementation considers following corner cases:
+ * <ul>
+ * <li>NaN == NaN</li>
+ * <li>+Inf == +Inf</li>
+ * <li>-Inf == -Inf</li>
+ * </ul>
+ * </p>
+ * @see #EPSILON
+ */
+ public static boolean isEqual(final float a, final float b) {
+ if ( Math.abs(a - b) < EPSILON ) {
+ return true;
+ } else {
+ // Values are equal (Inf, Nan .. )
+ return Float.floatToIntBits(a) == Float.floatToIntBits(b);
+ }
+ }
+
+ /**
+ * Return true if both values are equal, i.e. their absolute delta < {@link #EPSILON}.
+ * <p>
+ * Implementation does not consider corner cases like {@link #isEqual(float, float, float)}.
+ * </p>
+ * @see #EPSILON
+ */
+ public static boolean isEqual2(final float a, final float b) {
+ return Math.abs(a - b) < EPSILON;
+ }
+
+ /**
* Return true if both values are equal w/o regarding an epsilon.
* <p>
* Implementation considers following corner cases:
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
index 77971b72d..5d1d8e968 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Matrix4f.java
@@ -1125,13 +1125,13 @@ public class Matrix4f {
public final Matrix4f 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/jogl/classes/com/jogamp/opengl/math/Quaternion.java b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
index 9548a160a..be09d03af 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Quaternion.java
@@ -90,10 +90,10 @@ public class Quaternion {
*/
public final float magnitude() {
final float magnitudeSQ = magnitudeSquared();
- if ( FloatUtil.isZero(magnitudeSQ, FloatUtil.EPSILON) ) {
+ if ( FloatUtil.isZero(magnitudeSQ) ) {
return 0f;
}
- if ( FloatUtil.isEqual(1f, magnitudeSQ, FloatUtil.EPSILON) ) {
+ if ( FloatUtil.isEqual(1f, magnitudeSQ) ) {
return 1f;
}
return FloatUtil.sqrt(magnitudeSQ);
@@ -149,13 +149,13 @@ public class Quaternion {
* Returns <code>true</code> if this quaternion has identity.
* <p>
* Implementation uses {@link FloatUtil#EPSILON epsilon} to compare
- * {@link #w() W} {@link FloatUtil#isEqual(float, float, float) against 1f} and
+ * {@link #w() W} {@link FloatUtil#isEqual(float, float) against 1f} and
* {@link #x() X}, {@link #y() Y} and {@link #z() Z}
- * {@link FloatUtil#isZero(float, float) against zero}.
+ * {@link FloatUtil#isZero(float) against zero}.
* </p>
*/
public final boolean isIdentity() {
- return FloatUtil.isEqual(1f, w, FloatUtil.EPSILON) && VectorUtil.isZero(x, y, z, FloatUtil.EPSILON);
+ return FloatUtil.isEqual(1f, w) && VectorUtil.isZero(x, y, z);
// return w == 1f && x == 0f && y == 0f && z == 0f;
}
@@ -217,7 +217,7 @@ public class Quaternion {
*/
public final Quaternion invert() {
final float magnitudeSQ = magnitudeSquared();
- if ( FloatUtil.isEqual(1.0f, magnitudeSQ, FloatUtil.EPSILON) ) {
+ if ( FloatUtil.isEqual(1.0f, magnitudeSQ) ) {
conjugate();
} else {
final float invmsq = 1f/magnitudeSQ;
@@ -1025,12 +1025,12 @@ public class Quaternion {
public final float[] toMatrix(final float[] matrix) {
// pre-multiply scaled-reciprocal-magnitude to reduce multiplications
final float norm = magnitudeSquared();
- if ( FloatUtil.isZero(norm, FloatUtil.EPSILON) ) {
+ if ( FloatUtil.isZero(norm) ) {
// identity matrix -> srecip = 0f
return FloatUtil.makeIdentity(matrix);
}
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/jogl/classes/com/jogamp/opengl/math/Vec2f.java b/src/jogl/classes/com/jogamp/opengl/math/Vec2f.java
index d733aca5d..f504b960b 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Vec2f.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Vec2f.java
@@ -349,7 +349,7 @@ public final class Vec2f {
}
/**
- * Equals check using {@link FloatUtil#EPSILON} value and {@link FloatUtil#isEqual(float, float, float)}.
+ * Equals check using {@link FloatUtil#EPSILON} in {@link FloatUtil#isEqual(float, float)}.
* <p>
* Implementation considers following corner cases:
* <ul>
@@ -361,13 +361,18 @@ public final class Vec2f {
* @return true if all components differ less than {@link FloatUtil#EPSILON}, otherwise false.
*/
public boolean isEqual(final Vec2f o) {
- return isEqual(o, FloatUtil.EPSILON);
+ if( this == o ) {
+ return true;
+ } else {
+ return FloatUtil.isEqual(x, o.x) &&
+ FloatUtil.isEqual(y, o.y);
+ }
}
@Override
public boolean equals(final Object o) {
if( o instanceof Vec2f ) {
- return isEqual((Vec2f)o, FloatUtil.EPSILON);
+ return isEqual((Vec2f)o);
} else {
return false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Vec3f.java b/src/jogl/classes/com/jogamp/opengl/math/Vec3f.java
index 34f13adbe..7012edd74 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Vec3f.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Vec3f.java
@@ -367,7 +367,7 @@ public final class Vec3f {
}
/**
- * Equals check using {@link FloatUtil#EPSILON} value and {@link FloatUtil#isEqual(float, float, float)}.
+ * Equals check using {@link FloatUtil#EPSILON} in {@link FloatUtil#isEqual(float, float)}.
* <p>
* Implementation considers following corner cases:
* <ul>
@@ -379,13 +379,19 @@ public final class Vec3f {
* @return true if all components differ less than {@link FloatUtil#EPSILON}, otherwise false.
*/
public boolean isEqual(final Vec3f o) {
- return isEqual(o, FloatUtil.EPSILON);
+ if( this == o ) {
+ return true;
+ } else {
+ return FloatUtil.isEqual(x, o.x) &&
+ FloatUtil.isEqual(y, o.y) &&
+ FloatUtil.isEqual(z, o.z);
+ }
}
@Override
public boolean equals(final Object o) {
if( o instanceof Vec3f ) {
- return isEqual((Vec3f)o, FloatUtil.EPSILON);
+ return isEqual((Vec3f)o);
} else {
return false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/math/Vec4f.java b/src/jogl/classes/com/jogamp/opengl/math/Vec4f.java
index a5276c7f1..914450bf1 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/Vec4f.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/Vec4f.java
@@ -356,7 +356,7 @@ public final class Vec4f {
}
/**
- * Equals check using {@link FloatUtil#EPSILON} value and {@link FloatUtil#isEqual(float, float, float)}.
+ * Equals check using {@link FloatUtil#EPSILON} in {@link FloatUtil#isEqual(float, float)}.
* <p>
* Implementation considers following corner cases:
* <ul>
@@ -368,13 +368,20 @@ public final class Vec4f {
* @return true if all components differ less than {@link FloatUtil#EPSILON}, otherwise false.
*/
public boolean isEqual(final Vec4f o) {
- return isEqual(o, FloatUtil.EPSILON);
+ if( this == o ) {
+ return true;
+ } else {
+ return FloatUtil.isEqual(x, o.x) &&
+ FloatUtil.isEqual(y, o.y) &&
+ FloatUtil.isEqual(z, o.z) &&
+ FloatUtil.isEqual(w, o.w);
+ }
}
@Override
public boolean equals(final Object o) {
if( o instanceof Vec4f ) {
- return isEqual((Vec4f)o, FloatUtil.EPSILON);
+ return isEqual((Vec4f)o);
} else {
return false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
index d3b2c3cfd..e38501c73 100644
--- a/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/math/VectorUtil.java
@@ -52,6 +52,18 @@ public final class VectorUtil {
}
/**
+ * Return true if all three vector components are zero, i.e. it's their absolute value < {@link FloatUtil#EPSILON}.
+ * <p>
+ * Implementation uses {@link FloatUtil#isZero(float)}, see API doc for details.
+ * </p>
+ */
+ public static boolean isZero(final float x, final float y, final float z) {
+ return FloatUtil.isZero(x) &&
+ FloatUtil.isZero(y) &&
+ FloatUtil.isZero(z) ;
+ }
+
+ /**
* Return the squared distance between the given two points described vector v1 and v2.
* <p>
* When comparing the relative distance between two points it is usually sufficient to compare the squared