wrapped2d/collision/
time_of_impact.rs

1use std::mem;
2use std::marker::PhantomData;
3use common::math::Sweep;
4use collision::distance::{Proxy, RawProxy};
5
6#[repr(C)]
7#[doc(hidden)]
8pub struct RawInput {
9    proxy_a: RawProxy,
10    proxy_b: RawProxy,
11    sweep_a: Sweep,
12    sweep_b: Sweep,
13    t_max: f32,
14}
15
16pub struct Input<'a> {
17    raw: RawInput,
18    phantom: PhantomData<&'a ()>,
19}
20
21impl<'a> Input<'a> {
22    pub fn new(proxy_a: Proxy<'a>,
23               proxy_b: Proxy<'a>,
24               sweep_a: Sweep,
25               sweep_b: Sweep,
26               t_max: f32)
27               -> Input<'a> {
28        Input {
29            raw: RawInput {
30                proxy_a: proxy_a.raw,
31                proxy_b: proxy_b.raw,
32                sweep_a: sweep_a,
33                sweep_b: sweep_b,
34                t_max: t_max,
35            },
36            phantom: PhantomData,
37        }
38    }
39
40    pub fn query(&self) -> Output {
41        unsafe {
42            let mut out = mem::zeroed();
43            ffi::time_of_impact(&mut out, &self.raw);
44            out
45        }
46    }
47}
48
49#[repr(C)]
50#[derive(Clone, Copy, PartialEq, Debug)]
51pub enum State {
52    Unknown,
53    Failed,
54    Overlapped,
55    Touching,
56    Separated,
57}
58
59#[repr(C)]
60pub struct Output {
61    pub state: State,
62    pub t: f32,
63}
64
65#[doc(hidden)]
66pub mod ffi {
67    use super::{RawInput, Output};
68
69    extern "C" {
70        pub fn time_of_impact(output: *mut Output, input: *const RawInput);
71    }
72}