@@ -11,10 +11,10 @@ use std::fmt::Debug;
1111mod polygon;
1212mod polytope;
1313mod primitives;
14+ use crate :: util:: index_set_nth_power_iter;
1415pub use polygon:: * ;
1516pub use polytope:: * ;
1617pub use primitives:: * ;
17- use crate :: util:: { index_set_nth_power_iter} ;
1818
1919pub mod polymesh;
2020pub mod sdf;
@@ -153,10 +153,18 @@ where
153153{
154154 /// Computes the minimal bounding box which encloses both `this` and `other`.
155155 pub fn enclose ( & self , other : & AxisAlignedBoundingBox < T , D > ) -> Self {
156- let min = self . min . iter ( ) . zip ( & other. min . coords ) . map ( |( a, b) | T :: min ( * a, * b) ) ;
156+ let min = self
157+ . min
158+ . iter ( )
159+ . zip ( & other. min . coords )
160+ . map ( |( a, b) | T :: min ( * a, * b) ) ;
157161 let min = OVector :: < T , D > :: from_iterator ( min) ;
158162
159- let max = self . max . iter ( ) . zip ( & other. max . coords ) . map ( |( a, b) | T :: max ( * a, * b) ) ;
163+ let max = self
164+ . max
165+ . iter ( )
166+ . zip ( & other. max . coords )
167+ . map ( |( a, b) | T :: max ( * a, * b) ) ;
160168 let max = OVector :: < T , D > :: from_iterator ( max) ;
161169
162170 AxisAlignedBoundingBox :: new ( min. into ( ) , max. into ( ) )
@@ -242,20 +250,20 @@ where
242250 }
243251
244252 /// Creates an iterator over the corners of the bounding box.
245- pub fn corners_iter < ' a > ( & ' a self ) -> impl ' a + Iterator < Item = OPoint < T , D > >
253+ pub fn corners_iter < ' a > ( & ' a self ) -> impl ' a + Iterator < Item = OPoint < T , D > >
246254 where
247- DefaultAllocator : Allocator < usize , D >
255+ DefaultAllocator : Allocator < usize , D > ,
248256 {
249257 // We can enumerate the corners by looking at {0, 1}^D, i.e. the D-th power of the
250258 // set {0, 1}, and associating 0 and 1 with min and max coordinates for the i-th axis.
251- index_set_nth_power_iter :: < D > ( 2 )
252- . map ( move |multi_idx| {
253- OVector :: < T , D > :: from_fn ( |idx, _| match multi_idx[ idx] {
254- 0 => self . min [ idx] . clone ( ) ,
255- 1 => self . max [ idx] . clone ( ) ,
256- _ => unreachable ! ( )
257- } ) . into ( )
259+ index_set_nth_power_iter :: < D > ( 2 ) . map ( move |multi_idx| {
260+ OVector :: < T , D > :: from_fn ( |idx, _| match multi_idx[ idx] {
261+ 0 => self . min [ idx] . clone ( ) ,
262+ 1 => self . max [ idx] . clone ( ) ,
263+ _ => unreachable ! ( ) ,
258264 } )
265+ . into ( )
266+ } )
259267 }
260268
261269 /// Compute the point in the bounding box furthest away from the given point.
@@ -271,22 +279,21 @@ where
271279 #[ replace_float_literals( T :: from_f64( literal) . unwrap( ) ) ]
272280 pub fn furthest_point_to ( & self , point : & OPoint < T , D > ) -> OPoint < T , D >
273281 where
274- DefaultAllocator : Allocator < usize , D >
282+ DefaultAllocator : Allocator < usize , D > ,
275283 {
276284 // It turns out that we can choose, along each dimension, the point in the interval
277285 // [a_i, b_i] furthest away from p_i.
278- point. coords . zip_zip_map (
279- & self . min . coords ,
280- & self . max . coords ,
281- |p_i, a_i, b_i| {
286+ point
287+ . coords
288+ . zip_zip_map ( & self . min . coords , & self . max . coords , |p_i, a_i, b_i| {
282289 let mid = ( a_i + b_i) / 2.0 ;
283290 if p_i < mid {
284291 b_i
285292 } else {
286293 a_i
287294 }
288- }
289- ) . into ( )
295+ } )
296+ . into ( )
290297 }
291298
292299 /// The squared distance to the point in the bounding box furthest away from the given point.
@@ -297,7 +304,7 @@ where
297304 pub fn max_dist2_to ( & self , point : & OPoint < T , D > ) -> T
298305 where
299306 // TODO: Use DimAllocator and SmallDim
300- DefaultAllocator : Allocator < usize , D >
307+ DefaultAllocator : Allocator < usize , D > ,
301308 {
302309 ( self . furthest_point_to ( point) - point) . norm_squared ( )
303310 }
@@ -309,8 +316,8 @@ where
309316 /// Panic behavior is identical to [`max_dist2_to`](Self::max_dist2_to).
310317 pub fn max_dist_to ( & self , point : & OPoint < T , D > ) -> T
311318 where
312- // TODO: Use DimAllocator and SmallDim
313- DefaultAllocator : Allocator < usize , D >
319+ // TODO: Use DimAllocator and SmallDim
320+ DefaultAllocator : Allocator < usize , D > ,
314321 {
315322 self . max_dist2_to ( point) . sqrt ( )
316323 }
0 commit comments