Browse Source

Merge pull request #296 from demonixis/master

Added subtractInPlace to Vector2 and return 'this' when len == 0 in Vector2/3.normalize
David Catuhe 11 years ago
parent
commit
11803896f2
2 changed files with 14 additions and 4 deletions
  1. 7 2
      Babylon/Math/babylon.math.js
  2. 7 2
      Babylon/Math/babylon.math.ts

+ 7 - 2
Babylon/Math/babylon.math.js

@@ -292,6 +292,11 @@
         Vector2.prototype.subtract = function (otherVector) {
             return new Vector2(this.x - otherVector.x, this.y - otherVector.y);
         };
+		
+		Vector2.prototype.subtractInPlace = function (otherVector) {
+            this.x -= otherVector.x;
+            this.y -= otherVector.y;
+        };
 
         Vector2.prototype.multiplyInPlace = function (otherVector) {
             this.x *= otherVector.x;
@@ -352,7 +357,7 @@
             var len = this.length();
 
             if (len === 0)
-                return;
+                return this;
 
             var num = 1.0 / len;
 
@@ -639,7 +644,7 @@
             var len = this.length();
 
             if (len === 0)
-                return;
+                return this;
 
             var num = 1.0 / len;
 

+ 7 - 2
Babylon/Math/babylon.math.ts

@@ -258,6 +258,11 @@
         public subtract(otherVector: Vector2): Vector2 {
             return new Vector2(this.x - otherVector.x, this.y - otherVector.y);
         }
+		
+		public subtractInPlace(otherVector: Vector2): void {
+            this.x -= otherVector.x;
+            this.y -= otherVector.y;
+        }
 
         public multiplyInPlace(otherVector: Vector2): void {
             this.x *= otherVector.x;
@@ -318,7 +323,7 @@
             var len = this.length();
 
             if (len === 0)
-                return;
+                return this;
 
             var num = 1.0 / len;
 
@@ -602,7 +607,7 @@
             var len = this.length();
 
             if (len === 0)
-                return;
+                return this;
 
             var num = 1.0 / len;