struct
Crame::Vector2
- Crame::Vector2
- Struct
- Value
- Object
Overview
A two-dimensional vector.
Defined in:
crame/vector2.crConstructors
-
.new(x : Float64, y : Float64)
Creates a vector given its x and y coordinates.
-
.new
Creates a vector of coordinate 0.
Instance Method Summary
- #!=(other : Vector2) : Bool
- #*(other : Number) : Vector2
- #+(other : Vector2) : Vector2
- #-(other : Vector2) : Vector2
- #- : Vector2
- #/(other : Number) : Vector2
- #//(other : Number) : Vector2
- #==(other : Vector2) : Bool
-
#cross(other : Vector2) : Float64
Returns the cross product of
selfwithother. -
#dot(other : Vector2) : Float64
Returns the dot product of
selfwithother. -
#length : Float64
Returns the magnitude of
self. -
#normalized : Vector2
Returns a normalized version of
self(its magnitude equal to 1). -
#normalized? : Bool
Returns
trueifselfis normalized,falseotherwise. -
#to_s(io : IO)
Same as
#inspect(io). -
#x : Float64
The x coordinate.
-
#x=(x : Float64)
The x coordinate.
-
#y : Float64
The y coordinate.
-
#y=(y : Float64)
The y coordinate.
Constructor Detail
Instance Method Detail
Returns the cross product of self with other.
NOTE Normally this is mathematically not defined when using two-dimensional
vectors. When we do the operation only on the x and y coordinates, the only
result represent the z coordinate. Hence why this method returns a Float64.
Returns the dot product of self with other.
NOTE a.dot b is equivalent to b.dot a.