vec/vec3i
Types
Values
pub fn absolute_value(vector: vec3.Vec3(Int)) -> vec3.Vec3(Int)
Returns a new vector with all elements in absolute values.
Examples
Vec3(12, -34, 420) |> absolute_value()
// -> Vec3(12, 34, 420)
pub fn add(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Adds two vectors together.
Examples
Vec3(12, -34, 420) |> add(Vec3(21, 45, -20))
// -> Vec3(33, 11, 400)
pub fn anchor_position(
vector: vec3.Vec3(Int),
at position: vec3.Vec3(Int),
then fun: fn(vec3.Vec3(Int)) -> vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Return the equivalent of vector |> subtract(position) |> fun() |> add(position)
.
Examples
Vec3(12, -34, 420)
|> anchor_position(Vec3(20, 40, 0), scale(_, 2))
// -> Vec3(4, -108, 840)
pub fn clamp(
vector: vec3.Vec3(Int),
min min_bound: vec3.Vec3(Int),
max max_bound: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns a new vector with all components clamped between a lower and upper bound.
Examples
Vec3(12, -34, 420) |> clamp(
min: Vec3(10, 21, -54),
max: Vec3(14, 18, 323),
)
// -> Vec3(12, 21, 323)
pub fn compare_distance(
a: vec3.Vec3(Int),
with b: vec3.Vec3(Int),
to vector: vec3.Vec3(Int),
) -> order.Order
Compares two vector’s distances to a vector, returning an Order
:
Lt
for lower than, Eq
for equals, or Gt
for greater than.
Examples
compare_distance(Vec3(12, -34, 420), Vec3(2, 3, 4), Vec3(-25, 67, 194))
// -> Gt
pub fn compare_length(
a: vec3.Vec3(Int),
with b: vec3.Vec3(Int),
) -> order.Order
Compares two vector’s lengths, returning an Order
:
Lt
for lower than, Eq
for equals, or Gt
for greater than.
Examples
compare_length(Vec3(12, -34, 420), Vec3(2, 3, 4))
// -> Gt
pub fn cross(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns the cross product of two vectors.
Examples
Vec3(12, -34, 420) |> cross(Vec3(2, 3, 4))
// -> Vec3(-1396, 792, 104)
pub fn distance(
a: vec3.Vec3(Int),
with b: vec3.Vec3(Int),
) -> Float
Returns the distance between two vectors.
Examples
Vec3(12, -34, 420) |> distance(Vec3(2, 3, 4))
// -> 417.76
pub fn distance_squared(
a: vec3.Vec3(Int),
with b: vec3.Vec3(Int),
) -> Int
Returns the squared distance between two vectors.
Examples
Vec3(12, -34, 420) |> distance_squared(Vec3(2, 3, 4))
// -> 174_525
pub fn divide(
dividend: vec3.Vec3(Int),
by divisor: vec3.Vec3(Int),
) -> Result(vec3.Vec3(Int), Nil)
Returns division of the inputs as a Result
.
Examples
Vec3(12, -34, 420) |> divide(Vec3(2, 5, 4))
// -> Ok(Vec3(6, -6, 105))
Vec3(12, -34, 420) |> divide(Vec3(0, 5, 4))
// -> Error(Nil)
pub fn dot(a: vec3.Vec3(Int), b: vec3.Vec3(Int)) -> Int
Returns the dot product of two vectors.
Examples
Vec3(12, -34, 420) |> dot(Vec3(2, 3, 4))
// -> 1602
pub fn floor_divide(
dividend: vec3.Vec3(Int),
by divisor: vec3.Vec3(Int),
) -> Result(vec3.Vec3(Int), Nil)
Performs a floored integer vector division, which means that the result will always be rounded towards negative infinity.
Examples
Vec3(12, -34, 420) |> floor_divide(Vec3(2, 5, 4))
// -> Ok(Vec3(6, -7, 105))
Vec3(12, -34, 420) |> floor_divide(Vec3(0, 5, 4))
// -> Error(Nil)
pub fn length(vector: vec3.Vec3(Int)) -> Float
Returns the length (magnitude) of the vector.
Examples
Vec3(12, -34, 420) |> length()
// -> 421.54
pub fn length_squared(vector: vec3.Vec3(Int)) -> Int
Returns the squared length (squared magnitude) of the vector.
Examples
Vec3(12, -34, 420) |> length_squared()
// -> 177_700
pub fn max(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Compares two vectors, returning the larger of the two.
Examples
max(Vec3(12, -34, 420), Vec3(14, -93, 323))
// -> Vec3(14, -34, 420)
pub fn min(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Compares two vectors, returning the smaller of the two.
Examples
min(Vec3(12, -34, 420), Vec3(10, 21, -54))
// -> Vec3(10, -34, -54)
pub fn mirror(
vector: vec3.Vec3(Int),
through normal: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns the mirror of a vector through a plane defined by the given normal vector.
Examples
Vec3(12, -34, 420) |> mirror(Vec3(2, 3, 4))
// -> Vec3(-208, -364, -20)
pub fn modulo(
dividend: vec3.Vec3(Int),
by divisor: vec3.Vec3(Int),
) -> Result(vec3.Vec3(Int), Nil)
Returns the modulo of the inputs as a Result
.
Examples
Vec3(13, -13, 13) |> modulo(Vec3(3, 3, -3))
// -> Ok(Vec3(1, 2, -2))
pub fn multiply(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Multiplies two vectors together.
Examples
Vec3(12, -34, 420) |> multiply(Vec3(2, -3, 0))
// -> Vec3(24, 102, 0)
pub fn negate(vector: vec3.Vec3(Int)) -> vec3.Vec3(Int)
Returns a new vector with all elements negated.
Examples
Vec3(12, -34, 420) |> negate()
// -> Vec3(-12, 34, -420)
pub fn product(vectors: List(vec3.Vec3(Int))) -> vec3.Vec3(Int)
Multiplies a list of vectors and returns the product.
Examples
[
Vec3(12, -34, 420),
Vec3(21, -10, 999),
Vec3(32, 20, 0),
]
|> product()
// -> Vec3(8064, 6800, 0)
pub fn project(
a: vec3.Vec3(Int),
on b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns the projection of a vector on another vector.
Examples
Vec3(12, -34, 420) |> project(Vec3(2, 3, 4))
// -> Vec3(110, 165, 220)
pub fn reflect(
vector: vec3.Vec3(Int),
through normal: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns the reflection of a vector through a plane defined by the given normal vector.
Examples
Vec3(12, -34, 420) |> reflect(Vec3(2, 3, 4))
// -> Vec3(208, 364, 20)
pub fn remainder(
dividend: vec3.Vec3(Int),
by divisor: vec3.Vec3(Int),
) -> Result(vec3.Vec3(Int), Nil)
Computes the remainder of an integer vector division of inputs as a
Result
.
Examples
Vec3(13, -13, 13) |> remainder(Vec3(3, 3, -3))
// -> Ok(Vec3(1, -1, 1))
Vec3(12, -34, 420) |> remainder(Vec3(0, 1, 2))
// -> Error(Nil)
pub fn scale(
vector: vec3.Vec3(Int),
by scalar: Int,
) -> vec3.Vec3(Int)
Returns a new vector containing the elements multiplies by scalar
.
Examples
Vec3(12, -34, 420) |> scale(2)
// -> Vec3(24, -68, 840)
pub fn slide(
a: vec3.Vec3(Int),
on b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Returns a new vector resulting from sliding this vector along a plane defined by the given normal vector.
Examples
Vec3(12, -34, 420) |> slide(Vec3(2, 3, 4))
// -> Vec3(-98, -199, 200)
pub fn subtract(
a: vec3.Vec3(Int),
b: vec3.Vec3(Int),
) -> vec3.Vec3(Int)
Subtracts one vector from another.
Examples
Vec3(12, -34, 420) |> subtract(Vec3(7, -45, 20))
// -> Vec3(5, 11, 400)