clay/map/
linear.rs

1use std::collections::HashSet;
2use nalgebra::{Matrix3};
3use crate::{prelude::*, map::*};
4
5
6/// Linear transformation represented by a matrix.
7pub struct Linear(pub Matrix3<f64>);
8
9impl From<Matrix3<f64>> for Linear {
10    fn from(x: Matrix3<f64>) -> Self {
11        Linear(x)
12    }
13}
14
15impl Map for Linear {}
16
17impl Instance<MapClass> for Linear {
18    fn source(_: &mut HashSet<u64>) -> String {
19        "#include <clay/map/linear.h>".to_string()
20    }
21    fn inst_name() -> String {
22        "linear".to_string()
23    }
24}
25
26impl Pack for Linear {
27    fn size_int() -> usize {
28        2*Matrix3::<f64>::size_int()
29    }
30    fn size_float() -> usize {
31        2*Matrix3::<f64>::size_float()
32    }
33    fn pack_to(&self, buffer_int: &mut [i32], buffer_float: &mut [f32]) {
34        let inverse = self.0.try_inverse().unwrap();
35        Packer::new(buffer_int, buffer_float)
36        .pack(&self.0)
37        .pack(&inverse);
38    }
39}