vec/vec4i
Types
Values
pub fn absolute_value(vector: vec4.Vec4(Int)) -> vec4.Vec4(Int)
Returns a new vector with all elements in absolute values.
Examples
Vec4(12, -34, 420, 69) |> absolute_value()
// -> Vec4(12, 34, 420, 69)
pub fn add(
a: vec4.Vec4(Int),
b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Adds two vectors together.
Examples
Vec4(12, -34, 420, 69) |> add(Vec4(21, 45, -20, -9))
// -> Vec4(33, 11, 400, 60)
pub fn anchor_position(
vector: vec4.Vec4(Int),
at position: vec4.Vec4(Int),
then fun: fn(vec4.Vec4(Int)) -> vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Return the equivalent of vector |> subtract(position) |> fun() |> add(position)
.
Examples
Vec4(12, -34, 420, 69)
|> anchor_position(Vec4(2, 3, 4, 5), scale(_, 2))
// -> Vec4(22, -71, 836, 133)
pub fn clamp(
vector: vec4.Vec4(Int),
min min_bound: vec4.Vec4(Int),
max max_bound: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Returns a new vector with all components clamped between a lower and upper bound.
Examples
Vec4(12, -34, 420, 69) |> clamp(
min: Vec4(10, 21, -54, 75),
max: Vec4(14, 18, 323, 91),
)
// -> Vec4(12, 21, 323, 75)
pub fn compare_distance(
a: vec4.Vec4(Int),
with b: vec4.Vec4(Int),
to vector: vec4.Vec4(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(
Vec4(12, -34, 420, 69),
Vec4(2, 3, 4, 5),
Vec4(-25, 67, 194, 0),
)
// -> Gt
pub fn compare_length(
a: vec4.Vec4(Int),
with b: vec4.Vec4(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(Vec4(12, -34, 420, 69), Vec4(2, 3, 4, 5))
// -> Gt
pub fn decoder() -> decode.Decoder(vec4.Vec4(Int))
A decoder that decodes 4D int vectors where all elements are decoded with a given decoder.
pub fn distance(
a: vec4.Vec4(Int),
with b: vec4.Vec4(Int),
) -> Float
Returns the distance between two vectors.
Examples
Vec4(12, -34, 420, 69) |> distance(Vec4(2, 3, 4, 5))
// -> 422.64
pub fn distance_squared(
a: vec4.Vec4(Int),
with b: vec4.Vec4(Int),
) -> Int
Returns the squared distance between two vectors.
Examples
Vec4(12, -34, 420, 69) |> distance_squared(Vec4(2, 3, 4, 5))
// -> 178_621
pub fn divide(
dividend: vec4.Vec4(Int),
by divisor: vec4.Vec4(Int),
) -> Result(vec4.Vec4(Int), Nil)
Returns division of the inputs as a Result
.
Examples
Vec4(12, -34, 420, 69) |> divide(Vec4(2, 5, 4, 1))
// -> Ok(Vec4(6, -6, 105, 69))
Vec4(12, -34, 420, 69) |> divide(Vec4(0, 5, 4, 1))
// -> Error(Nil)
pub fn dot(a: vec4.Vec4(Int), b: vec4.Vec4(Int)) -> Int
Returns the dot product of two vectors.
Examples
Vec4(12, -34, 420, 69) |> dot(Vec4(2, 3, 4, 5))
// -> 1947
pub fn floor_divide(
dividend: vec4.Vec4(Int),
by divisor: vec4.Vec4(Int),
) -> Result(vec4.Vec4(Int), Nil)
Performs a floored integer vector division, which means that the result will always be rounded towards negative infinity.
Examples
Vec4(12, -34, 420, 69) |> floor_divide(Vec4(2, 5, 4, 1))
// -> Ok(Vec4(6, -7, 105, 69))
Vec4(12, -34, 420, 69) |> floor_divide(Vec4(0, 5, 4, 1))
// -> Error(Nil)
pub fn length(vector: vec4.Vec4(Int)) -> Float
Returns the length (magnitude) of the vector.
Examples
Vec4(12, -34, 420, 69) |> length()
// -> 427.15
pub fn length_squared(vector: vec4.Vec4(Int)) -> Int
Returns the squared length (squared magnitude) of the vector.
Examples
Vec4(12, -34, 420, 69) |> length_squared()
// -> 182_461
pub fn max(
a: vec4.Vec4(Int),
b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Compares two vectors, returning the larger of the two.
Examples
max(Vec4(12, -34, 420, 69), Vec4(14, -93, 323, 91))
// -> Vec4(14, -34, 420, 91)
pub fn min(
a: vec4.Vec4(Int),
b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Compares two vectors, returning the smaller of the two.
Examples
min(Vec4(12, -34, 420, 69), Vec4(10, 21, -54, 75))
// -> Vec4(10, -34, -54, 69)
pub fn mirror(
vector: vec4.Vec4(Int),
through normal: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Returns the mirror of a vector through a plane defined by the given normal vector.
Examples
Vec4(12, -34, 420, 69) |> mirror(Vec4(2, 3, 4, 5))
// -> Vec4(-132, -250, 132, -291)
pub fn modulo(
dividend: vec4.Vec4(Int),
by divisor: vec4.Vec4(Int),
) -> Result(vec4.Vec4(Int), Nil)
Returns the modulo of the inputs as a Result
.
Examples
Vec4(13, -13, 13, -13) |> modulo(Vec4(3, 3, -3, -3))
// -> Ok(Vec4(1, 2, -2, -1))
pub fn multiply(
a: vec4.Vec4(Int),
b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Multiplies two vectors together.
Examples
Vec4(12, -34, 420, 69) |> multiply(Vec4(2, -3, 0, 1))
// -> Vec4(24, 102, 0, 69)
pub fn negate(vector: vec4.Vec4(Int)) -> vec4.Vec4(Int)
Returns a new vector with all elements negated.
Examples
Vec4(12, -34, 420, 69) |> negate()
// -> Vec4(-12, 34, -420, -69)
pub fn product(vectors: List(vec4.Vec4(Int))) -> vec4.Vec4(Int)
Multiplies a list of vectors and returns the product.
Examples
[
Vec4(12, -34, 420, 69),
Vec4(21, -10, 999, 20),
Vec4(32, 20, 0, 5),
]
|> product()
// -> Vec4(8064, 6800, 0, 6900)
pub fn project(
a: vec4.Vec4(Int),
on b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Returns the projection of a vector on another vector.
Examples
Vec4(12, -34, 420, 69) |> project(Vec4(2, 3, 4, 5))
// -> Vec4(72, 108, 144, 180)
pub fn reflect(
vector: vec4.Vec4(Int),
through normal: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Returns the reflection of a vector through a plane defined by the given normal vector.
Examples
Vec4(12, -34, 420, 69) |> reflect(Vec4(2, 3, 4, 5))
// -> Vec4(132, 250, -132, 291)
pub fn remainder(
dividend: vec4.Vec4(Int),
by divisor: vec4.Vec4(Int),
) -> Result(vec4.Vec4(Int), Nil)
Computes the remainder of an integer vector division of inputs as a
Result
.
Examples
Vec4(13, -13, 13, -13) |> remainder(Vec4(3, 3, -3, -3))
// -> Ok(Vec4(1, -1, 1, -1))
Vec4(12, -34, 420, 69) |> remainder(Vec4(0, 1, 2, 3))
// -> Error(Nil)
pub fn scale(
vector: vec4.Vec4(Int),
by scalar: Int,
) -> vec4.Vec4(Int)
Returns a new vector containing the elements multiplies by scalar
.
Examples
Vec4(12, -34, 420, 69) |> scale(2)
// -> Vec4(24, -68, 840, 138)
pub fn slide(
a: vec4.Vec4(Int),
on b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Returns a new vector resulting from sliding this vector along a plane defined by the given normal vector.
Examples
Vec4(12, -34, 420, 69) |> slide(Vec4(2, 3, 4, 5))
// -> Vec4(-60, -142, 276, -111)
pub fn subtract(
a: vec4.Vec4(Int),
b: vec4.Vec4(Int),
) -> vec4.Vec4(Int)
Subtracts one vector from another.
Examples
Vec4(12, -34, 420, 69) |> subtract(Vec4(7, -45, 20, 32))
// -> Vec4(5, 11, 400, 37)