module Geode::CommonVector(T, N)
Overview
Common functionality across all vector types.
This type primarily serves as a means to unify VectorN(T)
and Vector(T, N)
types.
Included Modules
- Geode::VectorComparison(N)
- Geode::VectorGeometry(N)
- Geode::VectorMatrices(T, N)
- Geode::VectorOperations(N)
- Indexable(T)
Direct including types
Defined in:
geode/vectors/common.crInstance Method Summary
-
#inspect(io : IO) : Nil
Produces a debugger-friendly string representation of the vector.
-
#map(& : T -> U) : CommonVector forall U
Returns a new vector where components are mapped by the given block.
-
#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. -
#size
Returns the number of components in this vector.
-
#to_s(io : IO) : Nil
Produces a string representation of the vector.
-
#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.
Instance methods inherited from module Geode::VectorOperations(N)
&*(scalar : Number) : CommonVector
&*,
&+(other : CommonVector(T, N)) : CommonVector forall T
&+,
&-(other : CommonVector(T, N)) : CommonVector forall T
&-,
*(scalar : Number) : CommonVector
*,
+(other : CommonVector(T, N)) : CommonVector forall T
+,
-(other : CommonVector(T, N)) : CommonVector forall T- : self -, /(scalar : Number) : CommonVector /, //(scalar : Number) : CommonVector //, abs : self abs, abs2 : self abs2, ceil : self ceil, clamp(min : CommonVector(T, N), max : CommonVector(T, N)) : CommonVector forall T
clamp(min, max) : CommonVector
clamp(range : Range(CommonVector(T, N), CommonVector(T, N))) : CommonVector forall T
clamp(range : Range) : CommonVector clamp, edge(edge : CommonVector(T, N)) : self forall T
edge(edge : T) : self forall T edge, floor : self floor, fraction : self fraction, lerp(other : CommonVector(T, N), t : Number) : CommonVector forall T lerp, round(mode : Number::RoundingMode = :ties_even) : self
round(digits : Number, base = 10, *, mode : Number::RoundingMode = :ties_even) : self round, scale(vector : CommonVector(T, N)) : CommonVector forall T
scale(amount : Number) : CommonVector scale, scale!(vector : CommonVector(T, N)) : CommonVector forall T
scale!(amount : Number) : CommonVector scale!, sign : self sign
Instance methods inherited from module Geode::VectorMatrices(T, N)
&*(matrix : CommonMatrix(U, M, M)) : CommonVector forall U, M
&*,
*(matrix : CommonMatrix(U, M, M)) : CommonVector forall U, M
*,
to_column : CommonMatrix
to_column,
to_row : CommonMatrix
to_row
Instance methods inherited from module Geode::VectorGeometry(N)
angle(other : CommonVector(T, N)) : Number forall T
angle,
dot(other : CommonVector(T, N)) forall T
dot,
dot!(other : CommonVector(T, N)) forall T
dot!,
forward(surface : CommonVector(T, N)) : CommonVector forall T
forward,
length
length,
mag
mag,
mag2
mag2,
normalize : CommonVector
normalize,
project(other : CommonVector(T, N)) : CommonVector forall T
project,
reflect(surface : CommonVector(T, N)) : CommonVector forall T
reflect,
refract(surface : CommonVector(T, N), eta : Number) : CommonVector forall T
refract,
scale_to(length : Number) : CommonVector
scale_to
Instance methods inherited from module Geode::VectorComparison(N)
==(other : CommonVector(T, N)) forall T
==,
compare(other : CommonVector(T, N)) : CommonVector(Int32, N) forall T
compare,
eq?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T
eq?,
ge?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T
ge?,
gt?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T
gt?,
le?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T
le?,
lt?(other : CommonVector(T, N)) : CommonVector(Bool, N) forall T
lt?,
near_zero?(tolerance)
near_zero?,
zero?
zero?
Instance Method Detail
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)
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)
Produces a string representation of the vector.
The format is: (x, y, z)
but with the corresponding number of components.
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)