Browse Source

Added Manhattan distance (#9206)

WestLangley 9 years ago
parent
commit
7e45066f75
5 changed files with 42 additions and 20 deletions
  1. 10 5
      docs/api/math/Vector2.html
  2. 12 7
      docs/api/math/Vector3.html
  3. 8 8
      docs/api/math/Vector4.html
  4. 6 0
      src/math/Vector2.js
  5. 6 0
      src/math/Vector3.js

+ 10 - 5
docs/api/math/Vector2.html

@@ -126,17 +126,17 @@
 
 		<h3>[method:Float lengthSq]() [page:Vector2 this]</h3>
 		<div>
-		Computes squared length of this vector.
+		Computes the squared length of this vector.
 		</div>
 
 		<h3>[method:Float length]() [page:Vector2 this]</h3>
 		<div>
-		Computes length of this vector.
+		Computes the length of this vector.
 		</div>
 
 		<h3>[method:Float lengthManhattan]() [page:Vector2 this]</h3>
 		<div>
-		Computes Manhattan length of this vector.<br />
+		Computes the Manhattan length of this vector.<br />
 		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
 		</div>
 
@@ -152,12 +152,17 @@
 
 		<h3>[method:Float distanceTo]( [page:Vector2 v] )</h3>
 		<div>
-		Computes distance of this vector to *v*.
+		Computes the distance from this vector to *v*.
 		</div>
 
 		<h3>[method:Float distanceToSquared]( [page:Vector2 v] )</h3>
 		<div>
-		Computes squared distance of this vector to *v*.
+		Computes the squared distance from this vector to *v*.
+		</div>
+
+		<h3>[method:Float distanceToManhattan]( [page:Vector2 v] )</h3>
+		<div>
+		Computes the Manhattan distance from this vector to *v*.
 		</div>
 
 		<h3>[method:Vector2 setLength]( [page:Float l] ) [page:Vector2 this]</h3>

+ 12 - 7
docs/api/math/Vector3.html

@@ -130,17 +130,17 @@
 
 		<h3>[method:Float lengthSq]() [page:Vector3 this]</h3>
 		<div>
-		Computes squared length of this vector.
+		Computes the squared length of this vector.
 		</div>
 
 		<h3>[method:Float length]() [page:Vector3 this]</h3>
 		<div>
-		Computes length of this vector.
+		Computes the length of this vector.
 		</div>
 
 		<h3>[method:Float lengthManhattan]() [page:Vector3 this]</h3>
 		<div>
-		Computes Manhattan length of this vector.<br />
+		Computes the Manhattan length of this vector.<br />
 		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
 		</div>
 
@@ -149,14 +149,19 @@
 		Normalizes this vector. Transforms this Vector into a Unit vector by dividing the vector by its length.
 		</div>
 
-		<h3>[method:Float distanceTo]( [page:Vector3 v] ) [page:Vector3 this]</h3>
+		<h3>[method:Float distanceTo]( [page:Vector3 v] )</h3>
 		<div>
-		Computes distance of this vector to *v*.
+		Computes the distance from this vector to *v*.
 		</div>
 
-		<h3>[method:Float distanceToSquared]( [page:Vector3 v] ) [page:Vector3 this]</h3>
+		<h3>[method:Float distanceToSquared]( [page:Vector3 v] )</h3>
 		<div>
-		Computes squared distance of this vector to *v*.
+		Computes the squared distance from this vector to *v*.
+		</div>
+
+		<h3>[method:Float distanceToManhattan]( [page:Vector3 v] )</h3>
+		<div>
+		Computes the Manhattan distance from this vector to *v*.
 		</div>
 
 		<h3>[method:Vector3 setLength]( [page:Float l] ) [page:Vector3 this]</h3>

+ 8 - 8
docs/api/math/Vector4.html

@@ -137,12 +137,18 @@
 
 		<h3>[method:Float lengthSq]() [page:Vector4 this]</h3>
 		<div>
-		Computes squared length of this vector.
+		Computes the squared length of this vector.
 		</div>
 
 		<h3>[method:Float length]() [page:Vector4 this]</h3>
 		<div>
-		Computes length of this vector.
+		Computes the length of this vector.
+		</div>
+
+		<h3>[method:Float lengthManhattan]() [page:Vector4 this]</h3>
+		<div>
+		Computes the Manhattan length of this vector.<br />
+		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
 		</div>
 
 		<h3>[method:Vector4 normalize]() [page:Vector4 this]</h3>
@@ -294,12 +300,6 @@
 		Index 3: w<br/>
 		</div>
 
-		<h3>[method:Float lengthManhattan]() [page:Vector4 this]</h3>
-		<div>
-		Computes Manhattan length of this vector.<br />
-		[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
-		</div>
-
 		<h3>[method:Vector4 clone]() [page:Vector4 this]</h3>
 		<div>
 		Clones this vector.

+ 6 - 0
src/math/Vector2.js

@@ -393,6 +393,12 @@ THREE.Vector2.prototype = {
 
 	},
 
+	distanceToManhattan: function ( v ) {
+
+		return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
+
+	},
+
 	setLength: function ( length ) {
 
 		return this.multiplyScalar( length / this.length() );

+ 6 - 0
src/math/Vector3.js

@@ -659,6 +659,12 @@ THREE.Vector3.prototype = {
 
 	},
 
+	distanceToManhattan: function ( v ) {
+
+		return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
+
+	},
+
 	setFromSpherical: function( s ) {
 
 		var sinPhiRadius = Math.sin( s.phi ) * s.radius;