struct Glint::Vector2
- Glint::Vector2
- Struct
- Value
- Object
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.crConstant 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
-
.new(v : Raylib::Vector2)
Creates a new vector from
Raylib::Vector
. -
.new(x : Number = 0, y : Number = 0)
Creates a new vector from x/y components.
Class Method Summary
-
.angle_between(v1 : Vector2, v2 : Vector2)
Returns the angle between two vectors.
-
.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.
-
.clamp(v : Vector2, x_range : Range, y_range : Range)
Clamps a vector to min/max x and y ranges.
-
.cross(v1 : Vector2, v2 : Vector2)
Returns the cross product of two vectors.
-
.distance_between(v1 : Vector2, v2 : Vector2)
Returns the distance between two vectors.
-
.dot(v1 : Vector2, v2 : Vector2)
Returns the dot product of two vectors.
-
.lerp(v1 : Vector2, v2 : Vector2, amount : Number)
Returns the linear interpolation between two vectors at a certain amount.
-
.move_towards(v1 : Vector2, v2 : Vector2, maximum_distance : Number)
Moves a vector towards another vector by a maximum distance.
-
.normalize(v : Vector2)
Returns a normalized vector.
-
.one
Returns a (1, 1) vector.
-
.reflect(v : Vector2, normal : Vector2)
Returns a vector reflected relative to the normal.
-
.reflect_from_horizonal(v : Vector2)
Returns a vector reflected horizontally.
-
.reflect_from_vertical(v : Vector2)
Returns a vector reflected vertically.
-
.rotate(v : Vector2, angle : Number)
Returns a vector rotated about an angle.
-
.scale(v : Vector2, factor : Number)
Returns a vector scaled by a factor.
-
.unit
Alias for
self#one
. -
.zero
Returns a (0, 0) vector.
Instance Method Summary
-
#!=(other : Vector2)
Returns whether two vectors are not equal.
-
#%(other : Vector2)
Returns the cross product with another vector.
-
#*(other : Vector2)
Multiplies a vector by a factor vector.
-
#*(factor : Number)
Multiplies a vector by a factor.
-
#**(other : Vector2)
Returns the dot product with another vector.
-
#+(other : Vector2)
Adds another vector to the vector.
-
#+(value : Number)
Adds a value to the vector's components.
-
#-(other : Vector2)
Subtracts another vector from the vector.
-
#-(value : Number)
Subtracts a value from the vector components.
-
#-
Negates the vector.
-
#/(factor : Number)
Divides a vector by a factor.
-
#/(other : Vector)
Divides a vector by another vector.
-
#==(other : Vector2)
Returns whether two vectors are equal.
-
#adjust(&)
Takes a block and adjusts the
Vector2
in the way(s) defined by the block. -
#angle
Returns the direction of the vector.
-
#angle_to(other : Vector2)
Returns the angle to another vector.
-
#clamp(min_x : Number, max_x : Number, min_y : Number, max_y : Number)
Clamps the vector to min/max x and y values.
-
#clamp(x_range : Range, y_range : Range)
Clamps the vector to min/max x and y ranges.
-
#clamp!(min_x : Number, max_x : Number, min_y : Number, max_y : Number)
Clamps min/max x and y values.
-
#clamp!(x_range : Range, y_range : Range)
Clamps min/max x and y ranges.
-
#clone
Clones the vector and passes it into a block if given.
-
#clone(&b)
Clones the vector and passes it into a block if given.
-
#cross(other : Vector2)
Returns the cross product with another vector.
-
#distance_to(other : Vector2)
Returns the distance to another vector.
-
#dot(other : Vector2)
Returns the dot product with another vector.
-
#heading
Returns the direction of the vector.
-
#height
Returns the y component as a height.
-
#is_invalid_dimension?
Returns whether the
Vector2
, when considered as a dimension, would be invalid. -
#length
Returns the length of a vector.
-
#length_sqr
Returns the square of the length of a vector.
-
#lerp(other : Vector2, amount : Number)
Returns the linear interpolation to another vector at a certain amount.
-
#lerp!(other : Vector2, amount : Number)
Linearly interpolates to another vector at a certain amount.
-
#magnitude
Returns the length of a vector.
-
#magnitude_sqr
Returns the square of the length of a vector.
-
#move_towards(v : Vector2, maximum_distance : Number)
Moves the vector towards another vector by a maximum distance.
-
#move_towards!(v : Vector2, maximum_distance : Number)
Moves towards another vector by a maximum distance.
-
#normalize
Returns the normalized vector.
-
#normalize!
Normalizes the vector.
-
#normalized?
Returns whether the vector is normalized (has a length of 1.0).
-
#one?
Returns whether the vector is the unit vector.
-
#reflect(normal : Vector2)
Returns the vector reflected relative to the normal.
-
#reflect!(normal : Vector2)
Reflects the vector relative to the normal.
-
#reflect_from_horizonal
Returns the vector reflected horizontally.
-
#reflect_from_horizonal!
Reflects the vector horizontally.
-
#reflect_from_vertical
Returns the vector reflected vertically.
-
#reflect_from_vertical!
Reflects the vector vertically.
-
#rotate(angle : Number)
Returns the vector rotated about an angle.
-
#rotate!(angle : Number)
Rotates the vector about an angle.
-
#scale(factor : Number)
Returns the vector scaled by a factor.
-
#scale!(factor : Number)
Scales the vector by a factor.
-
#to_hash
Returns the vector's values as a
Hash
. - #to_rect(width : Number, height : Number)
- #to_rect(size : Dimension)
- #to_rect
-
#to_s(io : IO)
Returns a string representation of the vector.
-
#to_tuple
Returns the vector's values as a
Tuple
. -
#to_unsafe : Raylib::Vector2
Returns the vector in a C-compatible format, i.e.
-
#unit?
Returns whether the vector is the unit vector.
-
#values
Returns the vector's values as a
Tuple
. -
#width
Returns the x component as a width.
-
#x
Returns the vector's x component.
-
#x=(value : Number)
Set the vector's x component.
-
#y
Returns the vector's y component.
-
#y=(value : Number)
Set the vector's y component.
-
#zero!
Zeroes the vector.
-
#zero?
Returns whether the vector is zero.
Macro Summary
Constructor Detail
Creates a new vector from x/y components.
Class Method Detail
Returns the angle between two vectors.
Clamps a vector to min/max x and y values.
Clamps a vector to min/max x and y ranges.
Returns the cross product of two vectors.
Returns the distance between two vectors.
Returns the linear interpolation between two vectors at a certain amount.
Moves a vector towards another vector by a maximum distance.
Returns a vector reflected relative to the normal.
Returns a vector reflected horizontally.
Returns a vector rotated about an angle.
Instance Method Detail
Clamps the vector to min/max x and y values.
Clamps min/max x and y values.
Returns whether the Vector2
, when considered as a dimension, would be invalid.
Returns the linear interpolation to another vector at a certain amount.
Linearly interpolates to another vector at a certain amount.
Moves the vector towards another vector by a maximum distance.
Moves towards another vector by a maximum distance.
Returns the vector in a C-compatible format, i.e. as Raylib::Vector2
.
This allows for transparent interoperability with the Raylib library.