Skip to content

Commit

Permalink
1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Zunawe committed Jun 24, 2018
1 parent 8065496 commit e0f3fdd
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/index.html
Expand Up @@ -77,7 +77,7 @@



<h3>vecn 1.3.0</h3>
<h3>vecn 1.3.1</h3>



Expand Down
2 changes: 1 addition & 1 deletion docs/quicksearch.html
Expand Up @@ -7,7 +7,7 @@
<script src="scripts/fulltext-search.js"></script>

<script type="text/x-docstrap-searchdb">
{"global.html":{"id":"global.html","title":"Global","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Global Methods add(vecs) Adds an arbitrary number of vectors together. All vectors must be of the samedimension. Parameters: Name Type Argument Description vecs vecn &lt;repeatable&gt; Vectors to add together. Returns: The sum of all the provided vectors. Type vecn getVecType(dim) Returns a factory function for vectors of the specified dimension. Parameters: Name Type Description dim number The dimension of the new vector type. Returns: A factory (not a constructor) for creating new vecs. Type function isVec(v) The correct function for determining whether an object is a vecn. Parameters: Name Type Description v * The object in question. Returns: True if the object is an instance of vecn. Type boolean lerp(v1, v2, t) Linearly interpolates between two vectors. Parameters: Name Type Description v1 vecn The starting vector. v2 vecn The ending vector. t number The interpolant, which is clamped to the inteval [0, 1]. Returns: The interpolated vector. Type vecn multiply(vecs) Multiplies an arbitrary number of vectors together. All vectors must be of the samedimension. Parameters: Name Type Argument Description vecs vecn &lt;repeatable&gt; Vectors to multiply together. Returns: The product of all the provided vectors. Type vecn slerp(v1, v2, t) Spherically interpolates between two vectors. Parameters: Name Type Description v1 vecn The starting vector. v2 vecn The ending vector. t number The interpolant, which is clamped to the inteval [0, 1]. Returns: The interpolated vector. Type vecn × Search results Close "},"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Classes Classes vecn × Search results Close "},"index.html":{"id":"index.html","title":"Index","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp vecn 1.3.0 vecn A module for creating n-dimensional vector types that support swizzling. Allows for the creation of vectors of arbitrary dimension that are also JavaScript Arrays. These arrays are fixed-length and accept only numbers as input, though they generally decay gracefully into regular Arrays. For example, you're allowed to use map, reduce, concat, and other Array methods, and if the result is a valid vec, a vec will be returned. Otherwise, you'll get back a standard Array with the new elements. These are specifically overloaded methods, so experimental, custom, and rebound methods aren't guaranteed to work. Install$ npm install vecnUsageSince they're the most common, vec2, vec3, and vec4 are already included: const {vec3} = require('vecn') let v = vec3(1, 2, 3) console.log(v)[ 1, 2, 3 ]If you need to create your own vector type: const vecn = require('vecn') const vec5 = vecn.getVecType(5) var v = vec5(1, 2, 3, 4, 5) console.log(v)[ 1, 2, 3, 4, 5 ]For a more in-depth description of available vector methods, see the documentation. SwizzlingSwizzling is a technique used in GLSL that allows you to access a vector's components by name and build new vectors from them. It works the same here at arbitrary length. It's easiest to see in an example: var v = vec4(1, 2, 3, 4) v.x // 1 v.y // 2 v.z // 3 v.w // 4 v.xx // vec2 [ 1, 1 ] v.zy // vec2 [ 3, 2 ] v.zywwxyyz // vec8 [ 3, 2, 4, 4, 1, 2, 2, 3 ]We can also set values with swizzling. var v = vec3(1, 2, 3) v.xz = [4, 5] console.log(v)[ 4, 2, 5 ]Swizzling only works for vec2, vec3, and vec4 (with plans to extend it with custom accessors). Important NuanceWhen creating a new vecType, you are generating a new class. However, this class is hidden behind a function that creates the object for you and returns a Proxy. Therefore, the function returned by vecn.getVecType is not a constructor. Since the new keyword implies a return this at the end of the function, but the function already returns, the existence of a new before the function call has no effect. The following code explains the importance: const vec2 = vecn.getVecType(2) var v1 = vec2(1, 2) // Valid construction var v2 = new vec2(1, 2) // Also valid, but misleading v1.constructor === vec2 // falseBasically this allows for swizzling and lets me extend Array without letting the user mess with the length. × Search results Close "},"vecn.html":{"id":"vecn.html","title":"Class: vecn","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Class: vecn vecn A class for fixed-size vectors of numbers. new vecn(dimension [, args]) Creates a vecn of the specified dimension. This should never be calledby the user (as if this were an abstract class). Parameters: Name Type Argument Default Description dimension number The dimension of this vector. args Array.&lt;number&gt; &lt;optional&gt; [] The numbers to be put in the vector. Extends Array Members magnitude :number The L2 norm (Euclidian norm) of the vector. Type: number Methods approximatelyEquals(v, epsilon) Returns whether every element in each vector is approximately equal. Parameters: Name Type Default Description v Array.&lt;number&gt; A vector to test against. epsilon number 1e-8 The largest meaningful difference between two values. Returns: True if both vectors have the same dimension and thedistance between each number is less than epsilon. Type boolean argmax() Finds the indices of the max value in this vector. Returns: An array of indices corresponding to the max values. Type Array.&lt;number&gt; argmin() Finds the indices of the min value in this vector. Returns: An array of indices corresponding to the min values. Type Array.&lt;number&gt; choose(indices) Creates a new vector from the provided indices of this one. Basicallyequivalent to swizzling. Parameters: Name Type Description indices Array.&lt;number&gt; The indices to select into a new vector. Returns: A new vector from the provided indices. Type vecn concat() Same as Array.prototype.concat, but return value is of a new vecType. Returns: Type vecn copy() Creates a duplicate of this vector. Same as passing this vector throughthe factory that created it. Returns: A deep copy of this vector. Type vecn div(v) Returns a vector where this is divided by v componentwise. If v isa single number, the vector is scaled by 1/v. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to multiply with. Returns: A new vector with the divided components. Type vecn dot(v) Dot product of two vectors. Parameters: Name Type Description v Array.&lt;number&gt; The vector to dot with this one. Returns: The dot product between this and v. Type number equals(v) Returns whether every element in each vector is equal. Parameters: Name Type Description v Array.&lt;number&gt; A vector to test against. Returns: True if both vectors have the same dimension and values. Type boolean filter() Same as Array.prototype.filter, but returns an Array if the result has 0entries. Returns: Type vecn | Array.&lt;number&gt; map() Same as Array.prototype.map, but returns an Array if the result containsnon-numbers. Returns: Type vecn | Array max() Returns the max value of this vector. Returns: The max value of this vector. Type number min() Returns the min value of this vector. Returns: The min value of this vector. Type number minus(v) Returns a vector where v is subtracted from the components of thisvector. If v is a single number, it is subtracted to each component. If vis a vector, the vectors are combined componentwise. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to subtract from this vector. Returns: A new vector with the combined components. Type vecn neg() Negates each element in this vector. Returns: A new vector where all elements are negated. Type vecn normalize() Scales this vector to a magnitude of 1. Returns: A new vector with scaled components. Type vecn plus(v) Returns a vector where v is added to the components of this vector. If vis a single number, it is added to each component. If v is a vector, thevectors are added componentwise. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to add to this vector. Returns: A new vector with the summed components. Type vecn pnorm(p) Evaluates the p-norm (or lp-norm) of this vector. Parameters: Name Type Description p number The p-value to evaluate. Returns: The norm of this vector. Type number pow(p) Returns a vector where each component of this was raised to a power p. Parameters: Name Type Description p number The power to raise each component by. Returns: A new vector with the exponentiated components. Type vecn reflect(normal) Reflects this vector across the provided vector. The normal can be imaginedas a surface normal or as describing a hyperpalane. Parameters: Name Type Description normal Array.&lt;number&gt; A vector describing the hyperplane to reflect off of. Returns: The reflected vector. Type vecn slice() Same as Array.prototype.slice, but returns an Array if the result has 0entries. splice() A restrictive version of the Array.prototype.splice that requires allremoved elements to be replaced. sum() Sums the components of this vector. Returns: The sum of the components of this vector. Type number times(v) Returns a vector where v and this are multiplied componentwise. If v isa single number, the vector is scaled by v. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to multiply with. Returns: A new vector with the multiplied components. Type vecn toArray() Converts this vector into an Array. Returns: An array of the contents of this vector. Type Array.&lt;number&gt; × Search results Close "}}
{"global.html":{"id":"global.html","title":"Global","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Global Methods add(vecs) Adds an arbitrary number of vectors together. All vectors must be of the samedimension. Parameters: Name Type Argument Description vecs vecn &lt;repeatable&gt; Vectors to add together. Returns: The sum of all the provided vectors. Type vecn getVecType(dim) Returns a factory function for vectors of the specified dimension. Parameters: Name Type Description dim number The dimension of the new vector type. Returns: A factory (not a constructor) for creating new vecs. Type function isVec(v) The correct function for determining whether an object is a vecn. Parameters: Name Type Description v * The object in question. Returns: True if the object is an instance of vecn. Type boolean lerp(v1, v2, t) Linearly interpolates between two vectors. Parameters: Name Type Description v1 vecn The starting vector. v2 vecn The ending vector. t number The interpolant, which is clamped to the inteval [0, 1]. Returns: The interpolated vector. Type vecn multiply(vecs) Multiplies an arbitrary number of vectors together. All vectors must be of the samedimension. Parameters: Name Type Argument Description vecs vecn &lt;repeatable&gt; Vectors to multiply together. Returns: The product of all the provided vectors. Type vecn slerp(v1, v2, t) Spherically interpolates between two vectors. Parameters: Name Type Description v1 vecn The starting vector. v2 vecn The ending vector. t number The interpolant, which is clamped to the inteval [0, 1]. Returns: The interpolated vector. Type vecn × Search results Close "},"classes.list.html":{"id":"classes.list.html","title":"Classes","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Classes Classes vecn × Search results Close "},"index.html":{"id":"index.html","title":"Index","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp vecn 1.3.1 vecn A module for creating n-dimensional vector types that support swizzling. Allows for the creation of vectors of arbitrary dimension that are also JavaScript Arrays. These arrays are fixed-length and accept only numbers as input, though they generally decay gracefully into regular Arrays. For example, you're allowed to use map, reduce, concat, and other Array methods, and if the result is a valid vec, a vec will be returned. Otherwise, you'll get back a standard Array with the new elements. These are specifically overloaded methods, so experimental, custom, and rebound methods aren't guaranteed to work. Install$ npm install vecnUsageSince they're the most common, vec2, vec3, and vec4 are already included: const {vec3} = require('vecn') let v = vec3(1, 2, 3) console.log(v)[ 1, 2, 3 ]If you need to create your own vector type: const vecn = require('vecn') const vec5 = vecn.getVecType(5) var v = vec5(1, 2, 3, 4, 5) console.log(v)[ 1, 2, 3, 4, 5 ]For a more in-depth description of available vector methods, see the documentation. SwizzlingSwizzling is a technique used in GLSL that allows you to access a vector's components by name and build new vectors from them. It works the same here at arbitrary length. It's easiest to see in an example: var v = vec4(1, 2, 3, 4) v.x // 1 v.y // 2 v.z // 3 v.w // 4 v.xx // vec2 [ 1, 1 ] v.zy // vec2 [ 3, 2 ] v.zywwxyyz // vec8 [ 3, 2, 4, 4, 1, 2, 2, 3 ]We can also set values with swizzling. var v = vec3(1, 2, 3) v.xz = [4, 5] console.log(v)[ 4, 2, 5 ]Swizzling only works for vec2, vec3, and vec4 (with plans to extend it with custom accessors). Important NuanceWhen creating a new vecType, you are generating a new class. However, this class is hidden behind a function that creates the object for you and returns a Proxy. Therefore, the function returned by vecn.getVecType is not a constructor. Since the new keyword implies a return this at the end of the function, but the function already returns, the existence of a new before the function call has no effect. The following code explains the importance: const vec2 = vecn.getVecType(2) var v1 = vec2(1, 2) // Valid construction var v2 = new vec2(1, 2) // Also valid, but misleading v1.constructor === vec2 // falseBasically this allows for swizzling and lets me extend Array without letting the user mess with the length. × Search results Close "},"vecn.html":{"id":"vecn.html","title":"Class: vecn","body":" vecn Classes vecn Global addgetVecTypeisVeclerpmultiplyslerp Class: vecn vecn A class for fixed-size vectors of numbers. new vecn(dimension [, args]) Creates a vecn of the specified dimension. This should never be calledby the user (as if this were an abstract class). Parameters: Name Type Argument Default Description dimension number The dimension of this vector. args Array.&lt;number&gt; &lt;optional&gt; [] The numbers to be put in the vector. Extends Array Members magnitude :number The L2 norm (Euclidian norm) of the vector. Type: number Methods approximatelyEquals(v, epsilon) Returns whether every element in each vector is approximately equal. Parameters: Name Type Default Description v Array.&lt;number&gt; A vector to test against. epsilon number 1e-8 The largest meaningful difference between two values. Returns: True if both vectors have the same dimension and thedistance between each number is less than epsilon. Type boolean argmax() Finds the indices of the max value in this vector. Returns: An array of indices corresponding to the max values. Type Array.&lt;number&gt; argmin() Finds the indices of the min value in this vector. Returns: An array of indices corresponding to the min values. Type Array.&lt;number&gt; choose(indices) Creates a new vector from the provided indices of this one. Basicallyequivalent to swizzling. Parameters: Name Type Description indices Array.&lt;number&gt; The indices to select into a new vector. Returns: A new vector from the provided indices. Type vecn concat() Same as Array.prototype.concat, but return value is of a new vecType. Returns: Type vecn copy() Creates a duplicate of this vector. Same as passing this vector throughthe factory that created it. Returns: A deep copy of this vector. Type vecn div(v) Returns a vector where this is divided by v componentwise. If v isa single number, the vector is scaled by 1/v. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to multiply with. Returns: A new vector with the divided components. Type vecn dot(v) Dot product of two vectors. Parameters: Name Type Description v Array.&lt;number&gt; The vector to dot with this one. Returns: The dot product between this and v. Type number equals(v) Returns whether every element in each vector is equal. Parameters: Name Type Description v Array.&lt;number&gt; A vector to test against. Returns: True if both vectors have the same dimension and values. Type boolean filter() Same as Array.prototype.filter, but returns an Array if the result has 0entries. Returns: Type vecn | Array.&lt;number&gt; map() Same as Array.prototype.map, but returns an Array if the result containsnon-numbers. Returns: Type vecn | Array max() Returns the max value of this vector. Returns: The max value of this vector. Type number min() Returns the min value of this vector. Returns: The min value of this vector. Type number minus(v) Returns a vector where v is subtracted from the components of thisvector. If v is a single number, it is subtracted to each component. If vis a vector, the vectors are combined componentwise. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to subtract from this vector. Returns: A new vector with the combined components. Type vecn neg() Negates each element in this vector. Returns: A new vector where all elements are negated. Type vecn normalize() Scales this vector to a magnitude of 1. Returns: A new vector with scaled components. Type vecn plus(v) Returns a vector where v is added to the components of this vector. If vis a single number, it is added to each component. If v is a vector, thevectors are added componentwise. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to add to this vector. Returns: A new vector with the summed components. Type vecn pnorm(p) Evaluates the p-norm (or lp-norm) of this vector. Parameters: Name Type Description p number The p-value to evaluate. Returns: The norm of this vector. Type number pow(p) Returns a vector where each component of this was raised to a power p. Parameters: Name Type Description p number The power to raise each component by. Returns: A new vector with the exponentiated components. Type vecn reflect(normal) Reflects this vector across the provided vector. The normal can be imaginedas a surface normal or as describing a hyperpalane. Parameters: Name Type Description normal Array.&lt;number&gt; A vector describing the hyperplane to reflect off of. Returns: The reflected vector. Type vecn slice() Same as Array.prototype.slice, but returns an Array if the result has 0entries. splice() A restrictive version of the Array.prototype.splice that requires allremoved elements to be replaced. sum() Sums the components of this vector. Returns: The sum of the components of this vector. Type number times(v) Returns a vector where v and this are multiplied componentwise. If v isa single number, the vector is scaled by v. Parameters: Name Type Description v number | Array.&lt;number&gt; The value to multiply with. Returns: A new vector with the multiplied components. Type vecn toArray() Converts this vector into an Array. Returns: An array of the contents of this vector. Type Array.&lt;number&gt; × Search results Close "}}
</script>

<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "vecn",
"version": "1.3.0",
"version": "1.3.1",
"engines": {
"node": ">=6.4.0"
},
Expand Down

0 comments on commit e0f3fdd

Please sign in to comment.