CLASSES
TagsA - Z

Vector2

Objects

Description

class Vector2

Represent a point in a 2D space.

Constructor

new Vector2(x, y)

Creates a new Vector2

Parameters

Name Type Description
x number The X coordinate of another vector
y number The Y coordinate of another vector

Members

x : number

The first coordinate

y : number

The second coordinate

Methods

toString() → string

Returns a string representation of the vector

getClassName() → string

getHashCode() → number

toArray(array, index) → Vector2

Fills an array from a given index with the vector's coordinates

Parameters

Name Type Description
array number[] The given array
optional index number default : 0 The given index

asArray() → number[]

Returns an array representation of the vector

copyFrom(source) → Vector2

Copies another vector

Parameters

Name Type Description
source Vector2 The source vector

copyFromFloats(x, y) → Vector2

Copies another vector in float form

Parameters

Name Type Description
x number The X coordinate of another vector
y number The Y coordinate of another vector

add(otherVector) → Vector2

Adds an another vector and returns the result as a new vector

Parameters

Name Type Description
otherVector Vector2

addToRef(otherVector, result) → Vector2

Parameters

Name Type Description
otherVector Vector2
result Vector2 The existing vector

addInPlace(otherVector) → Vector2

Parameters

Name Type Description
otherVector Vector2

addVector3(otherVector) → Vector2

Adds the vector, the vector3's x and y

Parameters

Name Type Description
otherVector Vector3

subtract(otherVector) → Vector2

Substracts another vector and returns the result in a new vector

Parameters

Name Type Description
otherVector Vector2

subtractToRef(otherVector, result) → Vector2

Parameters

Name Type Description
otherVector Vector2
result Vector2 The existing vector

subtractInPlace(otherVector) → Vector2

Substracts another vector

Parameters

Name Type Description
otherVector Vector2

multiplyInPlace(otherVector) → Vector2

Multiply by another vector

Parameters

Name Type Description
otherVector Vector2

multiply(otherVector) → Vector2

Multiply by another vector and returns the result in a new vector

Parameters

Name Type Description
otherVector Vector2

multiplyToRef(otherVector, result) → Vector2

Multiply by another vector into a third target vector

Parameters

Name Type Description
otherVector Vector2
result Vector2 The existing vector

multiplyByFloats(x, y) → Vector2

Multiply by another vector in float form and returns the result in a new vector

Parameters

Name Type Description
x number The X coordinate of another vector
y number The Y coordinate of another vector

divide(otherVector) → Vector2

Divides by another vector and returns the result nin a new vector

Parameters

Name Type Description
otherVector Vector2

divideToRef(otherVector, result) → Vector2

Divides by another vector into a third target vector

Parameters

Name Type Description
otherVector Vector2
result Vector2 The existing vector

negate() → Vector2

Returns the opposite vector, that is the vector with opposite coordinates

scaleInPlace(scale) → Vector2

Scales the vector with the given factor

Parameters

Name Type Description
scale number The scaling factor

scale(scale) → Vector2

Scales the vector and retruns the result as a new vector

Parameters

Name Type Description
scale number The scaling factor

equals(otherVector) → boolean

Tests if two vectors are equal Returns true if X,Y coordinates are equal

Parameters

Name Type Description
otherVector Vector2

equalsWithEpsilon(otherVector, epsilon) → boolean

Parameters

Name Type Description
otherVector Vector2
optional epsilon number

length() → number

The length of the vector

lengthSquared() → number

The squared length of the vector

normalize() → Vector2

Normalizes a vector

clone() → Vector2

Clones a vector

static Zero() → Vector2

Returns a new Vector2 with x and y to zero

static FromArray(array, offset) → Vector2

Creates a new vector from a given array

Parameters

Name Type Description
array number[] The given array
optional offset number The first index of the array to look at

static FromArrayToRef(array, offset, result) → void

Sets an existing vector from a given array

Parameters

Name Type Description
array number[] The given array
offset number The first index of the array to look at
result Vector2 The existing vector

static CatmullRom(value1, value2, value3, value4, amount) → Vector2

Performs a Catmull-Rom interpolation using the specified positions. When the method completes, returns the result of the Catmull-Rom interpolation

Parameters

Name Type Description
value1 Vector2 first vector
value2 Vector2 second vector
value3 Vector2 The third position in the interpolation.
value4 Vector2 The fourth position in the interpolation.

static Clamp(value, min, max) → Vector2

Restricts a value to be within a specified range.

Parameters

Name Type Description
value Vector2 The value to clamp
min Vector2 The minimum value
max Vector2 The maximum value

static Hermite(value1, tangent1, value2, tangent2, amount) → Vector2

Performs a Hermite spline interpolation.

Parameters

Name Type Description
value1 Vector2 first vector
tangent1 Vector2 First source tangent vector.
value2 Vector2 second vector
tangent2 Vector2 Second source tangent vector.

static Lerp(start, end, amount) → Vector2

Performs a linear interpolation between two vectors.

Parameters

Name Type Description
start Vector2 interpolation start vector
end Vector2 interpolation end vector
amount number Weighting factor

static Dot(left, right) → number

Dot product between two vectors

Parameters

Name Type Description
left Vector2 The vector to maximize
right Vector2 the vector used to maximize

static Normalize(vector) → Vector2

Normalizes a vector

Parameters

Name Type Description
vector Vector2 The vector to transform

static Minimize(left, right) → Vector2

Minimizes the left vector with the right vector

Parameters

Name Type Description
left Vector2 The vector to maximize
right Vector2 the vector used to maximize

static Maximize(left, right) → Vector2

Maximizes the left vector with the right vector

Parameters

Name Type Description
left Vector2 The vector to maximize
right Vector2 the vector used to maximize

static Transform(vector, transformation) → Vector2

Transforms a vector into a new vector

Parameters

Name Type Description
vector Vector2 The vector to transform
transformation Matrix The transformation matrix

static TransformToRef(vector, transformation, result) → void

Parameters

Name Type Description
vector Vector2 The vector to transform
transformation Matrix The transformation matrix
result Vector2 The existing vector

static PointInTriangle(p, p0, p1, p2) → boolean

Parameters

Name Type Description
p Vector2
p0 Vector2
p1 Vector2

static Distance(value1, value2) → number

Returns the distance between two vectors

Parameters

Name Type Description
value1 Vector2 first vector
value2 Vector2 second vector

static DistanceSquared(value1, value2) → number

Parameters

Name Type Description
value1 Vector2 first vector
value2 Vector2 second vector

static Center(value1, value2) → Vector2

Parameters

Name Type Description
value1 Vector2 first vector
value2 Vector2 second vector

static DistanceOfPointFromSegment(p, segA, segB) → number

Parameters

Name Type Description
p Vector2
segA Vector2
segB Vector2