1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use {std};
use {constraint};

use stash::Stash;
use vec_map::VecMap;

pub mod group;
pub use self::group::Group;

#[cfg_attr(feature = "derive_serdes", derive(Serialize, Deserialize))]
#[derive(Clone,Debug,PartialEq)]
pub struct Contact {
  pub constraint : constraint::Planar
}

/// A "TOI contact".
///
/// A pair of objects together with a contact plane and non-negative restitution
/// value.
///
/// A resting contact will have a restitution value of 0.0 and a colliding
/// contact will usually have a positive non-zero restitution value.
///
/// ⚠ Note that the `PartialOrd` and `Ord` implementations are only so
/// that contacts can be sorted in the narrow TOI list. Attempting to compare
/// contacts will always panic.
#[cfg_attr(feature = "derive_serdes", derive(Serialize, Deserialize))]
#[derive(Clone,Debug,PartialEq)]
pub struct Colliding {
  pub contact     : Contact,
  pub restitution : f64
}

// TODO:
/// Persistent contact group manager
#[derive(Clone,Debug,Default)]
pub (crate) struct Manager {
  pub contact_groups        : Stash  <Group>,
  pub object_groups_static  : VecMap <group::KeyType>,
  pub object_groups_dynamic : VecMap <group::KeyType>
}

impl std::ops::Deref for Colliding {
  type Target = Contact;
  fn deref (&self) -> &Contact {
    &self.contact
  }
}
impl Eq for Colliding { }
impl PartialOrd for Colliding {
  /// Panics: should not be called; this trait is implemented so that narrow TOI
  /// results can be automatically be sorted
  fn partial_cmp (&self, _rhs : &Self) -> Option <std::cmp::Ordering> {
    // TODO: compiler hint ?
    unreachable!()
  }
}
impl Ord for Colliding {
  fn cmp (&self, _other : &Self) -> std::cmp::Ordering {
    // TODO: compiler hint ?
    unreachable!()
  }
}