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:
parent
b3e45b75d6
commit
bdd5cee92a
@ -49,6 +49,20 @@ impl Box {
|
|||||||
min_z: -z_length / 2.0,
|
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 {
|
impl Default for Box {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user