MCPcopy Create free account
hub / github.com/emilk/egui_plot / estimate_bounds

Method estimate_bounds

egui_plot/src/data.rs:202–241  ·  view source on GitHub ↗
(&self)

Source from the content-addressed store, hash-verified

200
201impl ExplicitGenerator<'_> {
202 fn estimate_bounds(&self) -> PlotBounds {
203 let mut bounds = PlotBounds::NOTHING;
204
205 let mut add_x = |x: f64| {
206 // avoid infinities, as we cannot auto-bound on them!
207 if x.is_finite() {
208 bounds.extend_with_x(x);
209 }
210 let y = (self.function)(x);
211 if y.is_finite() {
212 bounds.extend_with_y(y);
213 }
214 };
215
216 let min_x = *self.x_range.start();
217 let max_x = *self.x_range.end();
218
219 add_x(min_x);
220 add_x(max_x);
221
222 if min_x.is_finite() && max_x.is_finite() {
223 // Sample some points in the interval:
224 const N: u32 = 8;
225 for i in 1..N {
226 let t = i as f64 / (N - 1) as f64;
227 let x = lerp(min_x..=max_x, t);
228 add_x(x);
229 }
230 } else {
231 // Try adding some points anyway:
232 for x in [-1, 0, 1] {
233 let x = x as f64;
234 if min_x <= x && x <= max_x {
235 add_x(x);
236 }
237 }
238 }
239
240 bounds
241 }
242}

Callers 1

boundsMethod · 0.80

Calls 3

is_finiteMethod · 0.80
extend_with_xMethod · 0.80
extend_with_yMethod · 0.80

Tested by

no test coverage detected