parry3d/query/split/split_aabb.rs
1use crate::bounding_volume::Aabb;
2use crate::math::Real;
3use crate::query::SplitResult;
4
5impl Aabb {
6 /// Splits this `Aabb` along the given canonical axis.
7 ///
8 /// This will split the `Aabb` by a plane with a normal with it’s `axis`-th component set to 1.
9 /// The splitting plane is shifted wrt. the origin by the `bias` (i.e. it passes through the point
10 /// equal to `normal * bias`).
11 ///
12 /// # Result
13 /// Returns the result of the split. The first `Aabb` returned is the piece lying on the negative
14 /// half-space delimited by the splitting plane. The second `Aabb` returned is the piece lying on the
15 /// positive half-space delimited by the splitting plane.
16 pub fn canonical_split(&self, axis: usize, bias: Real, epsilon: Real) -> SplitResult<Self> {
17 if self.mins[axis] >= bias - epsilon {
18 SplitResult::Positive
19 } else if self.maxs[axis] <= bias + epsilon {
20 SplitResult::Negative
21 } else {
22 let mut left = *self;
23 let mut right = *self;
24 left.maxs[axis] = bias;
25 right.mins[axis] = bias;
26 SplitResult::Pair(left, right)
27 }
28 }
29}