Class: Vec2Array

Vec2Array

Array of two-element vectors of 32-bit floats. May reflect an ESSL array-of-vec2s uniform variable.
Individual Vec2 elements are available through the at method. Methods are available for optimized bulk processing.

new Vec2Array(size)

Parameters:
Name Type Description
size Number The number of Vec2 elements in the array.

Extends

Methods


add(b, c)

Adds vectors from the two argument arrays, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first terms. Its length must be identical to this array's length.
c VecArray Array of second terms. Its length must be identical to this array's length.
Inherited From:
Returns:
this
Type
VecArray

addAll(b, c)

Adds a vector to all argument array elements, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first operands. Same length as this.
c Vec Second operand.
Inherited From:
Returns:
this
Type
VecArray

addScaled(b, c, dt)

Adds vectors from the two argument arrays, scaling the second arguments, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first terms. Its length must be identical to this array's length.
c VecArray Array of second terms. Its length must be identical to this array's length.
dt Number Single scalar scaling factor.
Inherited From:
Returns:
this
Type
VecArray

at(index)

Returns a new Vec2 object that captures an element of the array. The new vector is a view on the original data, not a copy.
Parameters:
Name Type Description
index Number Index of the element.
Returns:
new view on one of the array's elements
Type
Vec2

clamp()

Constrains values in the array to the [0,1) interval.
Inherited From:
Returns:
this
Type
VecArray

commit(gl, uniformLocation)

Sets the value of the vector array to a WebGL vec2 array uniform variable.
Parameters:
Name Type Description
gl WebGLRenderingContext rendering context
uniformLocation WebGLUniformLocation location of the uniform variable in the currently used WebGL program

cossin(alphas)

Fills this array with (cos alpha, sin alpha) vectors, where alpha comes from the argument array.
Parameters:
Name Type Description
alphas Vec1Array Array of angles.
Returns:
this
Type
Vec2Array

div(b, c)

Divides, elementwise, vectors from the two argument arrays, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of dividends.
c VecArray Array of divisors.
Inherited From:
Returns:
this
Type
VecArray

divAll(b, c)

Divides (elementwise) all argument array elements with a vector, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first operands. Same length as this.
c Vec Second operand.
Inherited From:
Returns:
this
Type
VecArray

divWithVec1s(b, c)

Divides, elementwise, vectors from the two argument arrays, repeating individual values of the second one to produce the same number of values as in the output array.
Parameters:
Name Type Description
b VecArray Array of dividends. Its length must be identical to this array's length.
c Vec1Array Array of divisors. Its length must be identical to this array's length.
Inherited From:
Returns:
this
Type
VecArray

exp(b, c)

Exponentiates vectors from an array with a scalar, storing the result in this array. For scaling with factors stored in an array, see mulAll.
Parameters:
Name Type Description
b VecArray Array of vectors to scale. Its length must be identical to this array's length.
c VecArray Exponent.
Inherited From:
Returns:
this
Type
VecArray

mul(b, c)

Multipies, elementwise, vectors from the two argument arrays, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of factors. Its length must be identical to this array's length.
c VecArray Array of factors. Its length must be identical to this array's length.
Inherited From:
Returns:
this
Type
VecArray

mulAll(b, c)

Multiplies (elementwise) a vector with all argument array elements, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first operands. Same length as this.
c Vec Second operand.
Inherited From:
Returns:
this
Type
VecArray

mulWithVec1s(b, c)

Multipies, elementwise, vectors from the two argument arrays, repeating individual values of the second one to produce the same number of elements as in the output array. For scaling with a single scalar factor, see scale.
Parameters:
Name Type Description
b VecArray Array of factors. Its length must be identical to this array's length.
c Vec1Array Array of factors. Its length must be identical to this array's length.
Inherited From:
Returns:
this
Type
VecArray

normalize(b)

Fills this vector with the unit length versions of vectors in the argument vector.
Parameters:
Name Type Description
b Vec2Array Array of vectors to normalize. Its length must be identical to this array's length.
Returns:
this
Type
Vec2Array

random()

Fills the array with random values between 0 and 1.
Inherited From:
Returns:
this
Type
VecArray

scale(b, c)

Multipies vectors from an array with a scalar, storing the result in this array. For scaling with factors stored in an array, see mulAll.
Parameters:
Name Type Description
b VecArray Array of vectors to scale. Its length must be identical to this array's length.
c VecArray Scale factor.
Inherited From:
Returns:
this
Type
VecArray

set(data)

Sets the value of the vector array from another WebGLMath vector, vector array, matrix, or matrix array object, or an array of numbers.
Parameters:
Name Type Description
data Array.<number> | Object Input data.
Inherited From:

sub(b, c)

Subtracts vectors from the two argument arrays, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of minuends. Its length must be identical to this array's length.
c VecArray Array of subtrahends. Its length must be identical to this array's length.
Inherited From:
Returns:
this
Type
VecArray

subAll(b, c)

Subtracts a vector from all argument array elements, storing the result in this array.
Parameters:
Name Type Description
b VecArray Array of first operands. Same length as this.
c Vec Second operand.
Inherited From:
Returns:
this
Type
VecArray

subarray( [begin] [, end])

Returns a new Vec2Array object that captures a subrange of the array. The new array is a view on the original data, not a copy.
Parameters:
Name Type Argument Default Description
begin Number <optional>
0 Element to begin at. The offset is inclusive. The whole array will be cloned if this value is not specified.
end Number <optional>
length Element to end at. The offset is exclusive. If not specified, all elements from the one specified by begin to the end of the array are included in the new view.
Returns:
new view on some of the array's elements
Type
Vec2Array

xy00mul(v)

Fills this array with vectors from the argument array, augmented by a 0 to get a homogeneous direction vector, transformed by the argument 4x4 matrix. The vectors are cosidered row vectors, multiplied from the right with a matrix laid out in column-major order.
Parameters:
Name Type Description
v Vec2Array Array of vectors to transform. Its length must be identical to this array's length.
Returns:
this
Type
Vec2Array

xy01mul(v)

Fills this array with vectors from the argument array, augmented by a 1 to get a homogeneous position vector, transformed by the argument 4x4 matrix. The vectors are cosidered row vectors, multiplied from the right with a matrix laid out in column-major order.
Parameters:
Name Type Description
v Vec2Array Array of vectors to transform. Its length must be identical to this array's length.
Returns:
this
Type
Vec2Array