struct Godot::Vector2

Overview

2-element structure that can be used to represent 2D coordinates or vectors with 32-bit floating point precision.

Defined in:

libgodot/types/vector2.cr

Constant Summary

DOWN = Vector2.new(0.0_f32, 1.0_f32)
INF = Vector2.new(Float32::INFINITY, Float32::INFINITY)
LEFT = Vector2.new(-1.0_f32, 0.0_f32)
ONE = Vector2.new(1.0_f32, 1.0_f32)
RIGHT = Vector2.new(1.0_f32, 0.0_f32)
UP = Vector2.new(0.0_f32, -1.0_f32)
ZERO = Vector2.new(0.0_f32, 0.0_f32)

Constructors

Instance Method Summary

Constructor Detail

def self.new(x : Float32 = 0.0_f32, y : Float32 = 0.0_f32) #

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

def self.new(pointer : Pointer(Void)) #

Instance Method Detail

def !=(other : Vector2) : Bool #

def *(scalar : Number) : Vector2 #

def *(other : Vector2) : Vector2 #

def +(other : Vector2) : Vector2 #

def -(other : Vector2) : Vector2 #

def - : Vector2 #

def /(scalar : Number) : Vector2 #

def /(other : Vector2) : Vector2 #

def ==(other : Vector2) : Bool #

def abs : Vector2 #

def angle : Float32 #

Returns the angle in radians of this vector with respect to the positive X-axis.


def angle_to(to : Vector2) : Float32 #

Returns the unsigned angle in radians between this vector and other.


def angle_to_point(to : Vector2) : Float32 #

Returns the angle in radians between this vector and the given point.


def aspect : Float32 #

def bezier_interpolate(control_1 : Vector2, control_2 : Vector2, end_point : Vector2, t : Number) : Vector2 #

Bezier interpolation through control points.


def bounce(normal : Vector2) : Vector2 #

Returns a new vector bounced off a plane defined by the given normal.


def ceil : Vector2 #

def clamp(min : Vector2, max : Vector2) : Vector2 #

Clamps each component between min and max.


def clampf(min_val : Number, max_val : Number) : Vector2 #

Clamps each component between scalar min and max values.


def cross(other : Vector2) : Float32 #

def cubic_interpolate(b : Vector2, pre_a : Vector2, post_b : Vector2, weight : Number) : Vector2 #

Cubic interpolation between two vectors using pre_a and post_b tangents.


def direction_to(other : Vector2) : Vector2 #

Returns the normalized direction from this vector toward other.


def distance_squared_to(other : Vector2) : Float32 #

Returns the squared distance between this vector and other.


def distance_to(other : Vector2) : Float32 #

Returns the distance between this vector and other.


def dot(other : Vector2) : Float32 #

def floor : Vector2 #

def is_equal_approx(other : Vector2) : Bool #

def is_finite? : Bool #

def is_normalized? : Bool #

def is_zero_approx : Bool #

def is_zero_approx? : Bool #

def length : Float32 #

def length_squared : Float32 #

def lerp(to : Vector2, weight : Number) : Vector2 #

Linearly interpolates between this vector and to by weight.


def limit_length(max_length : Number = 1.0) : Vector2 #

Clamps the vector's length to max_length.


def max(other : Vector2) : Vector2 #

def min(other : Vector2) : Vector2 #

def move_toward(to : Vector2, delta : Number) : Vector2 #

Moves this vector toward to by the given delta amount, never exceeding to.


def normalized : Vector2 #

def orthogonal : Vector2 #

Returns the vector rotated 90 degrees counter-clockwise.


def perpendicular : Vector2 #

Alias for orthogonal.


def posmod(mod_val : Number) : Vector2 #

Returns the vector with each component modulo scalar.


def project(b : Vector2) : Vector2 #

Projects this vector onto vector b.


def reflect(normal : Vector2) : Vector2 #

Returns a new vector reflected from a plane defined by the given normal.


def rotated(angle : Number) : Vector2 #

Rotates this vector by the given angle in radians.


def round : Vector2 #

def sign : Vector2 #

def slerp(to : Vector2, weight : Number) : Vector2 #

Spherically interpolates between this vector and to by weight.


def slide(normal : Vector2) : Vector2 #

Returns a new vector slid along a plane defined by the given normal.


def snapped(step : Vector2) : Vector2 #

Snaps vector components to nearest multiple of step.


def to_i : Vector2i #

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

Same as #inspect(io).


def x : Float32 #

def x=(x : Float32) #

def y : Float32 #

def y=(y : Float32) #