From df04e0ffcd8023657312fb68f71154071e5f732c Mon Sep 17 00:00:00 2001 From: whatf0xx Date: Tue, 12 Mar 2024 21:36:59 +0100 Subject: [PATCH] Working and with a single unit test to verify --- src/bounding_volume/aabb.rs | 24 ++++++++++++++++-------- src/bounding_volume/mod.rs | 19 +++++++++++++++++++ src/partitioning/qbvh/mod.rs | 4 +--- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/bounding_volume/aabb.rs b/src/bounding_volume/aabb.rs index df432092..8eec882e 100644 --- a/src/bounding_volume/aabb.rs +++ b/src/bounding_volume/aabb.rs @@ -181,14 +181,18 @@ impl Aabb { pub fn scaled_wrt_center(self, scale: &Vector) -> Self { let center: Point = na::center(&self.mins, &self.maxs); - let translated_min = na::Translation2::from(center).transform_point(&self.mins); - let translated_max = na::Translation2::from(center).transform_point(&self.maxs); + let translated_min = na::Translation2::from(center) + .inverse() + .transform_point(&self.mins); + let translated_max = na::Translation2::from(center) + .inverse() + .transform_point(&self.maxs); let transformed_min = translated_min.coords.component_mul(scale); let transformed_max = translated_max.coords.component_mul(scale); - let a = transformed_min + center; - let b = transformed_max + center; + let a = center + transformed_min; + let b = center + transformed_max; Self { mins: a.inf(&b).into(), @@ -201,14 +205,18 @@ impl Aabb { pub fn scaled_wrt_center(self, scale: &Vector) -> Self { let center: Point = na::center(&self.mins, &self.maxs); - let translated_min = na::Translation3::from(center).transform_point(&self.mins); - let translated_max = na::Translation3::from(center).transform_point(&self.maxs); + let translated_min = na::Translation3::from(center) + .inverse() + .transform_point(&self.mins); + let translated_max = na::Translation3::from(center) + .inverse() + .transform_point(&self.maxs); let transformed_min = translated_min.coords.component_mul(scale); let transformed_max = translated_max.coords.component_mul(scale); - let a = transformed_min + center; - let b = transformed_max + center; + let a = center + transformed_min; + let b = center + transformed_max; Self { mins: a.inf(&b).into(), diff --git a/src/bounding_volume/mod.rs b/src/bounding_volume/mod.rs index 4587f99f..85a501a7 100644 --- a/src/bounding_volume/mod.rs +++ b/src/bounding_volume/mod.rs @@ -62,3 +62,22 @@ pub mod details { pub use super::aabb_utils::{local_point_cloud_aabb, local_support_map_aabb, point_cloud_aabb}; pub use super::bounding_sphere_utils::point_cloud_bounding_sphere; } + +#[cfg(test)] +mod quick_tests { + use super::*; + use crate::math::{Point, Vector}; + + #[test] + #[cfg(feature = "dim2")] + fn aabb_rescale_wrt_origin_2d() { + let x1 = Point::new(1.0, 1.0); + let x2 = Point::new(2.0, 2.0); + let scale = Vector::new(2.0, 2.0); + let aabb = Aabb::new(x1, x2); + let aabbp = aabb.scaled_wrt_center(&scale); + let xp1 = Point::new(0.5, 0.5); + let xp2 = Point::new(2.5, 2.5); + assert_eq!(aabbp, Aabb::new(xp1, xp2)); + } +} diff --git a/src/partitioning/qbvh/mod.rs b/src/partitioning/qbvh/mod.rs index 87ca330a..cd72717b 100644 --- a/src/partitioning/qbvh/mod.rs +++ b/src/partitioning/qbvh/mod.rs @@ -1,8 +1,6 @@ #[cfg(feature = "std")] pub use self::{ - build::{ - BuilderProxies, CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter, - }, + build::{CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter}, update::QbvhUpdateWorkspace, };