Skip to content

Commit fc881d6

Browse files
committed
Vector*: Simplified setLength(). See mrdoob#7326.
1 parent 071418a commit fc881d6

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

src/math/Vector2.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,15 +379,9 @@ THREE.Vector2.prototype = {
379379

380380
},
381381

382-
setLength: function ( l ) {
382+
setLength: function ( length ) {
383383

384-
var oldLength = this.length();
385-
386-
if ( oldLength !== 0 && l !== oldLength ) {
387-
388-
this.multiplyScalar( l / oldLength );
389-
390-
}
384+
this.multiplyScalar( length / this.length() );
391385

392386
return this;
393387

src/math/Vector3.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -584,15 +584,9 @@ THREE.Vector3.prototype = {
584584

585585
},
586586

587-
setLength: function ( l ) {
587+
setLength: function ( length ) {
588588

589-
var oldLength = this.length();
590-
591-
if ( oldLength !== 0 && l !== oldLength ) {
592-
593-
this.multiplyScalar( l / oldLength );
594-
595-
}
589+
this.multiplyScalar( length / this.length() );
596590

597591
return this;
598592

@@ -701,7 +695,7 @@ THREE.Vector3.prototype = {
701695

702696
angleTo: function ( v ) {
703697

704-
var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
698+
var theta = this.dot( v ) / Math.sqrt( this.lengthSq() * v.lengthSq() );
705699

706700
// clamp, to handle numerical problems
707701

src/math/Vector4.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -589,15 +589,9 @@ THREE.Vector4.prototype = {
589589

590590
},
591591

592-
setLength: function ( l ) {
592+
setLength: function ( length ) {
593593

594-
var oldLength = this.length();
595-
596-
if ( oldLength !== 0 && l !== oldLength ) {
597-
598-
this.multiplyScalar( l / oldLength );
599-
600-
}
594+
this.multiplyScalar( length / this.length() );
601595

602596
return this;
603597

0 commit comments

Comments
 (0)