Skip to content

Commit

Permalink
chore: a few internal renamings
Browse files Browse the repository at this point in the history
  • Loading branch information
sebcrozet committed May 5, 2024
1 parent 842366c commit dab01e2
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 86 deletions.
10 changes: 2 additions & 8 deletions crates/parry2d/examples/time_of_impact_query2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
26 changes: 10 additions & 16 deletions crates/parry2d/tests/geometry/time_of_impact2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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,
Expand All @@ -86,7 +80,7 @@ fn cuboid_cuboid_toi_issue_214() {
ShapeCastOptions::default(),
)
.unwrap();
assert!(time_of_impact.is_some());
assert!(hit.is_some());
}

#[test]
Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -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,
Expand All @@ -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]
Expand All @@ -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,
Expand All @@ -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);
}
10 changes: 2 additions & 8 deletions crates/parry3d/examples/time_of_impact_query3d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion crates/parry3d/tests/geometry/still_objects_toi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn collide(v_y: f32) -> Option<f32> {
ShapeCastOptions::default(),
)
.unwrap()
.map(|time_of_impact| time_of_impact.time_of_impact)
.map(|hit| hit.time_of_impact)
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions crates/parry3d/tests/geometry/time_of_impact3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion crates/parry3d/tests/geometry/trimesh_trimesh_toi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn do_toi_test() -> Option<Real> {
ShapeCastOptions::default(),
)
.unwrap()
.map(|time_of_impact| time_of_impact.time_of_impact)
.map(|hit| hit.time_of_impact)
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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),
Expand All @@ -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(
Expand All @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}

Expand Down
16 changes: 8 additions & 8 deletions src/query/shape_cast/shape_cast_composite_shape_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/query/shape_cast/shape_cast_halfspace_support_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,5 @@ where
other,
options,
)
.map(|time_of_impact| time_of_impact.swapped())
.map(|hit| hit.swapped())
}
19 changes: 4 additions & 15 deletions src/query/shape_cast/shape_cast_heightfield_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -297,5 +286,5 @@ where
g1,
options,
)?
.map(|time_of_impact| time_of_impact.swapped()))
.map(|hit| hit.swapped()))
}

0 comments on commit dab01e2

Please sign in to comment.