struct Oid::Vector2

Overview

Representation of 2D vector

Included Modules

Defined in:

oid/resources/vectors/vector2.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from module Oid::Vector

!=(other) !=, %(other : Vector) %, *(other : Vector)
*(other : Float64)
*
, **(other : Vector) **, +(other : Vector)
+(other : Float64)
+
, -(other : Vector)
-
-
, /(other : Vector)
/(other : Float64)
/
, ==(other) ==, clone
clone(&b)
clone
, cross(other) cross, distance(other : Vector) distance, dot(other) dot, heading heading, mag mag, magnitude magnitude, normalize normalize, normalize! normalize!, values values, zero! zero!

Constructor Detail

def self.new(x, y) #

Initializes vector with #x and #y


[View source]
def self.new(pull : JSON::PullParser) #

Class Method Detail

def self.parse(s) #

[View source]
def self.zero #

Zero vector


[View source]

Instance Method Detail

def !=(other) #
Description copied from class Object

Returns true if this object is not equal to other.

By default this method is implemented as !(self == other) so there's no need to override this unless there's a more efficient way to do it.


[View source]
def *(other : Vector) #

Performs component multiplication (for dot product see #dot)


[View source]
def *(other : Float64) #

Performs multiplication


[View source]
def +(other : Vector) #

Performs component addition


[View source]
def +(other : Float64) #

Performs component addition


[View source]
def -(other : Vector) #

Performs component subtraction


[View source]
def -(other : Float64) #

Performs component subtraction


[View source]
def - #

Returns negated vector


[View source]
def /(other : Vector) #

Performs component division


[View source]
def ==(other) #
Description copied from struct Struct

Returns true if this struct is equal to other.

Both structs' instance vars are compared to each other. Thus, two structs are considered equal if each of their instance variables are equal. Subclasses should override this method to provide specific equality semantics.

struct Point
  def initialize(@x : Int32, @y : Int32)
  end
end

p1 = Point.new 1, 2
p2 = Point.new 1, 2
p3 = Point.new 3, 4

p1 == p2 # => true
p1 == p3 # => false

[View source]
def angle(other : Vector) #

Returns angle between two vectors


[View source]
def angle #

Returns direction of a vector


[View source]
def clone #

Clones this vector and passes it into a block if given


[View source]
def cross(other) #

Returns cross product of two vectors


[View source]
def distance(other : Vector) #

Finds distance between two vectors


[View source]
def dot(other) #

Returns dot product of two vectors


[View source]
def find_normal_axis(other) #

Finds normal axis between two vectors


[View source]
def magnitude #

Returns magnitude of this vector


[View source]
def normalize! #

Normalizes current vector


[View source]
def to_v3 #

[View source]
def to_v4 #

[View source]
def values #

Converts vector to a tuple of values


[View source]
def x : Float64 #

[View source]
def x=(x : Float64) #

[View source]
def y : Float64 #

[View source]
def y=(y : Float64) #

[View source]
def zero! #

Fills current vector with zero


[View source]