35 lines
741 B
Rust
35 lines
741 B
Rust
|
|
|
|
pub struct CellAxis {
|
|
min: f32,
|
|
max: f32,
|
|
num: u32,
|
|
idx: u32
|
|
}
|
|
|
|
impl CellAxis {
|
|
pub fn new(min: f32, len: f32, num: u32) -> Self {
|
|
Self {
|
|
min,
|
|
max: min + len,
|
|
num,
|
|
idx: 0
|
|
}
|
|
}
|
|
}
|
|
|
|
impl Iterator for CellAxis {
|
|
type Item = (f32, f32);
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
if self.idx < self.num {
|
|
let beg: f32 = self.min + ((self.max - self.min) * self.idx as f32) / self.num as f32;
|
|
let end: f32 = self.min + ((self.max - self.min) * (self.idx + 1) as f32) / self.num as f32;
|
|
self.idx += 1;
|
|
|
|
return Some((beg.trunc(), end.trunc()));
|
|
}
|
|
return None;
|
|
}
|
|
}
|