Vec2

class cee.Vec2()

An immutable 2d vector with x, y values.

Used e.g. for texture coordinates

Constructors

Properties


Constructors

Vec2.constructor(x, y)
Arguments:
  • x (number) – None

  • y (number) – None

Constructor

Return type:

Vec2

Properties

Vec2.x
Type:

number

The x coordinate of the vector

Vec2.y
Type:

number

The y coordinate of the vector

Methods

equals

Vec2.equals(other)
Arguments:

Returns true if the vectors are equal

Return type:

boolean

getLength

Vec2.getLength()

Returns the length of the vector (sqrt(x^2 + y^2)).

Return type:

number

getLengthSquared

Vec2.getLengthSquared()

Returns the squared length of the vector

Return type:

number

getNegated

Vec2.getNegated()

Returns a negated version of the vector.

Return type:

Vec2

getNormalized

Vec2.getNormalized()

Returns a normalized version of the vector.

Return type:

Vec2

static add

Vec2.add(a, b)
Arguments:

Returns the result of adding the two vectors

Return type:

Vec2

static dot

Vec2.dot(a, b)
Arguments:

Returns the dot product of the 2 vectors

Return type:

number

static from

Vec2.from(vec)
Arguments:

Creates a new Vec2 instance from any object with x and y properties.

Return type:

Vec2

static fromArray

Vec2.fromArray(arr)
Arguments:
  • arr (ArrayLike) – None

Creates a new Vec2 instance from the first 2 elements of the given array.

Return type:

Vec2

static negate

Vec2.negate(vec)
Arguments:

Returns the negation of the given vector

Return type:

Vec2

static scale

Vec2.scale(vec, factor)
Arguments:
  • vec (Vec2Like) – None

  • factor (number) – None

Returns the result of scaling the given vector by the given factor

Return type:

Vec2

static sub

Vec2.sub(a, b)
Arguments:

Returns the result of subtracting vector b from vector a

Return type:

Vec2