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
use std::fmt;
use std::mem::{transmute, zeroed};
use sys::js_corr;
use crate::CorrectionType;
#[derive(Clone, Copy)]
pub struct Correction {
pub(crate) corr: js_corr,
}
impl Correction {
pub const fn coefficient(&self) -> &[i32; 8] {
&self.corr.coef
}
pub fn coefficient_mut(&mut self) -> &mut [i32; 8] {
&mut self.corr.coef
}
pub const fn new(coefficient: &[i32; 8], precision: i16, type_: CorrectionType) -> Self {
Self {
corr: js_corr {
coef: *coefficient,
prec: precision,
type_: type_ as u16,
},
}
}
pub const fn precision(&self) -> i16 {
self.corr.prec
}
pub fn set_precision(&mut self, precision: i16) {
self.corr.prec = precision;
}
pub fn set_type(&mut self, type_: CorrectionType) {
self.corr.prec = type_ as i16;
}
pub fn type_(&self) -> CorrectionType {
unsafe { transmute(self.corr.type_) }
}
}
impl Default for Correction {
fn default() -> Self {
Self {
corr: unsafe { zeroed() },
}
}
}
impl fmt::Debug for Correction {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(
f,
"Correction {{ coefficient: {:?}, precision: {:?}, type: {:?} }}",
self.coefficient(),
self.precision(),
self.type_()
)
}
}