1use std::sync::Once;
2
3static ALREADY_INIT: Once = Once::new();
4
5mod c_predicates {
6 #[link(name = "predicates")]
7 extern "C" {
8 pub fn exactinit();
9 pub fn orient2d(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2]) -> f64;
10 pub fn orient3d(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3]) -> f64;
11 pub fn incircle(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2], pd: &[f64;2]) -> f64;
12 pub fn insphere(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3], pe: &[f64;3]) -> f64;
13 }
14}
15
16pub fn exactinit() {
17 ALREADY_INIT.call_once(|| {
18 unsafe {
19 c_predicates::exactinit();
20 }
21 })
22}
23
24pub fn orient2d(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2]) -> f64 {
25 unsafe {
26 c_predicates::orient2d(pa, pb, pc)
27 }
28}
29
30pub fn orient3d(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3]) -> f64 {
31 unsafe {
32 c_predicates::orient3d(pa, pb, pc, pd)
33 }
34}
35
36pub fn incircle(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2], pd: &[f64;2]) -> f64 {
37 unsafe {
38 c_predicates::incircle(pa, pb, pc, pd)
39 }
40}
41
42pub fn insphere(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3], pe: &[f64;3]) -> f64 {
43 unsafe {
44 c_predicates::insphere(pa, pb, pc, pd, pe)
45 }
46}