From dab01e27ea4fd25590e84d59eed57000d11e6f14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Sun, 5 May 2024 15:32:29 +0200 Subject: [PATCH] chore: a few internal renamings --- .../examples/time_of_impact_query2d.rs | 10 +--- .../parry2d/tests/geometry/time_of_impact2.rs | 26 ++++------- .../examples/time_of_impact_query3d.rs | 10 +--- .../tests/geometry/still_objects_toi.rs | 2 +- .../parry3d/tests/geometry/time_of_impact3.rs | 6 +-- .../tests/geometry/trimesh_trimesh_toi.rs | 2 +- ...linear_shape_cast_composite_shape_shape.rs | 46 +++++++++---------- ...near_shape_cast_support_map_support_map.rs | 2 +- .../shape_cast_composite_shape_shape.rs | 16 +++---- .../shape_cast_halfspace_support_map.rs | 2 +- .../shape_cast_heightfield_shape.rs | 19 ++------ 11 files changed, 55 insertions(+), 86 deletions(-) diff --git a/crates/parry2d/examples/time_of_impact_query2d.rs b/crates/parry2d/examples/time_of_impact_query2d.rs index 8f4cfeee..d96e1d07 100644 --- a/crates/parry2d/examples/time_of_impact_query2d.rs +++ b/crates/parry2d/examples/time_of_impact_query2d.rs @@ -51,14 +51,8 @@ fn main() { ) .unwrap(); - assert_eq!( - toi_intersecting.map(|time_of_impact| time_of_impact.time_of_impact), - Some(0.0) - ); + assert_eq!(toi_intersecting.map(|hit| hit.time_of_impact), Some(0.0)); println!("Toi: {:?}", toi_will_touch); assert!(toi_will_touch.is_some() && toi_will_touch.unwrap().time_of_impact > 0.0); - assert_eq!( - toi_wont_touch.map(|time_of_impact| time_of_impact.time_of_impact), - None - ); + assert_eq!(toi_wont_touch.map(|hit| hit.time_of_impact), None); } diff --git a/crates/parry2d/tests/geometry/time_of_impact2.rs b/crates/parry2d/tests/geometry/time_of_impact2.rs index f2dc5011..bcb47ec2 100644 --- a/crates/parry2d/tests/geometry/time_of_impact2.rs +++ b/crates/parry2d/tests/geometry/time_of_impact2.rs @@ -51,18 +51,12 @@ fn ball_cuboid_toi() { ) .unwrap(); - assert_eq!( - toi_intersecting.map(|time_of_impact| time_of_impact.time_of_impact), - Some(0.0) - ); + assert_eq!(toi_intersecting.map(|hit| hit.time_of_impact), Some(0.0)); assert!(relative_eq!( toi_will_touch.unwrap().time_of_impact, ((2.0 as Real).sqrt() - 1.0) / (ball_vel2 - cuboid_vel2).norm() )); - assert_eq!( - toi_wont_touch.map(|time_of_impact| time_of_impact.time_of_impact), - None - ); + assert_eq!(toi_wont_touch.map(|hit| hit.time_of_impact), None); } #[test] @@ -76,7 +70,7 @@ fn cuboid_cuboid_toi_issue_214() { let vel1 = Vector2::new(1.0, 0.0); let vel2 = Vector2::new(0.0, 0.0); - let time_of_impact = query::cast_shapes( + let hit = query::cast_shapes( &pos1, &vel1, &shape1, @@ -86,7 +80,7 @@ fn cuboid_cuboid_toi_issue_214() { ShapeCastOptions::default(), ) .unwrap(); - assert!(time_of_impact.is_some()); + assert!(hit.is_some()); } #[test] @@ -107,7 +101,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_polyline() { Point2::new(1.0, 0.99999994) ); - let time_of_impact = query::cast_shapes( + let hit = query::cast_shapes( &ball_isometry, &ball_velocity, &ball, @@ -118,7 +112,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_polyline() { ) .unwrap(); - assert_eq!(time_of_impact.unwrap().time_of_impact, 0.5); + assert_eq!(hit.unwrap().time_of_impact, 0.5); } #[test] @@ -139,7 +133,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_segment() { Point2::new(1.0, 0.99999994) ); - let time_of_impact = query::cast_shapes( + let hit = query::cast_shapes( &ball_isometry, &ball_velocity, &ball, @@ -150,7 +144,7 @@ fn cast_shapes_should_return_toi_for_ball_and_rotated_segment() { ) .unwrap(); - assert_eq!(time_of_impact.unwrap().time_of_impact, 0.49999994); + assert_eq!(hit.unwrap().time_of_impact, 0.49999994); } #[test] @@ -171,7 +165,7 @@ fn cast_shapes_should_return_toi_for_rotated_segment_and_ball() { Point2::new(1.0, 0.99999994) ); - let time_of_impact = query::cast_shapes( + let hit = query::cast_shapes( &segment_isometry, &segment_velocity, &segment, @@ -182,5 +176,5 @@ fn cast_shapes_should_return_toi_for_rotated_segment_and_ball() { ) .unwrap(); - assert_eq!(time_of_impact.unwrap().time_of_impact, 0.5); + assert_eq!(hit.unwrap().time_of_impact, 0.5); } diff --git a/crates/parry3d/examples/time_of_impact_query3d.rs b/crates/parry3d/examples/time_of_impact_query3d.rs index 354d986a..20028785 100644 --- a/crates/parry3d/examples/time_of_impact_query3d.rs +++ b/crates/parry3d/examples/time_of_impact_query3d.rs @@ -50,13 +50,7 @@ fn main() { ) .unwrap(); - assert_eq!( - toi_intersecting.map(|time_of_impact| time_of_impact.time_of_impact), - Some(0.0) - ); + assert_eq!(toi_intersecting.map(|hit| hit.time_of_impact), Some(0.0)); assert!(toi_will_touch.is_some() && toi_will_touch.unwrap().time_of_impact > 0.0); - assert_eq!( - toi_wont_touch.map(|time_of_impact| time_of_impact.time_of_impact), - None - ); + assert_eq!(toi_wont_touch.map(|hit| hit.time_of_impact), None); } diff --git a/crates/parry3d/tests/geometry/still_objects_toi.rs b/crates/parry3d/tests/geometry/still_objects_toi.rs index d353a8e5..3c9bad02 100644 --- a/crates/parry3d/tests/geometry/still_objects_toi.rs +++ b/crates/parry3d/tests/geometry/still_objects_toi.rs @@ -35,7 +35,7 @@ fn collide(v_y: f32) -> Option { ShapeCastOptions::default(), ) .unwrap() - .map(|time_of_impact| time_of_impact.time_of_impact) + .map(|hit| hit.time_of_impact) } #[test] diff --git a/crates/parry3d/tests/geometry/time_of_impact3.rs b/crates/parry3d/tests/geometry/time_of_impact3.rs index e2907dec..71cbcf45 100644 --- a/crates/parry3d/tests/geometry/time_of_impact3.rs +++ b/crates/parry3d/tests/geometry/time_of_impact3.rs @@ -29,7 +29,7 @@ fn ball_cuboid_toi() { ShapeCastOptions::default(), ) .unwrap() - .map(|time_of_impact| time_of_impact.time_of_impact); + .map(|hit| hit.time_of_impact); let toi_will_touch = query::cast_shapes( &ball_pos_will_touch, &ball_vel2, @@ -40,7 +40,7 @@ fn ball_cuboid_toi() { ShapeCastOptions::default(), ) .unwrap() - .map(|time_of_impact| time_of_impact.time_of_impact); + .map(|hit| hit.time_of_impact); let toi_wont_touch = query::cast_shapes( &ball_pos_wont_touch, &ball_vel1, @@ -51,7 +51,7 @@ fn ball_cuboid_toi() { ShapeCastOptions::default(), ) .unwrap() - .map(|time_of_impact| time_of_impact.time_of_impact); + .map(|hit| hit.time_of_impact); assert_eq!(toi_intersecting, Some(0.0)); assert!(relative_eq!( diff --git a/crates/parry3d/tests/geometry/trimesh_trimesh_toi.rs b/crates/parry3d/tests/geometry/trimesh_trimesh_toi.rs index d676bd73..22493edb 100644 --- a/crates/parry3d/tests/geometry/trimesh_trimesh_toi.rs +++ b/crates/parry3d/tests/geometry/trimesh_trimesh_toi.rs @@ -43,7 +43,7 @@ fn do_toi_test() -> Option { ShapeCastOptions::default(), ) .unwrap() - .map(|time_of_impact| time_of_impact.time_of_impact) + .map(|hit| hit.time_of_impact) } #[test] diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs index 03402609..959d37de 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_composite_shape_shape.rs @@ -63,7 +63,7 @@ where end_time, stop_at_penetration, ) - .map(|time_of_impact| time_of_impact.swapped()) + .map(|hit| hit.swapped()) } /// A visitor used to determine the non-linear time of impact between a composite shape and another shape. @@ -141,25 +141,23 @@ where let ball_motion1 = self.motion1.prepend_translation(center1.coords); let ball_motion2 = self.motion2.prepend_translation(self.sphere2.center.coords); - if let Some(time_of_impact) = - query::details::cast_shapes_nonlinear_support_map_support_map( - self.dispatcher, - &ball_motion1, - &ball1, - &ball1, - &ball_motion2, - &ball2, - &ball2, - self.start_time, - self.end_time, - NonlinearShapeCastMode::StopAtPenetration, - ) - { + if let Some(hit) = query::details::cast_shapes_nonlinear_support_map_support_map( + self.dispatcher, + &ball_motion1, + &ball1, + &ball1, + &ball_motion2, + &ball2, + &ball2, + self.start_time, + self.end_time, + NonlinearShapeCastMode::StopAtPenetration, + ) { if let Some(data) = data { - if time_of_impact.time_of_impact < best && data[ii].is_some() { + if hit.time_of_impact < best && data[ii].is_some() { let part_id = *data[ii].unwrap(); self.g1.map_untyped_part_at(part_id, |part_pos1, g1, _| { - let time_of_impact = if let Some(part_pos1) = part_pos1 { + let hit = if let Some(part_pos1) = part_pos1 { self.dispatcher .cast_shapes_nonlinear( &self.motion1.prepend(*part_pos1), @@ -171,7 +169,7 @@ where self.stop_at_penetration, ) .unwrap_or(None) - .map(|time_of_impact| time_of_impact.transform1_by(part_pos1)) + .map(|hit| hit.transform1_by(part_pos1)) } else { self.dispatcher .cast_shapes_nonlinear( @@ -188,16 +186,16 @@ where // println!("Found time_of_impact: {:?}", time_of_impact); - if let Some(time_of_impact) = time_of_impact { - weights[ii] = time_of_impact.time_of_impact; - mask[ii] = time_of_impact.time_of_impact < best; - results[ii] = Some((part_id, time_of_impact)); + if let Some(hit) = hit { + weights[ii] = hit.time_of_impact; + mask[ii] = hit.time_of_impact < best; + results[ii] = Some((part_id, hit)); } }); } } else { - weights[ii] = time_of_impact.time_of_impact; - mask[ii] = time_of_impact.time_of_impact < best; + weights[ii] = hit.time_of_impact; + mask[ii] = hit.time_of_impact < best; } } } diff --git a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs index b000e3f0..bb04772f 100644 --- a/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs +++ b/src/query/nonlinear_shape_cast/nonlinear_shape_cast_support_map_support_map.rs @@ -87,7 +87,7 @@ where compute_toi( dispatcher, motion2, sm2, g2, motion1, sm1, g1, start_time, end_time, mode, ) - .map(|time_of_impact| time_of_impact.swapped()) + .map(|hit| hit.swapped()) } } diff --git a/src/query/shape_cast/shape_cast_composite_shape_shape.rs b/src/query/shape_cast/shape_cast_composite_shape_shape.rs index 55e008f8..915a5e6d 100644 --- a/src/query/shape_cast/shape_cast_composite_shape_shape.rs +++ b/src/query/shape_cast/shape_cast_composite_shape_shape.rs @@ -132,10 +132,10 @@ where for ii in 0..SIMD_WIDTH { if (bitmask & (1 << ii)) != 0 && data[ii].is_some() { let part_id = *data[ii].unwrap(); - let mut time_of_impact = None; + let mut hit = None; self.g1.map_untyped_part_at(part_id, |part_pos1, g1, _| { if let Some(part_pos1) = part_pos1 { - time_of_impact = self + hit = self .dispatcher .cast_shapes( &part_pos1.inv_mul(self.pos12), @@ -145,19 +145,19 @@ where self.options, ) .unwrap_or(None) - .map(|time_of_impact| time_of_impact.transform1_by(part_pos1)); + .map(|hit| hit.transform1_by(part_pos1)); } else { - time_of_impact = self + hit = self .dispatcher .cast_shapes(self.pos12, self.vel12, g1, self.g2, self.options) .unwrap_or(None); } }); - if let Some(time_of_impact) = time_of_impact { - results[ii] = Some((part_id, time_of_impact)); - mask[ii] = time_of_impact.time_of_impact < best; - weights[ii] = time_of_impact.time_of_impact; + if let Some(hit) = hit { + results[ii] = Some((part_id, hit)); + mask[ii] = hit.time_of_impact < best; + weights[ii] = hit.time_of_impact; } } } diff --git a/src/query/shape_cast/shape_cast_halfspace_support_map.rs b/src/query/shape_cast/shape_cast_halfspace_support_map.rs index 23932ba3..8d866cd2 100644 --- a/src/query/shape_cast/shape_cast_halfspace_support_map.rs +++ b/src/query/shape_cast/shape_cast_halfspace_support_map.rs @@ -80,5 +80,5 @@ where other, options, ) - .map(|time_of_impact| time_of_impact.swapped()) + .map(|hit| hit.swapped()) } diff --git a/src/query/shape_cast/shape_cast_heightfield_shape.rs b/src/query/shape_cast/shape_cast_heightfield_shape.rs index da32b299..d963722e 100644 --- a/src/query/shape_cast/shape_cast_heightfield_shape.rs +++ b/src/query/shape_cast/shape_cast_heightfield_shape.rs @@ -43,11 +43,7 @@ where if let Some(seg) = heightfield1.segment_at(curr) { // TODO: pre-check using a ray-cast on the Aabbs first? if let Some(hit) = dispatcher.cast_shapes(pos12, vel12, &seg, g2, options)? { - if hit.time_of_impact - < best_hit - .map(|time_of_impact| time_of_impact.time_of_impact) - .unwrap_or(Real::MAX) - { + if hit.time_of_impact < best_hit.map(|h| h.time_of_impact).unwrap_or(Real::MAX) { best_hit = Some(hit); } } @@ -92,11 +88,7 @@ where if let Some(seg) = heightfield1.segment_at(curr_elt as usize) { // TODO: pre-check using a ray-cast on the Aabbs first? if let Some(hit) = dispatcher.cast_shapes(pos12, vel12, &seg, g2, options)? { - if hit.time_of_impact - < best_hit - .map(|time_of_impact| time_of_impact.time_of_impact) - .unwrap_or(Real::MAX) - { + if hit.time_of_impact < best_hit.map(|h| h.time_of_impact).unwrap_or(Real::MAX) { best_hit = Some(hit); } } @@ -168,10 +160,7 @@ where for tri in [tri_a, tri_b].into_iter().flatten() { // TODO: pre-check using a ray-cast on the Aabbs first? if let Some(hit) = dispatcher.cast_shapes(pos12, vel12, &tri, g2, options)? { - if hit.time_of_impact - < best_hit - .map(|time_of_impact| time_of_impact.time_of_impact) - .unwrap_or(Real::MAX) + if hit.time_of_impact < best_hit.map(|h| h.time_of_impact).unwrap_or(Real::MAX) { best_hit = Some(hit); } @@ -297,5 +286,5 @@ where g1, options, )? - .map(|time_of_impact| time_of_impact.swapped())) + .map(|hit| hit.swapped())) }