1use crate::Real;
4
5#[derive(Debug, Clone)]
8pub struct ImageField {
9 pub data: Vec<Real>,
10 pub width: usize,
11 pub height: usize,
12}
13
14impl ImageField {
15 pub fn new(data: Vec<Real>, width: usize, height: usize) -> Self {
16 assert_eq!(
17 data.len(),
18 width * height,
19 "data length must equal width * height"
20 );
21 Self {
22 data,
23 width,
24 height,
25 }
26 }
27
28 pub fn zeros(width: usize, height: usize) -> Self {
29 Self {
30 data: vec![0.0; width * height],
31 width,
32 height,
33 }
34 }
35
36 #[inline]
38 pub fn get(&self, row: usize, col: usize) -> Real {
39 self.data[row * self.width + col]
40 }
41
42 #[inline]
44 pub fn get_mut(&mut self, row: usize, col: usize) -> &mut Real {
45 &mut self.data[row * self.width + col]
46 }
47}