Skip to content

Commit

Permalink
Working and with a single unit test to verify
Browse files Browse the repository at this point in the history
  • Loading branch information
whatf0xx committed Mar 12, 2024
1 parent fa8db53 commit df04e0f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 11 deletions.
24 changes: 16 additions & 8 deletions src/bounding_volume/aabb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,18 @@ impl Aabb {
pub fn scaled_wrt_center(self, scale: &Vector<Real>) -> Self {
let center: Point<Real> = 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(),
Expand All @@ -201,14 +205,18 @@ impl Aabb {
pub fn scaled_wrt_center(self, scale: &Vector<Real>) -> Self {
let center: Point<Real> = 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(),
Expand Down
19 changes: 19 additions & 0 deletions src/bounding_volume/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
4 changes: 1 addition & 3 deletions src/partitioning/qbvh/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#[cfg(feature = "std")]
pub use self::{
build::{
BuilderProxies, CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter,
},
build::{CenterDataSplitter, QbvhDataGenerator, QbvhNonOverlappingDataSplitter},
update::QbvhUpdateWorkspace,
};

Expand Down

0 comments on commit df04e0f

Please sign in to comment.