Add Box::from_corners method (#6672)

# Objective

This add a ctor to `Box` to aid the creation of non-centred boxes. The PR adopts @rezural's work on PR #3322, taking into account the feedback on that PR from @james7132.

## Solution

`Box::from_corners()` creates a `Box` from two opposing corners and automatically determines the min and max extents to ensure that the `Box` is well-formed.

Co-authored-by: rezural <rezural@protonmail.com>
This commit is contained in:
Robin KAY 2022-11-21 13:19:40 +00:00
parent b3e45b75d6
commit bdd5cee92a

View file

@ -49,6 +49,20 @@ impl Box {
min_z: -z_length / 2.0,
}
}
/// Creates a new box given the coordinates of two opposing corners.
pub fn from_corners(a: Vec3, b: Vec3) -> Box {
let max = a.max(b);
let min = a.min(b);
Box {
max_x: max.x,
min_x: min.x,
max_y: max.y,
min_y: min.y,
max_z: max.z,
min_z: min.z,
}
}
}
impl Default for Box {