Class Vector2

Vector with 2 floating point components: (x, y).

Vector2 constructors

Functions which can be used to create new instances of Vector2.

Synopsis

Methods
Vector2()

Default constructor

Vector2()

Constructor

Vector2()

Constructor

Vector2()

Default constructor. Initializes a vector to (0.0, 0.0).

Example
local vector2 = Vector2()
Vector2(x, y)

Constructor. Initializes a vector to (x, y).

Example
local vector2 = Vector2(x, y)
Parameters
x (float)

x coefficient of a vector.

y (float)

y coefficient of a vector.

Vector2(v)

Constructor. Initializes a vector to (v, v).

Example
local vector2 = Vector2(v)
Parameters
v (float)

x and y coefficients of a vector.

Vector2 methods

Methods of Vector2 class.

Synopsis

Methods
Vector2.zero()

Returns the vector with each element being zero

Vector2.one()

Returns the vector with each element being one

Vector2:getX()

Returns the x element of the vector

Vector2:getY()

Returns the y element of the vector

Vector2:setX()

Sets the x element of the vector

Vector2:setY()

Sets the y element of the vector

Vector2:hasNan()

Returns true if and only if at least one of the vector values is NaN

Vector2.createFromVector3()

Creates a Vector2 from Vector3 by dropping the z-coordinate

Vector2:length()

Calculates the length a vectors

Vector2:squaredLength()

Calculates the squared length a vectors

Vector2:normalized()

Normalizes the vector and returns the resulting vector

Vector2.lowestValue()

Returns the vector with each element having the most negative float value

Vector2.highestValue()

Returns the vector with each element having the most positive float value

Vector2.nan()

Returns the vector with each element being NaN

Vector2.positiveInfinity()

Returns the vector with each element being the positive infinity

Vector2.negativeInfinity()

Returns the vector with each element being the negative infinity

Vector2.zero()

Returns the vector with each element being zero.

Return Values
(Vector2)

Vector with zeroed elements.

Vector2.one()

Returns the vector with each element being one.

Return Values
(Vector2)

Vector with unit element values.

Vector2:getX()

Returns the x element of the vector.

Return Values
(float)

The x element.

Vector2:getY()

Returns the y element of the vector.

Return Values
(float)

The y element.

Vector2:setX(value)

Sets the x element of the vector.

Parameters
value (float)

The new value of the x element.

Vector2:setY(value)

Sets the y element of the vector.

Parameters
value (float)

The new value of the y element.

Vector2:hasNan()

Returns true if and only if at least one of the vector values is NaN.

Vector2.createFromVector3(v)

Creates a Vector2 from Vector3 by dropping the z-coordinate.

Parameters
v (Vector3)

Input vector.

Return Values
(Vector2)

The input vector without z-coordinate.

Vector2:length()

Calculates the length a vectors.

Return Values
(float)

sqrt(xx + yy)

Vector2:squaredLength()

Calculates the squared length a vectors.

Return Values
(float)

xx + yy

Vector2:normalized()

Normalizes the vector and returns the resulting vector.

Return Values
(Vector2)

The normalized vector.

Vector2.lowestValue()

Returns the vector with each element having the most negative float value.

Return Values
(Vector2)

Vector with the lowest possible value.

Vector2.highestValue()

Returns the vector with each element having the most positive float value.

Return Values
(Vector2)

Vector with the highest possible value.

Vector2.nan()

Returns the vector with each element being NaN.

Return Values
(Vector2)

Vector with NaN elements.

Vector2.positiveInfinity()

Returns the vector with each element being the positive infinity.

Return Values
(Vector2)

Vector with positive infinity elements.

Vector2.negativeInfinity()

Returns the vector with each element being the negative infinity.

Return Values
(Vector2)

Vector with negative infinity elements.

Vector2 functions

Vector2 specific standalone functions, which are not a part of the Vector2 class.

Synopsis

Functions
componentAbs()

Calculates component-wise absolute value for all elements and returns resulting vector

componentCeil()

Calculates component-wise ceil value for all elements and returns resulting vector

componentFloor()

Calculates component-wise floor value for all elements and returns resulting vector

componentRound()

Calculates component-wise rounded value for all elements and returns resulting vector

componentSqrt()

Calculates component-wise square root all elements and returns resulting vector

componentWiseMax()

Calculates the component-wise maximum for all vector elements and returns the resulting vector

componentWiseMin()

Calculates the component-wise minimum for all vector elements and returns the resulting vector

componentWiseMultiply()

Multiplies all vector elements component-wise and returns the resulting vector

componentWiseDivide()

Divides all vector elements component-wise and returns the resulting vector

componentWiseRemainder()

Calculates component-wise the remainder for all vector elements and returns the resulting vector

componentAdd()

Adds a value to all elements of a vector and returns the result

componentSubtract()

Subtracts a value from all elements of a vector and returns the result

componentAllLessThan()

Returns whether each component of the first vector is less than the corresponding component of the second vector

componentAllLessThanOrEqual()

Returns whether each component of the first vector is less than or equal to the corresponding component of the second vector

componentAllGreaterThan()

Returns whether each component of the first vector is greater than the corresponding component of the second vector

componentAllGreaterThanOrEqual()

Returns whether each component of the first vector is greater than or equal to the corresponding component of the second vector

dotProduct()

Calculates the dot product of two vectors

pseudoCrossProduct()

Calculates pseudo-cross product of two 2D vectors

isfinite()

Overloading of kanzi::isfinite for kanzi::Vector2

componentAbs(v)

Calculates component-wise absolute value for all elements and returns resulting vector.

Parameters
v (Vector2)

Vector input.

Return Values
(Vector2)

The result vector.

componentCeil(v)

Calculates component-wise ceil value for all elements and returns resulting vector.

Parameters
v (Vector2)

Vector input.

Return Values
(Vector2)

The result vector.

componentFloor(v)

Calculates component-wise floor value for all elements and returns resulting vector.

Parameters
v (Vector2)

Vector input.

Return Values
(Vector2)

The result vector.

componentRound(v)

Calculates component-wise rounded value for all elements and returns resulting vector.

Parameters
v (Vector2)

Vector input.

Return Values
(Vector2)

The result vector.

componentSqrt(v)

Calculates component-wise square root all elements and returns resulting vector.

Parameters
v (Vector2)

Vector input.

Return Values
(Vector2)

The result vector.

componentWiseMax(v1, v2)

Calculates the component-wise maximum for all vector elements and returns the resulting vector.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(Vector2)

The result vector.

componentWiseMin(v1, v2)

Calculates the component-wise minimum for all vector elements and returns the resulting vector.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(Vector2)

The result vector.

componentWiseMultiply(v1, v2)

Multiplies all vector elements component-wise and returns the resulting vector.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(Vector2)

The result vector.

componentWiseDivide(v1, v2)

Divides all vector elements component-wise and returns the resulting vector.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(Vector2)

The result vector.

componentWiseRemainder(v1, v2)

Calculates component-wise the remainder for all vector elements and returns the resulting vector.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(Vector2)

The result vector.

componentAdd(v, scalar)

Adds a value to all elements of a vector and returns the result.

Parameters
v (Vector2)

A vector.

scalar (float)

A scalar.

Return Values
(Vector2)

The result vector.

componentSubtract(v, scalar)

Subtracts a value from all elements of a vector and returns the result.

Parameters
v (Vector2)

A vector.

scalar (float)

A scalar.

Return Values
(Vector2)

The result vector.

componentAllLessThan(a, b)

Returns whether each component of the first vector is less than the corresponding component of the second vector.

Parameters
a (Vector2)

First vector.

b (Vector2)

Second vector.

Return Values
(bool)

If each component of the first vector is less than the corresponding component of the second vector, true, otherwise false.

componentAllLessThanOrEqual(a, b)

Returns whether each component of the first vector is less than or equal to the corresponding component of the second vector.

Parameters
a (Vector2)

First vector.

b (Vector2)

Second vector.

Return Values
(bool)

If each component of the first vector is less than or equal to the corresponding component of the second vector, true, otherwise false.

componentAllGreaterThan(a, b)

Returns whether each component of the first vector is greater than the corresponding component of the second vector.

Parameters
a (Vector2)

First vector.

b (Vector2)

Second vector.

Return Values
(bool)

If each component of the first vector is greater than the corresponding component of the second vector, true, otherwise false.

componentAllGreaterThanOrEqual(a, b)

Returns whether each component of the first vector is greater than or equal to the corresponding component of the second vector.

Parameters
a (Vector2)

First vector.

b (Vector2)

Second vector.

Return Values
(bool)

If each component of the first vector is greater than or equal to the corresponding component of the second vector, true, otherwise false.

dotProduct(v1, v2)

Calculates the dot product of two vectors.

Parameters
v1 (Vector2)

The first vector.

v2 (Vector2)

The second vector.

Return Values
(float)

The dot product of the vectors.

pseudoCrossProduct(left, right)

Calculates pseudo-cross product of two 2D vectors. U x V = Uy * Vx - Ux * Vy.

Parameters
left (Vector2)

The first vector.

right (Vector2)

The second vector.

Return Values
(float)

The pseudo-cross product of the vectors.

isfinite(vec)

Overloading of kanzi::isfinite for kanzi::Vector2.

Parameters
vec (Vector2)

Vector2 value.

Return Values
(bool)

If both elements of the Vector2 have finite value, true, otherwise false.