mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
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
1 changed files with 14 additions and 0 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue