Geode::Vector(T, N)
Inherits Geode::CommonVector < Geode::VectorOperations < Geode::VectorMatrices < Geode::VectorGeometry < Geode::VectorComparison < Indexable < Enumerable < Iterable < Struct < Value < Object
Generic vector type. Provides a collection of scalars of the same type.
T is the scalar type. N is a positive integer indicating the number of components.
Constructors
Constructs the vector with pre-existing values.
The memory allocated for components must match the size of the vector.
Creates a new matrix from a collection of components.
The size of components must be equal to N.
Vector(Int32, 5).new([1, 2, 3, 4, 5]) # => (1, 2, 3, 4, 5)
Constructs the vector by yielding for each component.
The value of each component should be returned from the block. The block will be given the index of each component as an argument.
Vector(Int32, 3).new { |i| i * 5 } # => (0, 5, 10)
Constructs a zero-vector.
Each component will have a scalar value equal to the type's'zero value.
This is done by calling T.zero for each component.
The type T must have a class method
Vector(Float32, 3).zero # => (0.0, 0.0, 0.0)
Class methods
Constructs a vector with existing components.
The type of the components is specified by the type parameter. Each value is cast to the type T.
Vector(Float32, 5)[1, 2, 3, 4, 5] # => (1.0, 2.0, 3.0, 4.0, 5.0)
Instance methods
Computes the cross-product of this and another vector.
Raises a compilation error if the vector size (N) isn't 3.
Vector[1, 3, 4].cross(Vector[2, -5, 8]) # => (44, 0, -11)
Returns a new vector where components are mapped by the given block.
vector = Vector[1, 2, 3]
vector.map { |v| v * 2 } # => (2, 4, 6)
Returns a pointer to the data for this vector.
The components are tightly packed and ordered consecutively in memory.
Retrieves the scalar value of the component at the given index, without checking size boundaries.
End-users should never invoke this method directly.
Instead, methods like #[] and #[]? should be used.
This method should only be directly invoked if the index is certain to be in bounds.
Retrieves the w component.
Raises a compilation error if the vector size (N) is less than 4.
Retrieves the x component.
Raises a compilation error if the vector size (N) is less than 1.
Retrieves the y component.
Raises a compilation error if the vector size (N) is less than 2.
Retrieves the z component.
Raises a compilation error if the vector size (N) is less than 3.
Macros
Constructs the vector with existing components.
The type of the components is derived from the type of each argument. The size of the vector is determined by the number of components.
Vector[1, 2, 3] # => (1, 2, 3)