struct Crame::Vector2

Overview

A two-dimensional vector.

Defined in:

crame/vector2.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Float64, y : Float64) #

Creates a vector given its x and y coordinates.


def self.new #

Creates a vector of coordinate 0.


Instance Method Detail

def !=(other : Vector2) : Bool #

def *(other : Number) : Vector2 #

def +(other : Vector2) : Vector2 #

def -(other : Vector2) : Vector2 #

def - : Vector2 #

def /(other : Number) : Vector2 #

def //(other : Number) : Vector2 #

def ==(other : Vector2) : Bool #

def cross(other : Vector2) : Float64 #

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.


def dot(other : Vector2) : Float64 #

Returns the dot product of self with other.

NOTE a.dot b is equivalent to b.dot a.


def length : Float64 #

Returns the magnitude of self.


def normalized : Vector2 #

Returns a normalized version of self (its magnitude equal to 1).


def normalized? : Bool #

Returns true if self is normalized, false otherwise.


def to_s(io : IO) #
Description copied from struct Struct

Same as #inspect(io).


def x : Float64 #

The x coordinate.


def x=(x : Float64) #

The x coordinate.


def y : Float64 #

The y coordinate.


def y=(y : Float64) #

The y coordinate.