-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathutil.rs
More file actions
121 lines (106 loc) · 3.47 KB
/
util.rs
File metadata and controls
121 lines (106 loc) · 3.47 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use crate::{
primitives::{BandSelection, BandSelectionIter},
raster::{GridBoundingBox2D, GridIdx2D, GridIdx2DIter, TileInformation, TileInformationIter},
};
#[derive(Clone, Debug)]
pub struct TileIdxBandCrossProductIter {
tile_iter: GridIdx2DIter,
band_iter: BandSelectionIter, // TODO: maybe change this to actual attributes from ResultDescriptor not the Selection?
current_tile: Option<GridIdx2D>,
}
impl TileIdxBandCrossProductIter {
pub fn new(tile_iter: GridIdx2DIter, band_iter: BandSelectionIter) -> Self {
let mut tile_iter = tile_iter;
let current_tile = tile_iter.next();
Self {
tile_iter,
band_iter,
current_tile,
}
}
pub fn grid_bounds(&self) -> GridBoundingBox2D {
self.tile_iter.grid_bounds
}
pub fn band_selection(&self) -> &BandSelection {
&self.band_iter.band_selection
}
pub fn with_grid_bounds_and_selection(
bounds: GridBoundingBox2D,
band_selection: BandSelection,
) -> Self {
let tile_iter = GridIdx2DIter::new(&bounds);
let band_iter = BandSelectionIter::new(band_selection);
Self::new(tile_iter, band_iter)
}
pub fn reset(&mut self) {
self.band_iter.reset();
self.tile_iter.reset();
self.current_tile = self.tile_iter.next();
}
}
impl Iterator for TileIdxBandCrossProductIter {
type Item = (GridIdx2D, u32);
fn next(&mut self) -> Option<Self::Item> {
let current_t = self.current_tile;
match (current_t, self.band_iter.next()) {
(None, _) => None,
(Some(t), Some(b)) => Some((t, b)),
(Some(_t), None) => {
self.band_iter.reset();
self.current_tile = self.tile_iter.next();
self.current_tile.map(|t| {
(
t,
self.band_iter
.next()
.expect("There must be at least one band"),
)
})
}
}
}
}
#[derive(Clone, Debug)]
pub struct TileInformationBandCrossProductIter {
tile_iter: TileInformationIter,
band_iter: BandSelectionIter,
current_tile: Option<TileInformation>,
}
impl TileInformationBandCrossProductIter {
pub fn new(tile_iter: TileInformationIter, band_iter: BandSelectionIter) -> Self {
let mut tile_iter = tile_iter;
let current_tile = tile_iter.next();
Self {
tile_iter,
band_iter,
current_tile,
}
}
pub fn reset(&mut self) {
self.band_iter.reset();
self.tile_iter.reset();
self.current_tile = self.tile_iter.next();
}
}
impl Iterator for TileInformationBandCrossProductIter {
type Item = (TileInformation, u32);
fn next(&mut self) -> Option<Self::Item> {
let current_t = self.current_tile;
match (current_t, self.band_iter.next()) {
(None, _) => None,
(Some(t), Some(b)) => Some((t, b)),
(Some(_t), None) => {
self.band_iter.reset();
self.current_tile = self.tile_iter.next();
self.current_tile.map(|t| {
(
t,
self.band_iter
.next()
.expect("There must be at least one band"),
)
})
}
}
}
}