Skip to content

Commit 979d7fe

Browse files
committed
Quaternion: Improve result of angleTo()
1 parent f2c9797 commit 979d7fe

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

src/math/Quaternion.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { _Math } from './Math.js';
12
import { Vector3 } from './Vector3.js';
23

34
/**
@@ -395,7 +396,7 @@ Object.assign( Quaternion.prototype, {
395396

396397
angleTo: function ( q ) {
397398

398-
return 2 * Math.acos( Math.abs( this.dot( q ) ) );
399+
return 2 * Math.acos( Math.abs( _Math.clamp( this.dot( q ), - 1, 1 ) ) );
399400

400401
},
401402

test/unit/src/math/Quaternion.tests.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -396,12 +396,10 @@ export default QUnit.module( 'Maths', () => {
396396
var a = new Quaternion();
397397
var b = new Quaternion().setFromEuler( new Euler( 0, Math.PI, 0 ) );
398398
var c = new Quaternion().setFromEuler( new Euler( 0, Math.PI * 2, 0 ) );
399-
var d = new Quaternion().setFromEuler( new Euler( 1, 1, 1 ) );
400399

401-
assert.ok( a.angleTo( a ) <= eps, "Passed!" );
402-
assert.ok( ( a.angleTo( b ) - Math.PI ) <= eps, "Passed!" );
403-
assert.ok( ( a.angleTo( c ) - ( Math.PI * 2 ) ) <= eps, "Passed!" );
404-
assert.ok( ( a.angleTo( d ) - ( 1.939087528822506 ) ) <= eps, "Passed!" );
400+
assert.ok( a.angleTo( a ) === 0, "Passed!" );
401+
assert.ok( a.angleTo( b ) === Math.PI, "Passed!" );
402+
assert.ok( a.angleTo( c ) === 0, "Passed!" );
405403

406404
} );
407405

0 commit comments

Comments
 (0)