Geode::CommonVector(T, N)
Inherits Geode::VectorOperations < Geode::VectorMatrices < Geode::VectorGeometry < Geode::VectorComparison < Indexable < Enumerable < Iterable
Common functionality across all vector types.
This type primarily serves as a means to unify VectorN(T) and Vector(T, N) types.
Instance methods
map
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)
map_with_index(offset = 0, & : T, Int32 -> U) : CommonVector(U, N) forall U
Like #map, but the block gets the component and its index as arguments.
Accepts an optional offset parameter, which to start the index at.
vector = Vector[1, 2, 3]
vector.map_with_index { |v, i| v * i } # => (0, 2, 6)
vector.map_with_index(3) { |v, i| v + i } # => (4, 6, 8)
to_s(io : IO) : Nil
Produces a string representation of the vector.
The format is: (x, y, z)
but with the corresponding number of components.
zip_map(other : CommonVector(U, N), & : T, U -> V) : CommonVector(V, N) forall U, V
Returns a new vector by iterating through each component of this vector and another.
v1 = Vector[1, 2, 3]
v2 = Vector[3, 2, 1]
v1.zip_map { |a, b| Math.min(a, b) } # => (1, 2, 1)