Browse Source

Merge pull request #7326 from Mugen87/dev

Added vector truncate methods
Mr.doob 9 years ago
parent
commit
91d7c95a85
2 changed files with 20 additions and 0 deletions
  1. 10 0
      src/math/Vector2.js
  2. 10 0
      src/math/Vector3.js

+ 10 - 0
src/math/Vector2.js

@@ -281,6 +281,16 @@ THREE.Vector2.prototype = {
 
 	}(),
 
+	clampLength: function ( min, max ) {
+
+		var length = this.length();
+
+		this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
+
+		return this;
+
+	},
+
 	floor: function () {
 
 		this.x = Math.floor( this.x );

+ 10 - 0
src/math/Vector3.js

@@ -494,6 +494,16 @@ THREE.Vector3.prototype = {
 
 	}(),
 
+	clampLength: function ( min, max ) {
+
+		var length = this.length();
+
+		this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
+
+		return this;
+
+	},
+
 	floor: function () {
 
 		this.x = Math.floor( this.x );