ncollide3d/pipeline/object/
query_type.rs

1use crate::query::ContactPrediction;
2use na::RealField;
3
4/// The kind of query a CollisionObject may be involved on.
5///
6/// The following queries are executed for a given pair of `GeometricQueryType` associated with two
7/// collision objects:
8///
9/// * Contacts + Contacts = exact contact point coputation.
10/// * Contacts + Proximity = proximity test only.
11/// * Proximity + Proximity = proximity test only.
12#[derive(Debug, PartialEq, Clone, Copy)]
13pub enum GeometricQueryType<N: RealField + Copy> {
14    /// This objects can respond to both contact point computation and proximity queries.
15    Contacts(N, N),
16    /// This object can respond to proximity tests only.
17    Proximity(N),
18    // FIXME: not yet implemented: Distance
19}
20
21impl<N: RealField + Copy> GeometricQueryType<N> {
22    /// The numerical distance limit of relevance for this query.
23    ///
24    /// If two objects are separated by a distance greater than the sum of their respective
25    /// `query_limit`, the corresponding query will not by performed. For proximity queries,
26    /// non-intersecting object closer than a distance equal to the sum of their `query_limit` will
27    /// be reported as `Proximity::WithinMargin`.
28    #[inline]
29    pub fn query_limit(&self) -> N {
30        match *self {
31            GeometricQueryType::Contacts(ref val, _) => *val,
32            GeometricQueryType::Proximity(ref val) => *val,
33        }
34    }
35
36    /// Given two contact query types, returns the corresponding contact prediction parameters.
37    ///
38    /// Returns `None` if any of `self` or `other` is not a `GeometricQueryType::Contacts`.
39    pub fn contact_queries_to_prediction(self, other: Self) -> Option<ContactPrediction<N>> {
40        match (self, other) {
41            (
42                GeometricQueryType::Contacts(linear1, angular1),
43                GeometricQueryType::Contacts(linear2, angular2),
44            ) => Some(ContactPrediction::new(
45                linear1 + linear2,
46                angular1,
47                angular2,
48            )),
49            _ => None,
50        }
51    }
52
53    /// Returns `true` if this is a contacts query type.
54    #[inline]
55    pub fn is_contacts_query(&self) -> bool {
56        if let GeometricQueryType::Contacts(..) = *self {
57            true
58        } else {
59            false
60        }
61    }
62
63    /// Returns `true` if this is a proximity query type.
64    #[inline]
65    pub fn is_proximity_query(&self) -> bool {
66        if let GeometricQueryType::Proximity(_) = *self {
67            true
68        } else {
69            false
70        }
71    }
72}