Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vector2

Class representing a vector containing 2 coordinates

Hierarchy

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

xSearch playground for x

x: number

defines the first coordinate

ySearch playground for y

y: number

defines the second coordinate

Methods

addSearch playground for add

  • Add another vector with the current one

    Parameters

    Returns Vector2

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

addInPlaceSearch playground for addInPlace

  • Set the Vector2 coordinates by adding the given Vector2 coordinates

    Parameters

    Returns Vector2

    the current updated Vector2

addToRefSearch playground for addToRef

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

    Parameters

    Returns Vector2

    the unmodified current Vector2

addVector3Search playground for 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

asArraySearch playground for asArray

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

    Returns number[]

    a new array with 2 elements: the Vector2 coordinates.

cloneSearch playground for clone

  • Gets a new Vector2 copied from the Vector2

    Returns Vector2

    a new Vector2

copyFromSearch playground for copyFrom

  • Sets the Vector2 coordinates with the given Vector2 coordinates

    Parameters

    Returns Vector2

    the current updated Vector2

copyFromFloatsSearch playground for 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

divideSearch playground for 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

divideInPlaceSearch playground for divideInPlace

  • Divides the current Vector2 coordinates by the given ones

    Parameters

    Returns Vector2

    the current updated Vector2

divideToRefSearch playground for divideToRef

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

    Parameters

    Returns Vector2

    the unmodified current Vector2

equalsSearch playground for equals

  • Gets a boolean if two vectors are equals

    Parameters

    Returns boolean

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

equalsWithEpsilonSearch playground for equalsWithEpsilon

  • Gets a boolean if two vectors are equals (using an epsilon value)

    Parameters

    • otherVector: DeepImmutable<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.

floorSearch playground for floor

  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

fractSearch playground for fract

  • Gets a new Vector2 from current Vector2 floored values

    Returns Vector2

    a new Vector2

fromArraySearch playground for fromArray

  • Update the current vector from an array

    Parameters

    • array: FloatArray

      defines the destination array

    • Optional index: number

      defines the offset in the destination array

    Returns Vector2

    the current Vector3

getClassNameSearch playground for getClassName

  • getClassName(): string
  • Gets class name

    Returns string

    the string "Vector2"

getHashCodeSearch playground for getHashCode

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

    Returns number

    the Vector2 hash code as a number

lengthSearch playground for length

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

    Returns number

    the vector length (float)

lengthSquaredSearch playground for lengthSquared

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

    Returns number

    the vector squared length (float)

multiplySearch playground for multiply

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

    Parameters

    Returns Vector2

    a new Vector2

multiplyByFloatsSearch playground for 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

multiplyInPlaceSearch playground for multiplyInPlace

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

    Parameters

    Returns Vector2

    the current updated Vector2

multiplyToRefSearch playground for multiplyToRef

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

    Parameters

    Returns Vector2

    the unmodified current Vector2

negateSearch playground for negate

  • Gets a new Vector2 with current Vector2 negated coordinates

    Returns Vector2

    a new Vector2

negateInPlaceSearch playground for negateInPlace

  • Negate this vector in place

    Returns Vector2

    this

negateToRefSearch playground for negateToRef

  • Negate the current Vector2 and stores the result in the given vector "result" coordinates

    Parameters

    • result: Vector2

      defines the Vector3 object where to store the result

    Returns Vector2

    the current Vector2

normalizeSearch playground for normalize

  • Normalize the vector

    Returns Vector2

    the current updated Vector2

scaleSearch playground for scale

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

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    a new Vector2

scaleAndAddToRefSearch playground for 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

scaleInPlaceSearch playground for scaleInPlace

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

    Parameters

    • scale: number

      defines the scaling factor

    Returns Vector2

    the current updated Vector2

scaleToRefSearch playground for 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

setSearch playground for 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

subtractSearch playground for 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

subtractInPlaceSearch playground for subtractInPlace

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

    Parameters

    Returns Vector2

    the current updated Vector2

subtractToRefSearch playground for subtractToRef

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

    Parameters

    Returns Vector2

    the unmodified current Vector2

toArraySearch playground for toArray

  • Sets the Vector2 coordinates in the given array or Float32Array from the given index.

    Parameters

    • array: FloatArray

      defines the source array

    • Optional index: number

      defines the offset in source array

    Returns Vector2

    the current Vector2

toStringSearch playground for toString

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

    Returns string

    a string with the Vector2 coordinates

Static CatmullRomSearch playground for CatmullRom

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

    Parameters

    Returns Vector2

    a new Vector2

Static CenterSearch playground for Center

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

    Parameters

    Returns Vector2

    a new Vector2

Static CenterToRefSearch playground for CenterToRef

Static ClampSearch playground for 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

    Returns Vector2

    a new Vector2

Static DistanceSearch playground for Distance

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

    Parameters

    Returns number

    the distance between vectors

Static DistanceOfPointFromSegmentSearch playground for DistanceOfPointFromSegment

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

    Parameters

    Returns number

    the shortest distance

Static DistanceSquaredSearch playground for DistanceSquared

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

    Parameters

    Returns number

    the squared distance between vectors

Static DotSearch playground for Dot

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

    Parameters

    Returns number

    the dot product (float)

Static FromArraySearch playground for FromArray

  • Gets a new Vector2 set from the given index element of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the data source

    • Optional offset: number

      defines the offset in the data source

    Returns Vector2

    a new Vector2

Static FromArrayToRefSearch playground for FromArrayToRef

  • Sets "result" from the given index element of the given array

    Parameters

    • array: DeepImmutable<ArrayLike<number>>

      defines the data source

    • offset: number

      defines the offset in the data source

    • result: Vector2

      defines the target vector

    Returns void

Static HermiteSearch playground for Hermite

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

    Parameters

    Returns Vector2

    a new Vector2

Static LerpSearch playground for Lerp

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

    Parameters

    Returns Vector2

    a new Vector2

Static MaximizeSearch playground for Maximize

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

    Parameters

    Returns Vector2

    a new Vector2

Static MinimizeSearch playground for Minimize

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

    Parameters

    Returns Vector2

    a new Vector2

Static NormalizeSearch playground for Normalize

  • Returns a new Vector2 equal to the normalized given vector

    Parameters

    Returns Vector2

    a new Vector2

Static OneSearch playground for One

  • Gets a new Vector2(1, 1)

    Returns Vector2

    a new Vector2

Static PointInTriangleSearch playground for PointInTriangle

  • Determines if a given vector is included in a triangle

    Parameters

    Returns boolean

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

Static TransformSearch playground for Transform

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

    Parameters

    Returns Vector2

    a new Vector2

Static TransformToRefSearch playground for TransformToRef

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

    Parameters

    Returns void

Static ZeroSearch playground for Zero

  • Gets a new Vector2(0, 0)

    Returns Vector2

    a new Vector2

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Static method