Skip to content

Commit 67bd749

Browse files
committed
wip: using point query options as dyn ; dispatching them depending on shapes knowing their underlying algorithm.
1 parent 7067ee2 commit 67bd749

47 files changed

Lines changed: 536 additions & 180 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/parry2d/examples/project_point2d.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ async fn main() {
3838
&Isometry::from_parts(translation, rot),
3939
&na_from_mquad(point_to_project),
4040
true,
41+
&(),
4142
);
4243

4344
/*
@@ -66,7 +67,8 @@ async fn main() {
6667

6768
// fixed local point inside the shape
6869
let point_to_project = Vec2::ZERO;
69-
let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true);
70+
let projected_point =
71+
trimesh.project_local_point(&na_from_mquad(point_to_project), true, &());
7072
let color = if projected_point.is_inside {
7173
RED
7274
} else {

crates/parry2d/examples/solid_point_query2d.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,26 @@ fn main() {
99
let pt_inside = Point2::origin();
1010
let pt_outside = Point2::new(2.0, 2.0);
1111

12+
let options = &();
1213
// Solid projection.
1314
assert_eq!(
14-
cuboid.distance_to_point(&Isometry2::identity(), &pt_inside, true),
15+
cuboid.distance_to_point(&Isometry2::identity(), &pt_inside, true, options),
1516
0.0
1617
);
1718

1819
// Non-solid projection.
1920
assert_eq!(
20-
cuboid.distance_to_point(&Isometry2::identity(), &pt_inside, false),
21+
cuboid.distance_to_point(&Isometry2::identity(), &pt_inside, false, options),
2122
-1.0
2223
);
2324

2425
// The other point is outside of the cuboid so the `solid` flag has no effect.
2526
assert_eq!(
26-
cuboid.distance_to_point(&Isometry2::identity(), &pt_outside, false),
27+
cuboid.distance_to_point(&Isometry2::identity(), &pt_outside, false, options),
2728
1.0
2829
);
2930
assert_eq!(
30-
cuboid.distance_to_point(&Isometry2::identity(), &pt_outside, true),
31+
cuboid.distance_to_point(&Isometry2::identity(), &pt_outside, true, options),
3132
1.0
3233
);
3334
}

crates/parry2d/tests/geometry/epa2.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use na::{self, Isometry2, Vector2};
2+
use parry2d::query::gjk::GjkOptions;
23
use parry2d::query::{self, ContactManifold, DefaultQueryDispatcher, PersistentQueryDispatcher};
34
use parry2d::shape::Cuboid;
45

@@ -8,15 +9,17 @@ fn cuboid_cuboid_EPA() {
89
let c = Cuboid::new(Vector2::new(2.0, 1.0));
910
let m1 = Isometry2::translation(3.5, 0.0);
1011
let m2 = Isometry2::identity();
11-
12-
let res = query::details::contact_support_map_support_map(&m1.inv_mul(&m2), &c, &c, 10.0)
13-
.expect("Penetration not found.");
12+
let options = GjkOptions::default();
13+
let res =
14+
query::details::contact_support_map_support_map(&m1.inv_mul(&m2), &c, &c, 10.0, &options)
15+
.expect("Penetration not found.");
1416
assert_eq!(res.dist, -0.5);
1517
assert_eq!(res.normal1, -Vector2::x_axis());
1618

1719
let m1 = Isometry2::translation(0.0, 0.2);
18-
let res = query::details::contact_support_map_support_map(&m1.inv_mul(&m2), &c, &c, 10.0)
19-
.expect("Penetration not found.");
20+
let res =
21+
query::details::contact_support_map_support_map(&m1.inv_mul(&m2), &c, &c, 10.0, &options)
22+
.expect("Penetration not found.");
2023
assert_eq!(res.dist, -1.8);
2124
assert_eq!(res.normal1, -Vector2::y_axis());
2225
}

crates/parry2d/tests/geometry/epa_convergence.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use na::Vector2;
22
use parry2d::{
33
math::{Isometry, Point, Real},
4-
query,
4+
query::{self, gjk::GjkOptions},
55
shape::{Capsule, ConvexPolygon, SharedShape},
66
};
77

@@ -23,6 +23,7 @@ fn capsule_convergence() {
2323
&shape1,
2424
&shape2,
2525
10.0,
26+
&GjkOptions::default(),
2627
)
2728
.expect("Penetration not found.");
2829
let shared_shape1 = SharedShape::new(shape1);

crates/parry2d/tests/query/point_composite_shape.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
use na::Point2;
2-
use parry2d::{query::PointQuery, shape::TriMesh};
2+
use parry2d::{
3+
query::{gjk::GjkOptions, PointQuery},
4+
shape::TriMesh,
5+
};
36

47
#[test]
58
fn project_local_point_and_get_feature_gets_the_enclosing_triangle() {
@@ -11,14 +14,15 @@ fn project_local_point_and_get_feature_gets_the_enclosing_triangle() {
1114
];
1215

1316
let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]).unwrap();
17+
let options = &();
1418
let query_pt = Point2::new(0.6, 0.6); // Inside the top-right triangle (index 1)
1519

16-
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);
20+
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt, options);
1721

1822
let correct_tri_idx = 1;
1923
let correct_tri = mesh.triangle(correct_tri_idx);
2024

21-
let is_inside_correct = correct_tri.contains_local_point(&query_pt);
25+
let is_inside_correct = correct_tri.contains_local_point(&query_pt, options);
2226

2327
assert!(is_inside_correct);
2428
assert_eq!(proj.is_inside, is_inside_correct);
@@ -35,16 +39,16 @@ fn project_local_point_and_get_feature_projects_correctly_from_outside() {
3539
];
3640

3741
let mesh = TriMesh::new(vertices, vec![[0, 1, 2], [3, 0, 2]]).unwrap();
38-
42+
let options = &();
3943
{
4044
let query_pt = Point2::new(-1.0, 0.0); // Left from the bottom-left triangle (index 0)
4145

42-
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);
46+
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt, options);
4347

4448
let correct_tri_idx = 0;
4549
let correct_tri = mesh.triangle(correct_tri_idx);
4650

47-
let is_inside_correct = correct_tri.contains_local_point(&query_pt);
51+
let is_inside_correct = correct_tri.contains_local_point(&query_pt, options);
4852

4953
assert_eq!(is_inside_correct, false);
5054
assert_eq!(proj.is_inside, is_inside_correct);
@@ -54,12 +58,12 @@ fn project_local_point_and_get_feature_projects_correctly_from_outside() {
5458
{
5559
let query_pt = Point2::new(0.5, 2.0); // Above the top-right triangle (index 1)
5660

57-
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt);
61+
let (proj, feat) = mesh.project_local_point_and_get_feature(&query_pt, options);
5862

5963
let correct_tri_idx = 1;
6064
let correct_tri = mesh.triangle(correct_tri_idx);
6165

62-
let is_inside_correct = correct_tri.contains_local_point(&query_pt);
66+
let is_inside_correct = correct_tri.contains_local_point(&query_pt, options);
6367

6468
assert_eq!(is_inside_correct, false);
6569
assert_eq!(proj.is_inside, is_inside_correct);

crates/parry2d/tests/query/point_triangle.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ fn project_local_point_point_on_ab() {
1212

1313
let query_pt = Point::new(1.4, 1.0);
1414

15-
let proj1 = tri1.project_local_point(&query_pt, false); // Used to fail on 0.14 and earlier
16-
let proj2 = tri2.project_local_point(&query_pt, false);
15+
let proj1 = tri1.project_local_point(&query_pt, false, &()); // Used to fail on 0.14 and earlier
16+
let proj2 = tri2.project_local_point(&query_pt, false, &());
1717

1818
assert_eq!(proj1.point, proj2.point);
1919
assert_eq!(proj1.point, query_pt);

crates/parry3d/examples/project_point3d.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ async fn main() {
2424
let slow_elapsed_time = elapsed_time / 3.0;
2525

2626
let point_to_project = lissajous_3d(slow_elapsed_time);
27-
let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true);
27+
let projected_point =
28+
trimesh.project_local_point(&na_from_mquad(point_to_project), true, &());
2829

2930
let slow_elapsed_time = slow_elapsed_time * 0.7;
3031
// Setup 3D camera.
@@ -65,7 +66,8 @@ async fn main() {
6566

6667
// fixed point inside the shape
6768
let point_to_project = Vec3::ZERO;
68-
let projected_point = trimesh.project_local_point(&na_from_mquad(point_to_project), true);
69+
let projected_point =
70+
trimesh.project_local_point(&na_from_mquad(point_to_project), true, &());
6971
let color = if projected_point.is_inside {
7072
RED
7173
} else {

crates/parry3d/examples/solid_point_query3d.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@ fn main() {
88
let cuboid = Cuboid::new(Vector3::new(1.0, 2.0, 2.0));
99
let pt_inside = Point3::origin();
1010
let pt_outside = Point3::new(2.0, 2.0, 2.0);
11+
let options = &();
1112

1213
// Solid projection.
1314
assert_eq!(
14-
cuboid.distance_to_point(&Isometry3::identity(), &pt_inside, true),
15+
cuboid.distance_to_point(&Isometry3::identity(), &pt_inside, true, options),
1516
0.0
1617
);
1718

1819
// Non-solid projection.
1920
assert_eq!(
20-
cuboid.distance_to_point(&Isometry3::identity(), &pt_inside, false),
21+
cuboid.distance_to_point(&Isometry3::identity(), &pt_inside, false, options),
2122
-1.0
2223
);
2324

2425
// The other point is outside of the cuboid so the `solid` flag has no effect.
2526
assert_eq!(
26-
cuboid.distance_to_point(&Isometry3::identity(), &pt_outside, false),
27+
cuboid.distance_to_point(&Isometry3::identity(), &pt_outside, false, options),
2728
1.0
2829
);
2930
assert_eq!(
30-
cuboid.distance_to_point(&Isometry3::identity(), &pt_outside, true),
31+
cuboid.distance_to_point(&Isometry3::identity(), &pt_outside, true, options),
3132
1.0
3233
);
3334
}

crates/parry3d/tests/geometry/cuboid_ray_cast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ where
4242
let point_nudged_out = point + intersection.normal * 0.001;
4343

4444
assert!(
45-
shape.contains_point(&position, &point_nudged_in),
45+
shape.contains_point(&position, &point_nudged_in, &()),
4646
"Shape {} rotated with {:#?} does not contain point nudged in {:#?}",
4747
name,
4848
rotation.axis(),
4949
point_nudged_in,
5050
);
5151

5252
assert!(
53-
!shape.contains_point(&position, &point_nudged_out),
53+
!shape.contains_point(&position, &point_nudged_out, &()),
5454
"Shape {} rotated with {:#?} does contains point nudged out {:#?}",
5555
name,
5656
rotation.axis(),

crates/parry3d/tests/geometry/cylinder_cuboid_contact.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use na::{self, Isometry3, Vector3};
22
use parry3d::query;
3+
use parry3d::query::gjk::GjkOptions;
34
use parry3d::shape::{Cuboid, Cylinder};
45

56
// Issue #157.
@@ -9,23 +10,28 @@ fn cylinder_cuboid_contact() {
910
let cyl_at = Isometry3::translation(10.97, 0.925, 61.02);
1011
let cuboid = Cuboid::new(Vector3::new(0.05, 0.75, 0.5));
1112
let cuboid_at = Isometry3::translation(11.50, 0.75, 60.5);
13+
let options = GjkOptions::default();
14+
1215
let distance = query::details::distance_support_map_support_map(
1316
&cyl_at.inv_mul(&cuboid_at),
1417
&cyl,
1518
&cuboid,
19+
&options,
1620
);
1721

1822
let intersecting = query::details::intersection_test_support_map_support_map(
1923
&cyl_at.inv_mul(&cuboid_at),
2024
&cyl,
2125
&cuboid,
26+
&options,
2227
);
2328

2429
let contact = query::details::contact_support_map_support_map(
2530
&cyl_at.inv_mul(&cuboid_at),
2631
&cyl,
2732
&cuboid,
2833
10.0,
34+
&options,
2935
);
3036

3137
assert!(distance == 0.0);

0 commit comments

Comments
 (0)