vec/vec3
Types
Values
pub fn from_tuple(tuple: #(value, value, value)) -> Vec3(value)
Converts a tuple of the contained elements into a vector.
Examples
assert #(12, -34, 420) |> from_tuple == Vec3(12, -34, 420)
pub fn map(vector: Vec3(a), with fun: fn(a) -> b) -> Vec3(b)
Returns a new vector containing only the elements of the first vector after the function has been applied to each one.
Examples
assert Vec3(12, -34, 420) |> map(fn(x) { x * 2 }) == Vec3(24, -68, 840)
pub fn map2(
a: Vec3(a),
b: Vec3(b),
with fun: fn(a, b) -> c,
) -> Vec3(c)
Combines two vectors into a single vector using the given function.
Examples
assert
Vec3(12, -34, 420)
|> map2(Vec3(1, 2, 3), fn(x, y) { x * y })
== Vec3(12, -68, 1260)
pub fn map3(
a: Vec3(a),
b: Vec3(b),
c: Vec3(c),
with fun: fn(a, b, c) -> c,
) -> Vec3(c)
Combines three vectors into a single vector using the given function.
Examples
fn linear_interpolation(weight: Float, a: Float, b: Float) -> Float {
a +. { b -. a } *. weight
}
assert
splat(0.6)
|> map3(
Vec3(1.2, -3.4, 42.0),
Vec3(1.0, 2.1, -5.4),
linear_interpolation,
)
== Vec3(1.08, -0.1, 13.56)
pub fn map_x(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the x element having had with applied to it.
Examples
assert Vec3(12, -34, 420) |> map_x(fn(n) { n * 2 }) == Vec3(24, -34, 420)
pub fn map_y(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the y element having had with applied to it.
Examples
assert Vec3(12, -34, 420) |> map_y(fn(n) { n * 2 }) == Vec3(12, -68, 420)
pub fn map_z(
vector: Vec3(value),
with fun: fn(value) -> value,
) -> Vec3(value)
Returns a new vector with the z element having had with applied to it.
Examples
assert Vec3(12, -34, 420) |> map_z(fn(n) { n * 2 }) == Vec3(12, -34, 840)
pub fn result(vector: Vec3(Result(a, e))) -> Result(Vec3(a), e)
Combines a vector of results into a single result. If all elements in the
vector are Ok then returns an Ok holding the vector of values. If any
element is Error then returns the first error.
Examples
assert Vec3(Ok(12), Ok(-34), Ok(420)) |> result == Ok(Vec3(12, -34, 420))
assert Vec3(Ok(12), Error("foo"), Error("bar")) |> result == Error("foo")
pub fn splat(value: value) -> Vec3(value)
Creates a vector with all elements set to a value.
Examples
assert splat(12) == Vec3(12, 12, 12)
pub fn swap_xy(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the x and y elements swaped.
Examples
assert Vec3(12, -34, 420) |> swap_xy == Vec3(-34, 12, 420)
pub fn swap_xz(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the x and z elements swaped.
Examples
assert Vec3(12, -34, 420) |> swap_xz == Vec3(420, -34, 12)
pub fn swap_yz(vector: Vec3(value)) -> Vec3(value)
Returns a new vector with the y and z elements swaped.
Examples
assert Vec3(12, -34, 420) |> swap_yz == Vec3(12, 420, -34)
pub fn to_list(vector: Vec3(value)) -> List(value)
Converts the vector into a list of the contained elements.
Examples
assert Vec3(12, -34, 420) |> to_list == [12, -34, 420]
pub fn to_tuple(vector: Vec3(value)) -> #(value, value, value)
Converts the vector into a tuple of the contained elements.
Examples
assert Vec3(12, -34, 420) |> to_tuple == #(12, -34, 420)
pub fn x(vector: Vec3(value)) -> value
Returns the x element in a vector.
Examples
assert Vec3(12, -34, 420) |> x == 12
pub fn y(vector: Vec3(value)) -> value
Returns the y element in a vector.
Examples
assert Vec3(12, -34, 420) |> y == -34