Plot: estimate bounds for generator functions

This commit is contained in:
Emil Ernerfeldt 2022-04-19 11:43:04 +02:00
parent cde5f95fc9
commit e82ea0c4b4

View file

@ -264,11 +264,19 @@ impl Values {
} }
pub(super) fn get_bounds(&self) -> PlotBounds { pub(super) fn get_bounds(&self) -> PlotBounds {
let mut bounds = PlotBounds::NOTHING; if self.values.is_empty() {
self.values if let Some(generator) = &self.generator {
.iter() generator.estimate_bounds()
.for_each(|value| bounds.extend_with(value)); } else {
bounds PlotBounds::NOTHING
}
} else {
let mut bounds = PlotBounds::NOTHING;
for value in &self.values {
bounds.extend_with(value);
}
bounds
}
} }
} }
@ -333,6 +341,20 @@ struct ExplicitGenerator {
points: usize, points: usize,
} }
impl ExplicitGenerator {
fn estimate_bounds(&self) -> PlotBounds {
let min_x = *self.x_range.start();
let max_x = *self.x_range.end();
let min_y = (self.function)(min_x);
let max_y = (self.function)(max_x);
// TODO: sample some more points
PlotBounds {
min: [min_x, min_y],
max: [max_x, max_y],
}
}
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
/// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use /// Result of [`super::PlotItem::find_closest()`] search, identifies an element inside the item for immediate use