use ffi;
use enums;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct InterpAccel {
pub cache: u64,
pub miss_count: u64,
pub hit_count: u64
}
impl InterpAccel {
pub fn new() -> InterpAccel {
InterpAccel {
cache: 0u64,
miss_count: 0u64,
hit_count: 0u64
}
}
pub fn reset(&mut self) {
self.cache = 0u64;
self.miss_count = 0u64;
self.hit_count = 0u64;
}
pub fn find(&mut self, x_array: &[f64], x: f64) -> u64 {
unsafe { ffi::gsl_interp_accel_find(self, x_array.as_ptr(), x_array.len() as u64, x) }
}
}
pub struct Interp {
interp: *mut ffi::gsl_interp
}
impl Interp {
pub fn new(t: &InterpType, size: u64) -> Option<Interp> {
let tmp = unsafe { ffi::gsl_interp_alloc(t.t, size) };
if tmp.is_null() {
None
} else {
Some(Interp {
interp: tmp
})
}
}
pub fn init(&self, xa: &[f64], ya: &[f64]) -> enums::value::Value {
unsafe { ffi::gsl_interp_init(self.interp, xa.as_ptr(), ya.as_ptr(), xa.len() as u64) }
}
pub fn name(&self) -> String {
let tmp = unsafe { ffi::gsl_interp_name(self.interp) };
if tmp.is_null() {
String::new()
} else {
unsafe { String::from_utf8_lossy(::std::ffi::CStr::from_ptr(tmp).to_bytes()).to_string() }
}
}
pub fn min_size(&self) -> u32 {
unsafe { ffi::gsl_interp_min_size(self.interp) }
}
}
impl Drop for Interp {
fn drop(&mut self) {
unsafe { ffi::gsl_interp_free(self.interp) };
self.interp = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_interp> for Interp {
fn wrap(interp: *mut ffi::gsl_interp) -> Interp {
Interp {
interp: interp
}
}
fn unwrap(interp: &Interp) -> *mut ffi::gsl_interp {
interp.interp
}
}
#[derive(Clone, Copy)]
pub struct InterpType {
t: *const ffi::gsl_interp_type
}
impl InterpType {
pub fn min_size(&self) -> u32 {
unsafe { ffi::gsl_interp_type_min_size(self.t) }
}
pub fn linear() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_linear as *mut ffi::gsl_interp_type)
}
pub fn polynomial() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_polynomial as *mut ffi::gsl_interp_type)
}
pub fn cspline() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_cspline as *mut ffi::gsl_interp_type)
}
pub fn cspline_periodic() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_cspline_periodic as *mut ffi::gsl_interp_type)
}
pub fn akima() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_akima as *mut ffi::gsl_interp_type)
}
pub fn akima_periodic() -> InterpType {
ffi::FFI::wrap(ffi::gsl_interp_akima_periodic as *mut ffi::gsl_interp_type)
}
}
impl ffi::FFI<ffi::gsl_interp_type> for InterpType {
fn wrap(t: *mut ffi::gsl_interp_type) -> InterpType {
InterpType {
t: t
}
}
fn unwrap(t: &InterpType) -> *mut ffi::gsl_interp_type {
t.t as *mut ffi::gsl_interp_type
}
}
pub struct Spline {
spline: *mut ffi::gsl_spline
}
impl Spline {
pub fn new(t: &InterpType, size: u64) -> Option<Spline> {
let tmp = unsafe { ffi::gsl_spline_alloc(t.t, size) };
if tmp.is_null() {
None
} else {
Some(Spline {
spline: tmp
})
}
}
pub fn init(&self, xa: &[f64], ya: &[f64]) -> enums::value::Value {
unsafe { ffi::gsl_spline_init(self.spline, xa.as_ptr(), ya.as_ptr(), xa.len() as u64) }
}
pub fn name(&self) -> String {
let tmp = unsafe { ffi::gsl_spline_name(self.spline) };
if tmp.is_null() {
String::new()
} else {
unsafe { String::from_utf8_lossy(::std::ffi::CStr::from_ptr(tmp).to_bytes()).to_string() }
}
}
pub fn min_size(&self) -> u32 {
unsafe { ffi::gsl_spline_min_size(self.spline) }
}
pub fn eval(&self, x: f64, acc: &mut InterpAccel) -> f64 {
unsafe { ffi::gsl_spline_eval(self.spline, x, acc) }
}
pub fn eval_e(&self, x: f64, acc: &mut InterpAccel, y: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_spline_eval_e(self.spline, x, acc, y) }
}
pub fn eval_deriv(&self, x: f64, acc: &mut InterpAccel) -> f64 {
unsafe { ffi::gsl_spline_eval_deriv(self.spline, x, acc) }
}
pub fn eval_deriv_e(&self, x: f64, acc: &mut InterpAccel, d: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_spline_eval_deriv_e(self.spline, x, acc, d) }
}
pub fn eval_deriv2(&self, x: f64, acc: &mut InterpAccel) -> f64 {
unsafe { ffi::gsl_spline_eval_deriv2(self.spline, x, acc) }
}
pub fn eval_deriv2_e(&self, x: f64, acc: &mut InterpAccel, d2: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_spline_eval_deriv2_e(self.spline, x, acc, d2) }
}
pub fn eval_integ(&self, a: f64, b: f64, acc: &mut InterpAccel) -> f64 {
unsafe { ffi::gsl_spline_eval_integ(self.spline, a, b, acc) }
}
pub fn eval_integ_e(&self, a: f64, b: f64, acc: &mut InterpAccel, result: &mut f64) -> enums::value::Value {
unsafe { ffi::gsl_spline_eval_integ_e(self.spline, a, b, acc, result) }
}
}
impl Drop for Spline {
fn drop(&mut self) {
unsafe { ffi::gsl_spline_free(self.spline) };
self.spline = ::std::ptr::null_mut();
}
}
impl ffi::FFI<ffi::gsl_spline> for Spline {
fn wrap(spline: *mut ffi::gsl_spline) -> Spline {
Spline {
spline: spline
}
}
fn unwrap(spline: &Spline) -> *mut ffi::gsl_spline {
spline.spline
}
}