Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector2

Class representing a vector containing 2 coordinates

Hierarchy

  • Vector2

Implements

Index

Constructors

constructor

  • new Vector2(x?: number, y?: number): Vector2
  • Creates a new Vector2 from the given x and y coordinates

    Parameters

    • Optional x: number

      defines the first coordinate

    • Optional y: number

      defines the second coordinate

    Returns Vector2

Properties

x

x: number

defines the first coordinate

y

y: number

defines the second coordinate

Methods

add

  • Add another vector with the current one

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2 set with the addition of the current Vector2 and the given one coordinates

addInPlace

  • Set the Vector2 coordinates by adding the given Vector2 coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    the current updated Vector2

addToRef

  • Sets the "result" coordinates with the addition of the current Vector2 and the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    • result: Vector2

      defines the target vector

    Returns Vector2

    the unmodified current Vector2

addVector3

  • Gets a new Vector2 by adding the current Vector2 coordinates to the given Vector3 x, y coordinates

    Parameters

    • otherVector: Vector3

      defines the other vector

    Returns Vector2

    a new Vector2

asArray

  • asArray(): number[]
  • Copy the current vector to an array

    Returns number[]

    a new array with 2 elements: the Vector2 coordinates.

clone

  • Gets a new Vector2 copied from the Vector2

    Returns Vector2

    a new Vector2

copy

  • Updates the Vector2 from the sparsely populated value.

    Parameters

    • from: Partial<Vector2Like>

      The sparsely populated value to read from.

    Returns this

copyFrom

  • Sets the Vector2 coordinates with the given Vector2 coordinates

    Parameters

    • source: Vector2

      defines the source Vector2

    Returns Vector2

    the current updated Vector2

copyFromFloats

  • copyFromFloats(x: number, y: number): Vector2
  • Sets the Vector2 coordinates with the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    the current updated Vector2

divide

  • Returns a new Vector2 set with the Vector2 coordinates divided by the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2

divideInPlace

  • Divides the current Vector2 coordinates by the given ones

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    the current updated Vector2

divideToRef

  • Sets the "result" coordinates with the Vector2 divided by the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    • result: Vector2

      defines the target vector

    Returns Vector2

    the unmodified current Vector2

equals

  • equals(otherVector: Vector2): boolean
  • Gets a boolean if two vectors are equals

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns boolean

    true if the given vector coordinates strictly equal the current Vector2 ones

equalsWithEpsilon

  • equalsWithEpsilon(otherVector: Vector2, epsilon?: number): boolean
  • Gets a boolean if two vectors are equals (using an epsilon value)

    Parameters

    • otherVector: Vector2

      defines the other vector

    • Optional epsilon: number

      defines the minimal distance to consider equality

    Returns boolean

    true if the given vector coordinates are close to the current ones by a distance of epsilon.

floor

  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

fract

  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

getClassName

  • getClassName(): string
  • Gets class name

    Returns string

    the string "Vector2"

getHashCode

  • getHashCode(): number
  • Gets current vector hash code

    Returns number

    the Vector2 hash code as a number

length

  • length(): number
  • Gets the length of the vector

    Returns number

    the vector length (float)

lengthSquared

  • lengthSquared(): number
  • Gets the vector squared length

    Returns number

    the vector squared length (float)

multiply

  • Returns a new Vector2 set with the multiplication of the current Vector2 and the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2

multiplyByFloats

  • multiplyByFloats(x: number, y: number): Vector2
  • Gets a new Vector2 set with the Vector2 coordinates multiplied by the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    a new Vector2

multiplyInPlace

  • Multiplies in place the current Vector2 coordinates by the given ones

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    the current updated Vector2

multiplyToRef

  • Sets "result" coordinates with the multiplication of the current Vector2 and the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    • result: Vector2

      defines the target vector

    Returns Vector2

    the unmodified current Vector2

negate

  • Gets a new Vector2 with current Vector2 negated coordinates

    Returns Vector2

    a new Vector2

normalize

  • Normalize the vector

    Returns Vector2

    the current updated Vector2

scale

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

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    a new Vector2

scaleAndAddToRef

  • Scale the current Vector2 values by a factor and add the result to a given Vector2

    Parameters

    • scale: number

      defines the scale factor

    • result: Vector2

      defines the Vector2 object where to store the result

    Returns Vector2

    the unmodified current Vector2

scaleInPlace

  • scaleInPlace(scale: number): Vector2
  • Multiply the Vector2 coordinates by scale

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    the current updated Vector2

scaleToRef

  • Scale the current Vector2 values by a factor to a given Vector2

    Parameters

    • scale: number

      defines the scale factor

    • result: Vector2

      defines the Vector2 object where to store the result

    Returns Vector2

    the unmodified current Vector2

set

  • set(x: number, y: number): Vector2
  • Sets the Vector2 coordinates with the given floats

    Parameters

    • x: number

      defines the first coordinate

    • y: number

      defines the second coordinate

    Returns Vector2

    the current updated Vector2

subtract

  • Gets a new Vector2 set with the subtracted coordinates of the given one from the current Vector2

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    a new Vector2

subtractInPlace

  • Sets the current Vector2 coordinates by subtracting from it the given one coordinates

    Parameters

    • otherVector: Vector2

      defines the other vector

    Returns Vector2

    the current updated Vector2

subtractToRef

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

    Parameters

    • otherVector: Vector2

      defines the other vector

    • result: Vector2

      defines the target vector

    Returns Vector2

    the unmodified current Vector2

toArray

  • toArray(array: number[], index?: number): Vector2
  • Sets the Vector2 coordinates in the given array or Float32Array from the given index.

    Parameters

    • array: number[]

      defines the source array

    • Optional index: number

      defines the offset in source array

    Returns Vector2

    the current Vector2

toJSON

  • Returns a JSON representation of this vector. This is necessary due to the way Actors detect changes on components like the actor's transform. They do this by adding properties for observation, and we don't want these properties serialized.

    Returns Vector2Like

toString

  • toString(): string
  • Gets a string with the Vector2 coordinates

    Returns string

    a string with the Vector2 coordinates

Static CatmullRom

  • Gets a new Vector2 located for "amount" (float) on the CatmullRom spline defined by the given four Vector2

    Parameters

    • value1: Vector2

      defines 1st point of control

    • value2: Vector2

      defines 2nd point of control

    • value3: Vector2

      defines 3rd point of control

    • value4: Vector2

      defines 4th point of control

    • amount: number

      defines the interpolation factor

    Returns Vector2

    a new Vector2

Static Center

  • Gets a new Vector2 located at the center of the vectors "value1" and "value2"

    Parameters

    • value1: Vector2

      defines first vector

    • value2: Vector2

      defines second vector

    Returns Vector2

    a new Vector2

Static Clamp

  • 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

    • value: Vector2

      defines the value to clamp

    • min: Vector2

      defines the lower limit

    • max: Vector2

      defines the upper limit

    Returns Vector2

    a new Vector2

Static Distance

  • Gets the distance between the vectors "value1" and "value2"

    Parameters

    • value1: Vector2

      defines first vector

    • value2: Vector2

      defines second vector

    Returns number

    the distance between vectors

Static DistanceOfPointFromSegment

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

    Parameters

    • p: Vector2

      defines the middle point

    • segA: Vector2

      defines one point of the segment

    • segB: Vector2

      defines the other point of the segment

    Returns number

    the shortest distance

Static DistanceSquared

  • Returns the squared distance between the vectors "value1" and "value2"

    Parameters

    • value1: Vector2

      defines first vector

    • value2: Vector2

      defines second vector

    Returns number

    the squared distance between vectors

Static Dot

  • Gets the dot product of the vector "left" and the vector "right"

    Parameters

    • left: Vector2

      defines first vector

    • right: Vector2

      defines second vector

    Returns number

    the dot product (float)

Static FromArray

  • FromArray(array: ArrayLike<number>, offset?: number): Vector2
  • Gets a new Vector2 set from the given index element of the given array

    Parameters

    • array: ArrayLike<number>

      defines the data source

    • Optional offset: number

      defines the offset in the data source

    Returns Vector2

    a new Vector2

Static FromArrayToRef

  • FromArrayToRef(array: ArrayLike<number>, offset: number, result: Vector2): void
  • Sets "result" from the given index element of the given array

    Parameters

    • array: ArrayLike<number>

      defines the data source

    • offset: number

      defines the offset in the data source

    • result: Vector2

      defines the target vector

    Returns void

Static Hermite

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

    Parameters

    • value1: Vector2

      defines the 1st control point

    • tangent1: Vector2

      defines the outgoing tangent

    • value2: Vector2

      defines the 2nd control point

    • tangent2: Vector2

      defines the incoming tangent

    • amount: number

      defines the interpolation factor

    Returns Vector2

    a new Vector2

Static Lerp

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

    Parameters

    • start: Vector2

      defines the start vector

    • end: Vector2

      defines the end vector

    • amount: number

      defines the interpolation factor

    Returns Vector2

    a new Vector2

Static Maximize

  • Gets a new Vecto2 set with the maximal coordinate values from the "left" and "right" vectors

    Parameters

    Returns Vector2

    a new Vector2

Static Minimize

  • Gets a new Vector2 set with the minimal coordinate values from the "left" and "right" vectors

    Parameters

    Returns Vector2

    a new Vector2

Static Normalize

  • Returns a new Vector2 equal to the normalized given vector

    Parameters

    • vector: Vector2

      defines the vector to normalize

    Returns Vector2

    a new Vector2

Static One

  • Gets a new Vector2(1, 1)

    Returns Vector2

    a new Vector2

Static PointInTriangle

  • Determines if a given vector is included in a triangle

    Parameters

    • p: Vector2

      defines the vector to test

    • p0: Vector2

      defines 1st triangle point

    • p1: Vector2

      defines 2nd triangle point

    • p2: Vector2

      defines 3rd triangle point

    Returns boolean

    true if the point "p" is in the triangle defined by the vertors "p0", "p1", "p2"

Static Transform

  • Gets a new Vector2 set with the transformed coordinates of the given vector by the given transformation matrix

    Parameters

    • vector: Vector2

      defines the vector to transform

    • transformation: Matrix

      defines the matrix to apply

    Returns Vector2

    a new Vector2

Static TransformToRef

  • Transforms the given vector coordinates by the given transformation matrix and stores the result in the vector "result" coordinates

    Parameters

    • vector: Vector2

      defines the vector to transform

    • transformation: Matrix

      defines the matrix to apply

    • result: Vector2

      defines the target vector

    Returns void

Static Zero

  • Gets a new Vector2(0, 0)

    Returns Vector2

    a new Vector2