Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpile all C code to Rust #3

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ description = "Robust predicates for computer geometry"
version = "0.1.4"
authors = ["hporro <[email protected]>"]
edition = "2021"
build = "build.rs"
license = "MIT"
keywords = ["geometry", "math", "robust", "predicates"]
homepage = "https://github.com/hporro/robust-predicates"
repository = "https://github.com/hporro/robust-predicates"

[build-dependencies]
cc = "1.0.66"
11 changes: 0 additions & 11 deletions build.rs

This file was deleted.

23 changes: 7 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,46 +1,37 @@
mod predicates;

use std::sync::Once;

static ALREADY_INIT: Once = Once::new();

mod c_predicates {
#[link(name = "predicates")]
extern "C" {
pub fn exactinit();
pub fn orient2d(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2]) -> f64;
pub fn orient3d(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3]) -> f64;
pub fn incircle(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2], pd: &[f64;2]) -> f64;
pub fn insphere(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3], pe: &[f64;3]) -> f64;
}
}

pub fn exactinit() {
ALREADY_INIT.call_once(|| {
unsafe {
c_predicates::exactinit();
predicates::exactinit();
}
})
}

pub fn orient2d(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2]) -> f64 {
unsafe {
c_predicates::orient2d(pa, pb, pc)
predicates::orient2d(pa.as_ptr(), pb.as_ptr(), pc.as_ptr())
}
}

pub fn orient3d(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3]) -> f64 {
unsafe {
c_predicates::orient3d(pa, pb, pc, pd)
predicates::orient3d(pa.as_ptr(), pb.as_ptr(), pc.as_ptr(), pd.as_ptr())
}
}

pub fn incircle(pa: &[f64;2], pb: &[f64;2], pc: &[f64;2], pd: &[f64;2]) -> f64 {
unsafe {
c_predicates::incircle(pa, pb, pc, pd)
predicates::incircle(pa.as_ptr(), pb.as_ptr(), pc.as_ptr(), pd.as_ptr())
}
}

pub fn insphere(pa: &[f64;3], pb: &[f64;3], pc: &[f64;3], pd: &[f64;3], pe: &[f64;3]) -> f64 {
unsafe {
c_predicates::insphere(pa, pb, pc, pd, pe)
predicates::insphere(pa.as_ptr(), pb.as_ptr(), pc.as_ptr(), pd.as_ptr(), pe.as_ptr())
}
}
Loading