Plot: estimate bounds for generator functions
This commit is contained in:
parent
cde5f95fc9
commit
e82ea0c4b4
1 changed files with 27 additions and 5 deletions
|
@ -264,11 +264,19 @@ impl Values {
|
|||
}
|
||||
|
||||
pub(super) fn get_bounds(&self) -> PlotBounds {
|
||||
let mut bounds = PlotBounds::NOTHING;
|
||||
self.values
|
||||
.iter()
|
||||
.for_each(|value| bounds.extend_with(value));
|
||||
bounds
|
||||
if self.values.is_empty() {
|
||||
if let Some(generator) = &self.generator {
|
||||
generator.estimate_bounds()
|
||||
} else {
|
||||
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,
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue