Skip to content

Commit

Permalink
Add Box::from_corners method (bevyengine#6672)
Browse files Browse the repository at this point in the history
# Objective

This add a ctor to `Box` to aid the creation of non-centred boxes. The PR adopts @rezural's work on PR bevyengine#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>
  • Loading branch information
2 people authored and alradish committed Jan 22, 2023
1 parent bfbea42 commit e3b81c4
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions crates/bevy_render/src/mesh/shape/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e3b81c4

Please sign in to comment.