struct Glint::Vector2

Overview

A wrapper for Raylib::Vector.

It provides access to a number of Raylib's Raymath vector library functions.

Some methods reimplemented from https://github.com/unn4m3d/crystaledge/blob/master/src/crystaledge/vector2.cr

Defined in:

glint/vector2.cr

Constant Summary

DOWN = Vector2.new(0, 1)

Vector representing the down direction.

DOWN_LEFT = DOWN + LEFT

Vector representing the down-left direction.

DOWN_RIGHT = DOWN + RIGHT

Vector representing the down-right direction.

EAST = RIGHT

Vector representing the east direction.

LEFT = Vector2.new(-1, 0)

Vector representing the left direction.

NORTH = UP

Vector representing the north direction.

NORTH_EAST = NORTH + EAST

Vector representing the north east direction.

NORTH_WEST = NORTH + WEST

Vector representing the north west direction.

ONE = Vector2.new(1, 1)

A unit vector.

RIGHT = Vector2.new(1, 0)

Vector representing the right direction.

SOUTH = DOWN

Vector representing the south direction.

SOUTH_EAST = SOUTH + EAST

Vector representing the south east direction.

SOUTH_WEST = SOUTH + WEST

Vector representing the south west direction.

UNIT = ONE

A unit vector.

UP = Vector2.new(0, -1)

Vector representing the up direction.

UP_LEFT = UP + LEFT

Vector representing the up-left direction.

UP_RIGHT = UP + RIGHT

Vector representing the up-right direction.

WEST = LEFT

Vector representing the west direction.

ZERO = Vector2.new(0, 0)

A zero vector.

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(v : Raylib::Vector2) #

Creates a new vector from Raylib::Vector.


[View source]
def self.new(x : Number = 0, y : Number = 0) #

Creates a new vector from x/y components.


[View source]

Class Method Detail

def self.angle_between(v1 : Vector2, v2 : Vector2) #

Returns the angle between two vectors.


[View source]
def self.clamp(v : Vector2, min_x : Number, max_x : Number, min_y : Number, max_y : Number) #

Clamps a vector to min/max x and y values.


[View source]
def self.clamp(v : Vector2, x_range : Range, y_range : Range) #

Clamps a vector to min/max x and y ranges.


[View source]
def self.cross(v1 : Vector2, v2 : Vector2) #

Returns the cross product of two vectors.


[View source]
def self.distance_between(v1 : Vector2, v2 : Vector2) #

Returns the distance between two vectors.


[View source]
def self.dot(v1 : Vector2, v2 : Vector2) #

Returns the dot product of two vectors.


[View source]
def self.lerp(v1 : Vector2, v2 : Vector2, amount : Number) #

Returns the linear interpolation between two vectors at a certain amount.


[View source]
def self.move_towards(v1 : Vector2, v2 : Vector2, maximum_distance : Number) #

Moves a vector towards another vector by a maximum distance.


[View source]
def self.normalize(v : Vector2) #

Returns a normalized vector.


[View source]
def self.one #

Returns a (1, 1) vector.


[View source]
def self.reflect(v : Vector2, normal : Vector2) #

Returns a vector reflected relative to the normal.


[View source]
def self.reflect_from_horizonal(v : Vector2) #

Returns a vector reflected horizontally.


[View source]
def self.reflect_from_vertical(v : Vector2) #

Returns a vector reflected vertically.


[View source]
def self.rotate(v : Vector2, angle : Number) #

Returns a vector rotated about an angle.


[View source]
def self.scale(v : Vector2, factor : Number) #

Returns a vector scaled by a factor.


[View source]
def self.unit #

Alias for self#one.


[View source]
def self.zero #

Returns a (0, 0) vector.


[View source]

Instance Method Detail

def !=(other : Vector2) #

Returns whether two vectors are not equal.


[View source]
def %(other : Vector2) #

Returns the cross product with another vector.


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

Multiplies a vector by a factor vector. See also #dot and #cross products.


[View source]
def *(factor : Number) #

Multiplies a vector by a factor.


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

Returns the dot product with another vector.


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

Adds another vector to the vector.


[View source]
def +(value : Number) #

Adds a value to the vector's components.


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

Subtracts another vector from the vector.


[View source]
def -(value : Number) #

Subtracts a value from the vector components.


[View source]
def - #

Negates the vector.


[View source]
def /(factor : Number) #

Divides a vector by a factor.


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

Divides a vector by another vector.


[View source]
def ==(other : Vector2) #

Returns whether two vectors are equal.


[View source]
def adjust(&) #

Takes a block and adjusts the Vector2 in the way(s) defined by the block.


[View source]
def angle #

Returns the direction of the vector.


[View source]
def angle_to(other : Vector2) #

Returns the angle to another vector.


[View source]
def clamp(min_x : Number, max_x : Number, min_y : Number, max_y : Number) #

Clamps the vector to min/max x and y values.


[View source]
def clamp(x_range : Range, y_range : Range) #

Clamps the vector to min/max x and y ranges.


[View source]
def clamp!(min_x : Number, max_x : Number, min_y : Number, max_y : Number) #

Clamps min/max x and y values.


[View source]
def clamp!(x_range : Range, y_range : Range) #

Clamps min/max x and y ranges.


[View source]
def clone #

Clones the vector and passes it into a block if given.


[View source]
def clone(&b) #

Clones the vector and passes it into a block if given.


[View source]
def cross(other : Vector2) #

Returns the cross product with another vector.


[View source]
def distance_to(other : Vector2) #

Returns the distance to another vector.


[View source]
def dot(other : Vector2) #

Returns the dot product with another vector.


[View source]
def heading #

Returns the direction of the vector.


[View source]
def height #

Returns the y component as a height.


[View source]
def is_invalid_dimension? #

Returns whether the Vector2, when considered as a dimension, would be invalid.


[View source]
def length #

Returns the length of a vector.


[View source]
def length_sqr #

Returns the square of the length of a vector.


[View source]
def lerp(other : Vector2, amount : Number) #

Returns the linear interpolation to another vector at a certain amount.


[View source]
def lerp!(other : Vector2, amount : Number) #

Linearly interpolates to another vector at a certain amount.


[View source]
def magnitude #

Returns the length of a vector.


[View source]
def magnitude_sqr #

Returns the square of the length of a vector.


[View source]
def move_towards(v : Vector2, maximum_distance : Number) #

Moves the vector towards another vector by a maximum distance.


[View source]
def move_towards!(v : Vector2, maximum_distance : Number) #

Moves towards another vector by a maximum distance.


[View source]
def normalize #

Returns the normalized vector.


[View source]
def normalize! #

Normalizes the vector.


[View source]
def normalized? #

Returns whether the vector is normalized (has a length of 1.0).


[View source]
def one? #

Returns whether the vector is the unit vector.


[View source]
def reflect(normal : Vector2) #

Returns the vector reflected relative to the normal.


[View source]
def reflect!(normal : Vector2) #

Reflects the vector relative to the normal.


[View source]
def reflect_from_horizonal #

Returns the vector reflected horizontally.


[View source]
def reflect_from_horizonal! #

Reflects the vector horizontally.


[View source]
def reflect_from_vertical #

Returns the vector reflected vertically.


[View source]
def reflect_from_vertical! #

Reflects the vector vertically.


[View source]
def rotate(angle : Number) #

Returns the vector rotated about an angle.


[View source]
def rotate!(angle : Number) #

Rotates the vector about an angle.


[View source]
def scale(factor : Number) #

Returns the vector scaled by a factor.


[View source]
def scale!(factor : Number) #

Scales the vector by a factor.


[View source]
def to_hash #

Returns the vector's values as a Hash.


[View source]
def to_rect(width : Number, height : Number) #

Returns a Rect at Vector2 with a specific width and height.


[View source]
def to_rect(size : Dimension) #

Returns a Rect at Vector2 with a specific size.


[View source]
def to_rect #

Returns a Rect with the size of the Vector2.


[View source]
def to_s(io : IO) #

Returns a string representation of the vector.


[View source]
def to_tuple #

Returns the vector's values as a Tuple.


[View source]
def to_unsafe : Raylib::Vector2 #

Returns the vector in a C-compatible format, i.e. as Raylib::Vector2.

This allows for transparent interoperability with the Raylib library.


[View source]
def unit? #

Returns whether the vector is the unit vector.


[View source]
def values #

Returns the vector's values as a Tuple.


[View source]
def width #

Returns the x component as a width.


[View source]
def x #

Returns the vector's x component.


[View source]
def x=(value : Number) #

Set the vector's x component.


[View source]
def y #

Returns the vector's y component.


[View source]
def y=(value : Number) #

Set the vector's y component.


[View source]
def zero! #

Zeroes the vector.


[View source]
def zero? #

Returns whether the vector is zero.


[View source]

Macro Detail

macro method_missing(call) #

[View source]