poloto/build/
plotit.rs

1use super::*;
2
3///
4/// Return min max bounds as well as the points of one plot.
5///
6pub trait PlotIt {
7    type L: Point;
8    type It: Iterator<Item = Self::L>;
9    fn unpack(self, area: &mut Area<<Self::L as Point>::X, <Self::L as Point>::Y>) -> Self::It;
10}
11
12#[derive(Copy, Clone)]
13pub struct ClonedPlotIt<I>(I);
14
15impl<L: Point, I: Iterator + Clone> ClonedPlotIt<I>
16where
17    I::Item: build::unwrapper::Unwrapper<Item = L>,
18{
19    pub fn new(it: I) -> Self {
20        Self(it)
21    }
22}
23
24impl<L: Point, I: Iterator + Clone> PlotIt for ClonedPlotIt<I>
25where
26    I::Item: build::unwrapper::Unwrapper<Item = L>,
27{
28    type L = L;
29    type It = build::unwrapper::UnwrapperIter<I>;
30
31    fn unpack(self, area: &mut Area<L::X, L::Y>) -> Self::It {
32        let it = self.0;
33        for k in it.clone() {
34            let l = k.unwrap();
35            let (x, y) = l.get();
36            area.grow(Some(x), Some(y));
37        }
38        build::unwrapper::UnwrapperIter(it)
39    }
40}
41
42impl<L: Point, I: IntoIterator> PlotIt for I
43where
44    I::Item: build::unwrapper::Unwrapper<Item = L>,
45{
46    type L = L;
47    type It = std::vec::IntoIter<L>;
48
49    fn unpack(self, area: &mut Area<L::X, L::Y>) -> Self::It {
50        let it = self.into_iter();
51
52        let vec: Vec<_> = it.map(|j| j.unwrap()).collect();
53
54        for l in vec.iter() {
55            let (x, y) = l.get();
56            area.grow(Some(x), Some(y));
57        }
58
59        vec.into_iter()
60    }
61}