Math.Vector

(in ./Carbon/Math/Vector.lua)

Abstract Template Vector<N>

Provides a metaprogramming-driven method of generating N-length vectors.

Presently has a hard maximum component count of 26, can be expanded upon request.

Inherits OOP.Object


Methods

class public Vector<N>:New(...)

Returns Vector<N>

object public Vector<N>:Init(...)

Returns void

  • optional ...: The arguments to the intialization. Should be N arguments long.

Creates a new Vector with N components.


object public (number, Vector<N>)

Returns

  • required other: The object to multiply with; a vector, matrix, or number.
  • optional out: Where to put the resulting data, if specified.


unknown public Vector:Generate(uint length, [dictionary parameters])

Returns Vector<length>

  • required length: The length of the vector.
  • optional parameters: Options for generating the class:

Generates a new Vector class with the given keys and parameters. Results are cached, but this method may still be slow. It performs runtime code generation and template parsing on each generated class.

The following parameters are valid:

  • number NormalizedLength (1): The length the vector reaches when normalized.
  • number DefaultValue (0): The value to initialize all members to if not given.
  • list<number> DefaultValues: A list of values to initialize specific keys to. If any are given, all keys must be specified.


object public Vector:LooseScale(number scalar)

Returns loose<Vector>

  • required scalar: The value to scale by.

Scales the Vector and returns it in loose form.


object public Vector:Scale(number scalar, [Vector out])

Returns Vector

  • required scalar: The value to scale by.
  • optional out: Where to put the resulting data.

Scales the Vector, optionally outputting into an existing Vector.


object public Vector:Scale!(number scalar)

Returns Vector

object public Vector:ScaleInPlace(number scalar)

Returns Vector

  • required scalar: The value to scale by.

Scales the Vector in place.


object public Vector<N>:DotMultiply(Vector<N> other)

Returns number

  • required other: The Vector to multiply with.

Performs a dot product between two vectors.


object public Vector<N>:GetComponents()

Returns tuple<N, unumber>

Returns the individual components of the Vector<N> in order. Much faster than unpack.


object public Vector<N>:Length()

Returns unumber

Returns the length of the vector.


object public Vector<N>:LengthSquared()

Returns unumber

Returns the length of the vector squared.


object public Vector<N>:Normalize([Vector<N> out])

Returns out

  • optional out: Where to place the data of the normalized vector. A new Vector<N> if not given.

Normalizes the Vector<N> object, optionally outputting the data to an existing Vector<N>.


object public Vector<N>:Normalize!()

Returns self

object public Vector<N>:NormalizeInPlace()

Returns self

Normalizes the vector in-place.

Called in Carbide as Vector:Normalize!()


unknown private Vector:__generate_method(string body, dictionary arguments, [dictionary env])

Returns function

  • required body: Template-enabled code to return a function.
  • required arguments: Arguments to the template
  • optional env: The environment to generate the method under.

Generates a method using Carbon's TemplateEngine and handles errors.


Properties

[none]