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
64
65
66
67
68
69
70
71
72
use std::mem;
use std::marker::PhantomData;
use common::math::Sweep;
use collision::distance::{Proxy, RawProxy};

#[repr(C)]
#[doc(hidden)]
pub struct RawInput {
    proxy_a: RawProxy,
    proxy_b: RawProxy,
    sweep_a: Sweep,
    sweep_b: Sweep,
    t_max: f32,
}

pub struct Input<'a> {
    raw: RawInput,
    phantom: PhantomData<&'a ()>,
}

impl<'a> Input<'a> {
    pub fn new(proxy_a: Proxy<'a>,
               proxy_b: Proxy<'a>,
               sweep_a: Sweep,
               sweep_b: Sweep,
               t_max: f32)
               -> Input<'a> {
        Input {
            raw: RawInput {
                proxy_a: proxy_a.raw,
                proxy_b: proxy_b.raw,
                sweep_a: sweep_a,
                sweep_b: sweep_b,
                t_max: t_max,
            },
            phantom: PhantomData,
        }
    }

    pub fn query(&self) -> Output {
        unsafe {
            let mut out = mem::zeroed();
            ffi::time_of_impact(&mut out, &self.raw);
            out
        }
    }
}

#[repr(C)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum State {
    Unknown,
    Failed,
    Overlapped,
    Touching,
    Separated,
}

#[repr(C)]
pub struct Output {
    pub state: State,
    pub t: f32,
}

#[doc(hidden)]
pub mod ffi {
    use super::{RawInput, Output};

    extern "C" {
        pub fn time_of_impact(output: *mut Output, input: *const RawInput);
    }
}