View Source Exray.Structs.Vector2 (Exray v0.6.0)

Vector2 TypedStruct. Defines functions for Vector2 from Raymath

Summary

Functions

Add vector and vector or float

Calculate angle between two vectors

Clamp the components of the vector between min and max values specified by the given vectors

Clamp the magnitude of the vector between two min and max values

Calculate distance between two vectors

Calculate square distance between two vectors

Divide vector by vector

Calculate two vectors dot product

Check whether two given vectors are almost equal.

Invert the given vector. Doesn't quite work as well as Exray.Structs.Vector2.negate/1, though.

Calculate vector length

Calculate vector square length

Calculate linear interpolation between two vectors

Calculate angle defined by a two vectors line

Get max value for each pair of components

Get min value for each pair of components

Move Vector towards target

Multiply vector by vector

Negate vector

Normalize provided vector

Vector with components value 1.0f

Calculate reflected vector to normal

Compute the direction of a refracted ray

Rotate vector by angle

Scale vector (multiply by value)

Subtract vector by vector or float

Transforms a Vector2 by a given Matrix

Vector with components value 0.0f

Types

@type t() :: %Exray.Structs.Vector2{x: float(), y: float()}

Functions

@spec add(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2
@spec add(Exray.Structs.Vector2, number()) :: Exray.Structs.Vector2

Add vector and vector or float

@spec angle(Exray.Structs.Vector2, Exray.Structs.Vector2) :: float()

Calculate angle between two vectors

NOTE: Angle is calculated from origin point (0, 0)

@spec clamp(Vector, Vector, Vector) :: Vector

Clamp the components of the vector between min and max values specified by the given vectors

Link to this function

clamp_value(v, min, max)

View Source
@spec clamp_value(Exray.Structs.Vector2, number(), number()) :: Exray.Structs.Vector2

Clamp the magnitude of the vector between two min and max values

@spec distance(Exray.Structs.Vector2, Exray.Structs.Vector2) :: float()

Calculate distance between two vectors

@spec distance_sqr(Exray.Structs.Vector2, Exray.Structs.Vector2) :: float()

Calculate square distance between two vectors

@spec divide(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2

Divide vector by vector

@spec dot_product(Exray.Structs.Vector2, Exray.Structs.Vector2) :: float()

Calculate two vectors dot product

@spec equals(Exray.Structs.Vector2, Exray.Structs.Vector2) :: boolean()

Check whether two given vectors are almost equal.

Very useful given 1.00000001 != 1.0000000003

@spec invert(Exray.Structs.Vector2) :: Exray.Structs.Vector2

Invert the given vector. Doesn't quite work as well as Exray.Structs.Vector2.negate/1, though.

@spec length(Exray.Structs.Vector2) :: float()

Calculate vector length

@spec length_sqr(Exray.Structs.Vector2) :: float()

Calculate vector square length

@spec lerp(Exray.Structs.Vector2, Exray.Structs.Vector2, number()) ::
  Exray.Structs.Vector2

Calculate linear interpolation between two vectors

@spec line_angle(Exray.Structs.Vector2, Exray.Structs.Vector2) :: float()

Calculate angle defined by a two vectors line

NOTE: Parameters need to be normalized

Current implementation should be aligned with glm::angle

@spec max(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2

Get max value for each pair of components

@spec min(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2

Get min value for each pair of components

Link to this function

move_towards(v, target, max_distance)

View Source
@spec move_towards(Exray.Structs.Vector2, Exray.Structs.Vector2, number()) ::
  Exray.Structs.Vector2

Move Vector towards target

@spec multiply(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2

Multiply vector by vector

@spec negate(Exray.Structs.Vector2) :: Exray.Structs.Vector2

Negate vector

@spec normalize(Exray.Structs.Vector2) :: Exray.Structs.Vector2

Normalize provided vector

@spec one() :: Exray.Structs.Vector2

Vector with components value 1.0f

@spec reflect(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2

Calculate reflected vector to normal

@spec refract(Exray.Structs.Vector2, Exray.Structs.Vector2, number()) ::
  Exray.Structs.Vector2

Compute the direction of a refracted ray

v: normalized direction of the incoming ray
n: normalized normal vector of the interface of two optical media
r: ratio of the refractive index of the medium from where the ray comes
to the refractive index of the medium on the other side of the surface
@spec rotate(Exray.Structs.Vector2, number()) :: Exray.Structs.Vector2

Rotate vector by angle

@spec scale(Exray.Structs.Vector2, number()) :: Exray.Structs.Vector2

Scale vector (multiply by value)

@spec subtract(Exray.Structs.Vector2, Exray.Structs.Vector2) :: Exray.Structs.Vector2
@spec subtract(Exray.Structs.Vector2, float()) :: Exray.Structs.Vector2

Subtract vector by vector or float

@spec transform(Exray.Structs.Vector2, Matrix) :: Exray.Structs.Vector2

Transforms a Vector2 by a given Matrix

@spec zero() :: Exray.Structs.Vector2

Vector with components value 0.0f