Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
9e0a85b
PhantomTrianglesTest: initialize the system delegate
stephengold Feb 18, 2021
6b829c6
testcase and fix for issue #1459 (BoundingSphere merge yields NaNs) (…
stephengold Feb 18, 2021
153e3e8
fix issue #1366 (Javadoc not built for jme3-examples)
stephengold Feb 20, 2021
799c59d
test and fix for issue #1469 (initial transform of Joint never cloned)
stephengold Feb 18, 2021
8c534b9
common.gradle: fix for issue #1370 (test classes added to javadoc JARs)
stephengold Feb 25, 2021
e1dc2f6
build.gradle: fix for issue #1370 (test classes added to merged javadoc)
stephengold Feb 25, 2021
3305928
TouchTrigger: resolve issue #1448 (assertion failure in touchHash())
stephengold Feb 26, 2021
44a2433
PhysicsTestHelper: resolve 2 javadoc warnings
stephengold Feb 26, 2021
c322153
LICENSE: include 2021 in the copyright notice
stephengold Feb 26, 2021
7b00c50
main.yml: enable workflow for the new "gsw" branch
stephengold Feb 27, 2021
346ced7
make JBullet the default for jme3-examples (instead of native Bullet)
stephengold Feb 27, 2021
671a90b
eliminate native Bullet from build scripts
stephengold Feb 27, 2021
b5f53f3
delete the glue code for native Bullet
stephengold Feb 27, 2021
b58c6d0
delete makefiles for jme3-bullet-native-android
stephengold Feb 27, 2021
a9332fd
delete Java sourcecode associated with native Bullet
stephengold Feb 27, 2021
fc8128c
[skip ci] update natives snapshot
Feb 27, 2021
eb59aed
iOS gl3 and some improvements (#1473)
joliver82 Mar 11, 2021
13f7921
[skip ci] update natives snapshot
Mar 11, 2021
27ee6e4
TerrainQuad: serialize "patchSize" field. (#1476)
Ali-RS Mar 11, 2021
bb6cc88
[skip ci] update natives snapshot
Mar 11, 2021
bcb73a9
bugfix: "Deploy natives snapshot" step always detects native changes
stephengold Mar 11, 2021
e1c5489
main.yml: correct bash syntax error
stephengold Mar 11, 2021
0a81a61
main.yml: deploy each new natives snapshot to the MinIO instance
stephengold Mar 11, 2021
c86e668
create a new natives snapshot, to test uploading to the MinIO instance
stephengold Mar 11, 2021
ecdf8d6
main.yml: correct name of MinIO bucket
stephengold Mar 12, 2021
b15fa50
[skip ci] update natives snapshot
Mar 12, 2021
efcad1c
gradle.properties: download natives snapshots from the MinIO instance
stephengold Mar 12, 2021
caedc2b
main.yml: don't deploy natives snapshots to Bintray
stephengold Mar 12, 2021
5153c1a
create a new natives snapshot, to test NOT uploading to Bintray
stephengold Mar 12, 2021
eae4de1
[skip ci] update natives snapshot
Mar 12, 2021
202b315
bintray.sh: specify --quiet when using the "wget" command
stephengold Mar 12, 2021
cdb1641
common.gradle: add and configure maven-publish and signing plugins
stephengold Mar 12, 2021
2272bce
main.yml: sign Maven artifacts if possible
stephengold Mar 12, 2021
db06d14
main.yml: deploy the artifacts from each release to Sonatype
stephengold Mar 13, 2021
013aa15
bugfix: published POMs lack documentation
stephengold Mar 13, 2021
8bc22cb
bugfix: artifacts for Sonatype deployment aren't signed
stephengold Mar 13, 2021
8c4d523
Android native sound fix and update openal-soft to 1.21.1 (#1475)
joliver82 Mar 13, 2021
db24141
[skip ci] update natives snapshot
Mar 13, 2021
cf10451
Fix issue #1477 (assertion fails for createIndexBuffer(0, 0)) (#1479)
Ali-RS Mar 14, 2021
4fdee8f
resolve issue #1447 (no setter for EnvironmentCamera background color…
stephengold Mar 15, 2021
d653d6b
main.yml: remove trailing whitespace
stephengold Mar 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
testcase and fix for issue jMonkeyEngine#1459 (BoundingSphere merge y…
…ields NaNs) (jMonkeyEngine#1465)

* testcase and fix for issue jMonkeyEngine#1459 (BoundingSphere merge yields NaNs)

* Vector3f: fix overflow/underflow bugs in length() and distance() methods
  • Loading branch information
stephengold authored Feb 18, 2021
commit 6b829c69e50a5d816dbe8161379fcde2bb0f8e6d
4 changes: 2 additions & 2 deletions jme3-core/src/main/java/com/jme3/bounding/BoundingSphere.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2020 jMonkeyEngine
* Copyright (c) 2009-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -615,7 +615,7 @@ private BoundingVolume merge(float temp_radius, Vector3f temp_center,
if (rCenter == null) {
rVal.setCenter(rCenter = new Vector3f());
}
if (length > RADIUS_EPSILON) {
if (length > RADIUS_EPSILON && Float.isFinite(length)) {
float coeff = (length + radiusDiff) / (2.0f * length);
rCenter.set(center.addLocal(diff.multLocal(coeff)));
} else {
Expand Down
28 changes: 25 additions & 3 deletions jme3-core/src/main/java/com/jme3/math/Vector3f.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2020 jMonkeyEngine
* Copyright (c) 2009-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -435,7 +435,18 @@ public boolean isUnitVector() {
* @return the length or magnitude of the vector.
*/
public float length() {
return FastMath.sqrt(lengthSquared());
/*
* Use double-precision arithmetic to reduce the chance of overflow
* (when lengthSquared > Float.MAX_VALUE) or underflow (when
* lengthSquared is < Float.MIN_VALUE).
*/
double xx = x;
double yy = y;
double zz = z;
double lengthSquared = xx * xx + yy * yy + zz * zz;
float result = (float) Math.sqrt(lengthSquared);

return result;
}

/**
Expand Down Expand Up @@ -470,7 +481,18 @@ public float distanceSquared(Vector3f v) {
* @return the distance between the two vectors.
*/
public float distance(Vector3f v) {
return FastMath.sqrt(distanceSquared(v));
/*
* Use double-precision arithmetic to reduce the chance of overflow
* (when distanceSquared > Float.MAX_VALUE) or underflow (when
* distanceSquared is < Float.MIN_VALUE).
*/
double dx = x - v.x;
double dy = y - v.y;
double dz = z - v.z;
double distanceSquared = dx * dx + dy * dy + dz * dz;
float result = (float) Math.sqrt(distanceSquared);

return result;
}

/**
Expand Down
66 changes: 66 additions & 0 deletions jme3-core/src/test/java/com/jme3/bounding/TestBoundingSphere.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright (c) 2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package com.jme3.bounding;

import com.jme3.math.Vector3f;
import org.junit.Assert;
import org.junit.Test;

/**
* Test cases for the BoundingSphere class.
*
* @author Stephen Gold
*/
public class TestBoundingSphere {

/**
* Verify that an infinite bounding sphere can be merged with a very
* eccentric bounding box without producing NaNs. This was issue #1459 at
* GitHub.
*/
@Test
public void testIssue1459() {
Vector3f boxCenter = new Vector3f(-92f, 3.3194322e29f, 674.89886f);
BoundingBox boundingBox = new BoundingBox(boxCenter,
1.0685959f, 3.3194322e29f, 2.705017f);

Vector3f sphCenter = new Vector3f(0f, 0f, 0f);
float radius = Float.POSITIVE_INFINITY;
BoundingSphere boundingSphere = new BoundingSphere(radius, sphCenter);

boundingSphere.mergeLocal(boundingBox);

Vector3f copyCenter = new Vector3f();
boundingSphere.getCenter(copyCenter);
Assert.assertTrue(Vector3f.isValidVector(copyCenter));
}
}
24 changes: 19 additions & 5 deletions jme3-core/src/test/java/com/jme3/math/Vector3fTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2009-2015 jMonkeyEngine
* Copyright (c) 2009-2021 jMonkeyEngine
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -235,12 +235,16 @@ public void testCrossLocal() {
assertEquals(-0.0f, retval.z, 0.0f);
}

/**
* Verify that distance() doesn't always overflow when distanceSquared >
* Float.MAX_VALUE .
*/
@Test
public void testDistance() {
final Vector3f target = new Vector3f(3.86405e+18f, 3.02146e+23f, 0.171875f);
final Vector3f v = new Vector3f(-2.0f, -1.61503e+19f, 0.171875f);

assertEquals(Float.POSITIVE_INFINITY, target.distance(v), 0.0f);
assertEquals(3.0216215e23f, target.distance(v), 0f);
}

@Test
Expand Down Expand Up @@ -540,11 +544,21 @@ public void testIsValidVector() {

@Test
public void testLength() {
assertEquals(0.0f, new Vector3f(1.88079e-37f, 0.0f, 1.55077e-36f).length(), 0.0f);
/*
* avoid underflow when lengthSquared is < Float.MIN_VALUE
*/
assertEquals(1.5621336e-36f,
new Vector3f(1.88079e-37f, 0.0f, 1.55077e-36f).length(), 0f);

assertEquals(Float.NaN, new Vector3f(Float.NaN, 0.0f, 1.55077e-36f).length(), 0.0f);
assertEquals(Float.POSITIVE_INFINITY, new Vector3f(Float.POSITIVE_INFINITY, 0.0f, 1.0f).length(), 0.0f);

assertEquals(4.0124f, new Vector3f(1.9f, 3.2f, 1.5f).length(), 0.001f);
assertEquals(Float.POSITIVE_INFINITY, new Vector3f(1.8e37f, 1.8e37f, 1.5e36f).length(), 0.0f);
/*
* avoid overflow when lengthSquared > Float.MAX_VALUE
*/
assertEquals(2.5499999e37f,
new Vector3f(1.8e37f, 1.8e37f, 1.5e36f).length(), 0.0f);
}

@Test
Expand Down