From 7e45066f7575fc848565405bd4ae0f0fa62ff247 Mon Sep 17 00:00:00 2001 From: WestLangley Date: Fri, 24 Jun 2016 00:53:33 -0400 Subject: [PATCH] Added Manhattan distance (#9206) --- docs/api/math/Vector2.html | 15 ++++++++++----- docs/api/math/Vector3.html | 19 ++++++++++++------- docs/api/math/Vector4.html | 16 ++++++++-------- src/math/Vector2.js | 6 ++++++ src/math/Vector3.js | 6 ++++++ 5 files changed, 42 insertions(+), 20 deletions(-) diff --git a/docs/api/math/Vector2.html b/docs/api/math/Vector2.html index 625f889808..ed46ec0b77 100644 --- a/docs/api/math/Vector2.html +++ b/docs/api/math/Vector2.html @@ -126,17 +126,17 @@

[method:Float lengthSq]() [page:Vector2 this]

- Computes squared length of this vector. + Computes the squared length of this vector.

[method:Float length]() [page:Vector2 this]

- Computes length of this vector. + Computes the length of this vector.

[method:Float lengthManhattan]() [page:Vector2 this]

- Computes Manhattan length of this vector.
+ Computes the Manhattan length of this vector.
[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
@@ -152,12 +152,17 @@

[method:Float distanceTo]( [page:Vector2 v] )

- Computes distance of this vector to *v*. + Computes the distance from this vector to *v*.

[method:Float distanceToSquared]( [page:Vector2 v] )

- Computes squared distance of this vector to *v*. + Computes the squared distance from this vector to *v*. +
+ +

[method:Float distanceToManhattan]( [page:Vector2 v] )

+
+ Computes the Manhattan distance from this vector to *v*.

[method:Vector2 setLength]( [page:Float l] ) [page:Vector2 this]

diff --git a/docs/api/math/Vector3.html b/docs/api/math/Vector3.html index 9f5b381259..ed0b62b55d 100644 --- a/docs/api/math/Vector3.html +++ b/docs/api/math/Vector3.html @@ -130,17 +130,17 @@

[method:Float lengthSq]() [page:Vector3 this]

- Computes squared length of this vector. + Computes the squared length of this vector.

[method:Float length]() [page:Vector3 this]

- Computes length of this vector. + Computes the length of this vector.

[method:Float lengthManhattan]() [page:Vector3 this]

- Computes Manhattan length of this vector.
+ Computes the Manhattan length of this vector.
[link:http://en.wikipedia.org/wiki/Taxicab_geometry]
@@ -149,14 +149,19 @@ Normalizes this vector. Transforms this Vector into a Unit vector by dividing the vector by its length. -

[method:Float distanceTo]( [page:Vector3 v] ) [page:Vector3 this]

+

[method:Float distanceTo]( [page:Vector3 v] )

- Computes distance of this vector to *v*. + Computes the distance from this vector to *v*.
-

[method:Float distanceToSquared]( [page:Vector3 v] ) [page:Vector3 this]

+

[method:Float distanceToSquared]( [page:Vector3 v] )

- Computes squared distance of this vector to *v*. + Computes the squared distance from this vector to *v*. +
+ +

[method:Float distanceToManhattan]( [page:Vector3 v] )

+
+ Computes the Manhattan distance from this vector to *v*.

[method:Vector3 setLength]( [page:Float l] ) [page:Vector3 this]

diff --git a/docs/api/math/Vector4.html b/docs/api/math/Vector4.html index a7f33f87aa..1aa7264616 100644 --- a/docs/api/math/Vector4.html +++ b/docs/api/math/Vector4.html @@ -137,12 +137,18 @@

[method:Float lengthSq]() [page:Vector4 this]

- Computes squared length of this vector. + Computes the squared length of this vector.

[method:Float length]() [page:Vector4 this]

- Computes length of this vector. + Computes the length of this vector. +
+ +

[method:Float lengthManhattan]() [page:Vector4 this]

+
+ Computes the Manhattan length of this vector.
+ [link:http://en.wikipedia.org/wiki/Taxicab_geometry]

[method:Vector4 normalize]() [page:Vector4 this]

@@ -294,12 +300,6 @@ Index 3: w
-

[method:Float lengthManhattan]() [page:Vector4 this]

-
- Computes Manhattan length of this vector.
- [link:http://en.wikipedia.org/wiki/Taxicab_geometry] -
-

[method:Vector4 clone]() [page:Vector4 this]

Clones this vector. diff --git a/src/math/Vector2.js b/src/math/Vector2.js index a016a73733..fb5b27c2bc 100644 --- a/src/math/Vector2.js +++ b/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() ); diff --git a/src/math/Vector3.js b/src/math/Vector3.js index 0fc8ca4d3c..25acd8421f 100644 --- a/src/math/Vector3.js +++ b/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; -- GitLab