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
use std::convert::TryFrom;

use collision::{proximity, Proximity};

/// Describes the inter-penetration of a pair of bounded objects
#[derive(Clone,Debug,PartialEq)]
pub struct Intersection {
  penetration : Proximity,
  // TODO: include relation information
  //relation    : Relation
}

#[derive(Clone,Copy,Debug,Eq,PartialEq)]
pub enum Relation {
  /// Partial intersection
  Partial,
  AinB,
  BinA
}

impl Intersection {
  #[inline]
  pub fn penetration (&self) -> &Proximity {
    &self.penetration
  }
}
impl TryFrom <Proximity> for Intersection {
  type Error = Proximity;
  fn try_from (proximity : Proximity) -> Result <Self, Proximity> {
    match proximity.relation() {
      proximity::Relation::Intersect
        => Ok (Intersection { penetration: proximity }),
      _ => Err(proximity)
    }
  }
}