use ffi;
use enums;
#[repr(C)]
#[derive(Clone, Copy)]
pub struct InterpAccel {
pub cache: usize,
pub miss_count: usize,
pub hit_count: usize
}
impl InterpAccel {
pub fn new() -> InterpAccel {
InterpAccel {
cache: 0usize,
miss_count: 0usize,
hit_count: 0usize
}
}
pub fn reset(&mut self) {
self.cache = 0usize;
self.miss_count = 0usize;
self.hit_count = 0usize;
}
pub fn find(&mut self, x_array: &[f64], x: f64) -> usize {
unsafe { ffi::gsl_interp_accel_find(self, x_array.as_ptr(), x_array.len() as usize, x) }
}
}
pub struct Interp {
interp: *mut ffi::gsl_interp
}
impl Interp {
pub fn new(t: &InterpType, size: usize) -> 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 {
enums::Value::from(unsafe {
ffi::gsl_interp_init(self.interp, xa.as_ptr(), ya.as_ptr(), xa.len() as usize)
})
}
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 soft_wrap(interp: *mut ffi::gsl_interp) -> Interp {
Self::wrap(interp)
}
fn unwrap_shared(interp: &Interp) -> *const ffi::gsl_interp {
interp.interp as *const _
}
fn unwrap_unique(interp: &mut 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_wrap!(gsl_interp_linear, gsl_interp_type)
}
pub fn polynomial() -> InterpType {
ffi_wrap!(gsl_interp_polynomial, gsl_interp_type)
}
pub fn cspline() -> InterpType {
ffi_wrap!(gsl_interp_cspline, gsl_interp_type)
}
pub fn cspline_periodic() -> InterpType {
ffi_wrap!(gsl_interp_cspline_periodic, gsl_interp_type)
}
pub fn akima() -> InterpType {
ffi_wrap!(gsl_interp_akima, gsl_interp_type)
}
pub fn akima_periodic() -> InterpType {
ffi_wrap!(gsl_interp_akima_periodic, 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 soft_wrap(t: *mut ffi::gsl_interp_type) -> InterpType {
Self::wrap(t)
}
fn unwrap_shared(t: &InterpType) -> *const ffi::gsl_interp_type {
t.t as *const ffi::gsl_interp_type
}
fn unwrap_unique(t: &mut 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: usize) -> 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 {
enums::Value::from(unsafe {
ffi::gsl_spline_init(self.spline, xa.as_ptr(), ya.as_ptr(), xa.len() as usize)
})
}
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 {
enums::Value::from(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 {
enums::Value::from(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 {
enums::Value::from(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 {
enums::Value::from(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 soft_wrap(spline: *mut ffi::gsl_spline) -> Spline {
Self::wrap(spline)
}
fn unwrap_shared(spline: &Spline) -> *const ffi::gsl_spline {
spline.spline as *const _
}
fn unwrap_unique(spline: &mut Spline) -> *mut ffi::gsl_spline {
spline.spline
}
}