Module pico8lib.vector

Vectors (points and directions)

Class Vector

vector.x X coordinate
vector.y Y coordinate
vector:__eq (a, b) Equality operation
vector:__unm (v) Unary Minus operation
vector:__add (a, b) Addition operation
vector:__sub (a, b) Subtraction operation
vector:__mul (a, b) Mutliplication operation, Scalar Product (alias scalarproduct)
vector:crossproduct (a, b) Cross Product
vector:__div (v, n) Division operation, Scalar Division
vector:__len (v) Magnitude (alias mag)
vector:__tostring (v) String representation
vector:magsqr (v) Magnitude squared
vector:angle (v) Angle of this vector
vector:normalize (v) Normalized vector
vector:contained (v, p1, p2) Vector contained within rectangle
vector:dset (v, idx) Store in persistent cartridge storage
vector:dget (idx) Retrieve from persistent cartridge storage
vector:rotate_90 (v) Return this vector rotated 90 degrees
vector:rotate_180 (v) Return this vector rotated 180 degrees
vector:rotate_270 (v) Return this vector rotated 270 degrees
vector:rotate_degrees (v, angle) Return this vector rotated a certain number of degrees
vector:rotate (v, angle) Return this vector rotated a certain angle
vector:from_polar (p) Construct a Euclidean vector from a polar vector
vector:to_polar (v) Return the polar version of this vector
vector:reflect (v, n) Reflect Vector across Normal
vector:__call (v[, t]) Constructor

Lookups

vector_directions_4 Cardinal directions as vectors {E, S, W, N}
vector_directions_8 Cardinal and diagonal directions as vectors {E, SE, S, SW, W, NW, N, NE}


Class Vector

vector.x
X coordinate
vector.y
Y coordinate
vector:__eq (a, b)
Equality operation

Parameters:

Returns:

    Boolean
vector:__unm (v)
Unary Minus operation

Parameters:

Returns:

    Vector
vector:__add (a, b)
Addition operation

Parameters:

Returns:

    Vector
vector:__sub (a, b)
Subtraction operation

Parameters:

Returns:

    Vector
vector:__mul (a, b)
Mutliplication operation, Scalar Product (alias scalarproduct)

Parameters:

Returns:

    number
vector:crossproduct (a, b)
Cross Product

Parameters:

Returns:

    number Magnitude of the cross product
vector:__div (v, n)
Division operation, Scalar Division

Parameters:

Returns:

    Vector
vector:__len (v)
Magnitude (alias mag)

Parameters:

Returns:

    number Magnitude of this Vector
vector:__tostring (v)
String representation

Parameters:

Returns:

    string [vector:0,0]
vector:magsqr (v)
Magnitude squared

Parameters:

Returns:

    number Magnitude of this Vector, squared
vector:angle (v)
Angle of this vector

Parameters:

Returns:

    number Angle [0-1) from the origin to this Vector
vector:normalize (v)
Normalized vector

Parameters:

Returns:

    Vector A Vector with the same angle as this Vector and magnitude 1
vector:contained (v, p1, p2)
Vector contained within rectangle

Parameters:

  • v Vector
  • p1 Vector Top left corner of rectangle
  • p2 Vector Bottom right corner of rectangle

Returns:

    boolean Is a within [p1,p2]?
vector:dset (v, idx)
Store in persistent cartridge storage

Parameters:

  • v Vector
  • idx int First storage index in [0,62], also uses idx+1
vector:dget (idx)
Retrieve from persistent cartridge storage

Parameters:

  • idx int First storage index in [0,62], also reads idx+1

Returns:

    Vector
vector:rotate_90 (v)
Return this vector rotated 90 degrees

Parameters:

Returns:

    Vector A Vector with the same magnitude as this Vector and an angle rotated 90 degrees
vector:rotate_180 (v)
Return this vector rotated 180 degrees

Parameters:

Returns:

    Vector A Vector with the same magnitude as this Vector and an angle rotated 180 degrees
vector:rotate_270 (v)
Return this vector rotated 270 degrees

Parameters:

Returns:

    Vector A Vector with the same magnitude as this Vector and an angle rotated 270 degrees
vector:rotate_degrees (v, angle)
Return this vector rotated a certain number of degrees

Parameters:

  • v Vector
  • angle number Angle of rotation in degrees

Returns:

    Vector A Vector with the same magnitude as this Vector and an angle rotated the given amount
vector:rotate (v, angle)
Return this vector rotated a certain angle

Parameters:

  • v Vector
  • angle number Angle of rotation [0,1)

Returns:

    Vector A Vector with the same magnitude as this Vector and an angle rotated the given amount
vector:from_polar (p)
Construct a Euclidean vector from a polar vector

Parameters:

  • p Polar {r:number,t:number}

Returns:

    Vector
vector:to_polar (v)
Return the polar version of this vector

Parameters:

Returns:

    Polar
vector:reflect (v, n)
Reflect Vector across Normal

Parameters:

Returns:

    Vector v reflected across n, as if n was perpendicular to a mirror
vector:__call (v[, t])
Constructor

Parameters:

Lookups

vector_directions_4
Cardinal directions as vectors {E, S, W, N}
vector_directions_8
Cardinal and diagonal directions as vectors {E, SE, S, SW, W, NW, N, NE}
generated by LDoc 1.5.0 Last updated 2024-09-08 15:22:01