Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/partitioning/bvh/bvh_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,12 @@ impl BvhNode {
/// - [`Bvh::scale`] - Scale an entire BVH tree
#[inline]
pub fn scale(&mut self, scale: Vector) {
self.mins *= scale;
self.maxs *= scale;
let new_mins = self.mins * scale;
let new_maxs = self.maxs * scale;
// When scale has negative components, mins/maxs swap on those axes.
// Use component-wise min/max to maintain the AABB invariant (mins <= maxs).
self.mins = new_mins.min(new_maxs);
self.maxs = new_mins.max(new_maxs);
}

/// Calculates the volume of this node's AABB.
Expand Down Expand Up @@ -1995,18 +1999,18 @@ impl Bvh {

/// Scales all AABBs in the tree by the given factors.
///
/// This multiplies all AABB coordinates (mins and maxs) by the corresponding components
/// of the scale vector. This is useful when scaling an entire scene or changing coordinate
/// systems.
/// Each AABB's coordinates are multiplied by the corresponding scale components, with
/// mins and maxs swapped on any axis where the scale is negative to preserve the
/// AABB invariant. This is useful when scaling an entire scene or changing coordinate
/// systems, including reflections.
///
/// # Arguments
///
/// * `scale` - Per-axis scale factors (must all be positive)
/// * `scale` - Per-axis scale factors. Each component must be non-zero.
///
/// # Panics
///
/// This function has undefined behavior if any scale component is negative or zero.
/// Always use positive scale values.
/// Undefined behavior if any scale component is zero (degenerate AABB).
///
/// # Example
///
Expand Down