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,13 +264,21 @@ impl Values {
}
pub(super) fn get_bounds(&self) -> PlotBounds {
if self.values.is_empty() {
if let Some(generator) = &self.generator {
generator.estimate_bounds()
} else {
PlotBounds::NOTHING
}
} else {
let mut bounds = PlotBounds::NOTHING;
self.values
.iter()
.for_each(|value| bounds.extend_with(value));
for value in &self.values {
bounds.extend_with(value);
}
bounds
}
}
}
// ----------------------------------------------------------------------------
@ -333,6 +341,20 @@ struct ExplicitGenerator {
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