(&self)
| 200 | |
| 201 | impl 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 | } |
no test coverage detected