Vector2

Objects

Description

class Vector2

Constructor

new Vector2(x, y)

Creates a new Vector2 from the passed x and y coordinates.

Parameters

Name Type Description
x number
y number

Members

x : number

y : number

Methods

toString() string

Returns a string with the Vector2 coordinates.

getClassName() string

Returns the string "Vector2"

getHashCode() number

Returns the Vector2 hash code as a number.

toArray(array, index) Vector2

Sets the Vector2 coordinates in the passed array or Float32Array from the passed index.

Returns the Vector2.

Parameters

Name Type Description
array FloatArray
optional index number

asArray() number[]

Returns a new array with 2 elements : the Vector2 coordinates.

copyFrom(source) Vector2

Sets the Vector2 coordinates with the passed Vector2 coordinates.

Returns the updated Vector2.

Parameters

Name Type Description
source Vector2

copyFromFloats(x, y) Vector2

Sets the Vector2 coordinates with the passed floats.

Returns the updated Vector2.

Parameters

Name Type Description
x number
y number

set(x, y) Vector2

Sets the Vector2 coordinates with the passed floats.

Returns the updated Vector2.

Parameters

Name Type Description
x number
y number

add(otherVector) Vector2

Returns a new Vector2 set with the addition of the current Vector2 and the passed one coordinates.

Parameters

Name Type Description
otherVector Vector2

addToRef(otherVector, result) Vector2

Sets the "result" coordinates with the addition of the current Vector2 and the passed one coordinates.

Returns the Vector2.

Parameters

Name Type Description
otherVector Vector2
result Vector2

addInPlace(otherVector) Vector2

Set the Vector2 coordinates by adding the passed Vector2 coordinates.

Returns the updated Vector2.

Parameters

Name Type Description
otherVector Vector2

addVector3(otherVector) Vector2

Returns a new Vector2 by adding the current Vector2 coordinates to the passed Vector3 x, y coordinates.

Parameters

Name Type Description
otherVector Vector3

subtract(otherVector) Vector2

Returns a new Vector2 set with the subtracted coordinates of the passed one from the current Vector2.

Parameters

Name Type Description
otherVector Vector2

subtractToRef(otherVector, result) Vector2

Sets the "result" coordinates with the subtraction of the passed one from the current Vector2 coordinates.

Returns the Vector2.

Parameters

Name Type Description
otherVector Vector2
result Vector2

subtractInPlace(otherVector) Vector2

Sets the current Vector2 coordinates by subtracting from it the passed one coordinates.

Returns the updated Vector2.

Parameters

Name Type Description
otherVector Vector2

multiplyInPlace(otherVector) Vector2

Multiplies in place the current Vector2 coordinates by the passed ones.

Returns the updated Vector2.

Parameters

Name Type Description
otherVector Vector2

multiply(otherVector) Vector2

Returns a new Vector2 set with the multiplication of the current Vector2 and the passed one coordinates.

Parameters

Name Type Description
otherVector Vector2

multiplyToRef(otherVector, result) Vector2

Sets "result" coordinates with the multiplication of the current Vector2 and the passed one coordinates.

Returns the Vector2.

Parameters

Name Type Description
otherVector Vector2
result Vector2

multiplyByFloats(x, y) Vector2

Returns a new Vector2 set with the Vector2 coordinates multiplied by the passed floats.

Parameters

Name Type Description
x number
y number

divide(otherVector) Vector2

Returns a new Vector2 set with the Vector2 coordinates divided by the passed one coordinates.

Parameters

Name Type Description
otherVector Vector2

divideToRef(otherVector, result) Vector2

Sets the "result" coordinates with the Vector2 divided by the passed one coordinates.

Returns the Vector2.

Parameters

Name Type Description
otherVector Vector2
result Vector2

negate() Vector2

Returns a new Vector2 with current Vector2 negated coordinates.

scaleInPlace(scale) Vector2

Multiply the Vector2 coordinates by scale.

Returns the updated Vector2.

Parameters

Name Type Description
scale number

scale(scale) Vector2

Returns a new Vector2 scaled by "scale" from the current Vector2.

Parameters

Name Type Description
scale number

equals(otherVector) boolean

Boolean : True if the passed vector coordinates strictly equal the current Vector2 ones.

Parameters

Name Type Description
otherVector Vector2

equalsWithEpsilon(otherVector, epsilon) boolean

Boolean : True if the passed vector coordinates are close to the current ones by a distance of epsilon.

Parameters

Name Type Description
otherVector Vector2
optional epsilon number

length() number

Returns the vector length (float).

lengthSquared() number

Returns the vector squared length (float);

normalize() Vector2

Normalize the vector.

Returns the updated Vector2.

clone() Vector2

Returns a new Vector2 copied from the Vector2.

static Zero() Vector2

Returns a new Vector2(0, 0)

static One() Vector2

Returns a new Vector2(1, 1)

static FromArray(array, offset) Vector2

Returns a new Vector2 set from the passed index element of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
optional offset number

static FromArrayToRef(array, offset, result) void

Sets "result" from the passed index element of the passed array.

Parameters

Name Type Description
array ArrayLike<number>
offset number
result Vector2

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

Retuns a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the passed four Vector2.

Parameters

Name Type Description
value1 Vector2
value2 Vector2
value3 Vector2
value4 Vector2

static Clamp(value, min, max) Vector2

Returns a new Vector2 set with same the coordinates than "value" ones if the vector "value" is in the square defined by "min" and "max".

If a coordinate of "value" is lower than "min" coordinates, the returned Vector2 is given this "min" coordinate.

If a coordinate of "value" is greater than "max" coordinates, the returned Vector2 is given this "max" coordinate.

Parameters

Name Type Description
value Vector2
min Vector2
max Vector2

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

Returns a new Vector2 located for "amount" (float) on the Hermite spline defined by the vectors "value1", "value3", "tangent1", "tangent2".

Parameters

Name Type Description
value1 Vector2
tangent1 Vector2
value2 Vector2
tangent2 Vector2

static Lerp(start, end, amount) Vector2

Returns a new Vector2 located for "amount" (float) on the linear interpolation between the vector "start" adn the vector "end".

Parameters

Name Type Description
start Vector2
end Vector2
amount number

static Dot(left, right) number

Returns the dot product (float) of the vector "left" and the vector "right".

Parameters

Name Type Description
left Vector2
right Vector2

static Normalize(vector) Vector2

Returns a new Vector2 equal to the normalized passed vector.

Parameters

Name Type Description
vector Vector2

static Minimize(left, right) Vector2

Returns a new Vecto2 set with the minimal coordinate values from the "left" and "right" vectors.

Parameters

Name Type Description
left Vector2
right Vector2

static Maximize(left, right) Vector2

Returns a new Vecto2 set with the maximal coordinate values from the "left" and "right" vectors.

Parameters

Name Type Description
left Vector2
right Vector2

static Transform(vector, transformation) Vector2

Returns a new Vecto2 set with the transformed coordinates of the passed vector by the passed transformation matrix.

Parameters

Name Type Description
vector Vector2
transformation Matrix

static TransformToRef(vector, transformation, result) void

Transforms the passed vector coordinates by the passed transformation matrix and stores the result in the vector "result" coordinates.

Parameters

Name Type Description
vector Vector2
transformation Matrix
result Vector2

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

Boolean : True if the point "p" is in the triangle defined by the vertors "p0", "p1", "p2"

Parameters

Name Type Description
p Vector2
p0 Vector2
p1 Vector2

static Distance(value1, value2) number

Returns the distance (float) between the vectors "value1" and "value2".

Parameters

Name Type Description
value1 Vector2
value2 Vector2

static DistanceSquared(value1, value2) number

Returns the squared distance (float) between the vectors "value1" and "value2".

Parameters

Name Type Description
value1 Vector2
value2 Vector2

static Center(value1, value2) Vector2

Returns a new Vecto2 located at the center of the vectors "value1" and "value2".

Parameters

Name Type Description
value1 Vector2
value2 Vector2

static DistanceOfPointFromSegment(p, segA, segB) number

Returns the shortest distance (float) between the point "p" and the segment defined by the two points "segA" and "segB".

Parameters

Name Type Description
p Vector2
segA Vector2
segB Vector2