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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::marker::PhantomData;
use nalgebra::{Affine2, Point2};
use crate::{extensions::Affine2Ext, iterators::Slicer, Layer};
#[derive(Debug, Clone, Copy)]
pub struct Positioned<'a, L, T, S>
where
L: Layer,
S: Slicer<'a, L, T>,
{
slicer: S,
layer: L,
to_parent: Affine2<f64>,
_phantom: PhantomData<(L, &'a T)>,
}
impl<'a, L, T, S> Positioned<'a, L, T, S>
where
L: Layer,
S: Slicer<'a, L, T>,
{
pub(crate) fn new(slicer: S, layer: L, to_parent: Affine2<f64>) -> Self {
Self {
slicer,
layer,
to_parent,
_phantom: PhantomData,
}
}
}
impl<'a, L, T, S> Slicer<'a, L, T> for Positioned<'a, L, T, S>
where
L: Layer,
S: Slicer<'a, L, T>,
{
type Output = ((L, Point2<f64>), S::Output);
type OutputMut = ((L, Point2<f64>), S::OutputMut);
fn slice(&self, data: &'a ndarray::Array2<T>) -> Option<Self::Output> {
let item = self.slicer.slice(data)?;
let index = self.slicer.index()?;
Some(((self.layer.clone(), self.to_parent.position(index)), item))
}
fn slice_mut(&self, data: &'a mut ndarray::Array2<T>) -> Option<Self::OutputMut> {
let item = self.slicer.slice_mut(data)?;
let index = self.slicer.index()?;
Some(((self.layer.clone(), self.to_parent.position(index)), item))
}
fn advance(&mut self) {
self.slicer.advance()
}
fn index(&self) -> Option<nalgebra::Point2<usize>> {
self.slicer.index()
}
fn reset(&mut self, layer: Option<L>) {
if let Some(ref l) = layer {
self.layer = l.clone()
}
self.slicer.reset(layer)
}
}