abstract struct Geode::VectorBase(T, N)
- Geode::VectorBase(T, N)
- Struct
- Value
- Object
Overview
Base type for all vectors with a specific dimensionality.
T is the scalar type. N is a positive integer indicating the number of components.
Included Modules
Direct Known Subclasses
Defined in:
geode/vectors/base.crConstructors
-
.new(array : StaticArray(T, N))
Constructs the vector with pre-existing values.
-
.new(other : CommonVector(T, M)) forall M
Copies the contents of another vector.
-
.new(&)
Constructs the vector by yielding for each component.
-
.zero : self
Constructs a zero-vector.
Instance Method Summary
-
#map(& : T -> U) : CommonVector forall U
Returns a new vector where components are mapped by the given block.
-
#to_slice : Slice(T)
Returns a slice that points to the components in this vector.
-
#to_unsafe : Pointer(T)
Returns a pointer to the data for this vector.
-
#unsafe_fetch(index : Int)
Retrieves the scalar value of the component at the given index, without checking size boundaries.
Instance methods inherited from module Geode::CommonVector(T, N)
inspect(io : IO) : Nil
inspect,
map(& : T -> U) : CommonVector forall U
map,
map_with_index(offset = 0, & : T, Int32 -> U) : CommonVector(U, N) forall U
map_with_index,
size
size,
to_s(io : IO) : Nil
to_s,
zip_map(other : CommonVector(U, N), & : T, U -> V) : CommonVector(V, N) forall U, V
zip_map
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?
Constructor Detail
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.
Vector3(Int32).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
Vector3(Float32).zero # => (0.0, 0.0, 0.0)
Instance Method Detail
Returns a new vector where components are mapped by the given block.
vector = Vector3.new(1, 2, 3)
vector.map { |v| v * 2 } # => (2, 4, 6)
Returns a slice that points to the components in this vector.
NOTE The returned slice is only valid for the caller's scope and sub-calls. The slice points to memory on the stack, it will be invalid after the caller returns.
Returns a pointer to the data for this vector.
The components are tightly packed and ordered consecutively in memory.
NOTE The returned pointer is only valid for the caller's scope and sub-calls. The pointer refers to memory on the stack, it will be invalid after the caller returns.
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.