mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Plot: estimate bounds for generator functions
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user