From 455ecd84e57837a00e00ddeb53e2928d174e2758 Mon Sep 17 00:00:00 2001 From: Duncan Date: Thu, 3 Dec 2020 21:33:20 -0800 Subject: [PATCH] use direct nalgebra conversions instead of mint for the collision code --- crates/building_blocks_search/Cargo.toml | 3 +-- crates/building_blocks_search/src/collision.rs | 11 ++++------- crates/building_blocks_search/src/lib.rs | 10 ---------- crates/building_blocks_search/src/octree_dbvt.rs | 6 +++--- 4 files changed, 8 insertions(+), 22 deletions(-) diff --git a/crates/building_blocks_search/Cargo.toml b/crates/building_blocks_search/Cargo.toml index d9ed32cd..3b8f0637 100644 --- a/crates/building_blocks_search/Cargo.toml +++ b/crates/building_blocks_search/Cargo.toml @@ -12,7 +12,7 @@ description = "Search algorithms for voxel data." [features] default = [] -ncollide = ["mint", "nalgebra", "ncollide3d", "building_blocks_core/mint"] +ncollide = ["nalgebra", "ncollide3d", "building_blocks_core/nalgebra"] [dependencies] fnv = "1.0" @@ -20,7 +20,6 @@ indexmap = "1.5" itertools = "0.9" # Optional, feature-gated -mint = { version = "0.5", optional = true } nalgebra = { version = "0.23", optional = true, features = ["mint"] } ncollide3d = { version = "0.26", optional = true } diff --git a/crates/building_blocks_search/src/collision.rs b/crates/building_blocks_search/src/collision.rs index 4ef72702..1d4fecdc 100644 --- a/crates/building_blocks_search/src/collision.rs +++ b/crates/building_blocks_search/src/collision.rs @@ -1,7 +1,4 @@ -use crate::{ - na_conversions::na_point3f_from_point3i, - octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor}, -}; +use crate::octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor}; use building_blocks_core::prelude::*; use building_blocks_storage::octree::{Octant, VisitStatus}; @@ -272,7 +269,7 @@ fn impact_with_leaf_octant( // land in the correct voxel. It should help to nudge the point along the // intersection normal by some amount less than 1.0. const NUDGE_AMOUNT: f32 = 0.25; - let nudged_p: mint::Point3 = (contact - NUDGE_AMOUNT * octant_normal).into(); + let nudged_p = contact - NUDGE_AMOUNT * octant_normal; Point3f::from(nudged_p).in_voxel() } @@ -283,14 +280,14 @@ fn extent3i_cuboid(e: &Extent3i) -> Cuboid { } fn extent3i_cuboid_transform(e: &Extent3i) -> Isometry3 { - let min = na_point3f_from_point3i(e.minimum); + let min = na::Point3::from(Point3f::from(e.minimum)); let center = min + half_extent(e.shape); Isometry3::new(center.coords, zero()) } fn half_extent(shape: Point3i) -> na::Vector3 { - na_point3f_from_point3i(shape).coords / 2.0 + na::Vector3::from(Point3f::from(shape)) / 2.0 } // ████████╗███████╗███████╗████████╗ diff --git a/crates/building_blocks_search/src/lib.rs b/crates/building_blocks_search/src/lib.rs index 1b10239d..6325d394 100644 --- a/crates/building_blocks_search/src/lib.rs +++ b/crates/building_blocks_search/src/lib.rs @@ -15,13 +15,3 @@ pub use octree_dbvt::{OctreeDBVT, OctreeDBVTVisitor}; #[cfg(feature = "ncollide")] pub use ncollide3d; - -#[cfg(feature = "ncollide")] -mod na_conversions { - use building_blocks_core::{Point3f, Point3i}; - use nalgebra as na; - - pub fn na_point3f_from_point3i(p: Point3i) -> na::Point3 { - mint::Point3::from(Point3f::from(p)).into() - } -} diff --git a/crates/building_blocks_search/src/octree_dbvt.rs b/crates/building_blocks_search/src/octree_dbvt.rs index f0aabf76..4c775843 100644 --- a/crates/building_blocks_search/src/octree_dbvt.rs +++ b/crates/building_blocks_search/src/octree_dbvt.rs @@ -6,11 +6,11 @@ use building_blocks_core::prelude::*; use building_blocks_storage::octree::{Octant, OctreeSet, OctreeVisitor, VisitStatus}; -use crate::na_conversions::na_point3f_from_point3i; use core::hash::Hash; use fnv::FnvHashMap; use ncollide3d::{ bounding_volume::AABB, + na, partitioning::{self as nc_part, DBVTLeaf, DBVTLeafId, BVH, DBVT}, }; @@ -99,8 +99,8 @@ pub trait OctreeDBVTVisitor { } pub fn octant_aabb(octant: &Octant) -> AABB { - let aabb_min = na_point3f_from_point3i(octant.minimum); - let aabb_max = na_point3f_from_point3i(octant.minimum + PointN([octant.edge_length; 3])); + let aabb_min = Point3f::from(octant.minimum).into(); + let aabb_max = Point3f::from(octant.minimum + PointN([octant.edge_length; 3])).into(); AABB::new(aabb_min, aabb_max) }