rtiow/vec3: add min/max functions for building new Vec3 from 2 others.

This commit is contained in:
Bill Thiede 2023-01-19 19:48:59 -08:00
parent 468cba97b3
commit 4ab9425a97

View File

@ -15,6 +15,23 @@ pub struct Vec3 {
pub z: f32,
}
// Return a `Vec3` with the lowest of each component in v1 or v2.
pub fn min(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.x.min(v2.x),
y: v1.y.min(v2.y),
z: v1.z.min(v2.z),
}
}
// Return a `Vec3` with the greatest of each component in v1 or v2.
pub fn max(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.x.max(v2.x),
y: v1.y.max(v2.y),
z: v1.z.max(v2.z),
}
}
pub fn cross(v1: Vec3, v2: Vec3) -> Vec3 {
Vec3 {
x: v1.y * v2.z - v1.z * v2.y,