Inverse-CDF inversion: returns the largest index i such that `cdf[i] <= u`. Used for both marginal and conditional sampling.
(cdf: &[f32], u: f32)
| 1482 | /// Inverse-CDF inversion: returns the largest index i such that |
| 1483 | /// `cdf[i] <= u`. Used for both marginal and conditional sampling. |
| 1484 | fn upper_bound_index(cdf: &[f32], u: f32) -> usize { |
| 1485 | // Binary search for the last index whose CDF value is <= u. |
| 1486 | let mut lo = 0usize; |
| 1487 | let mut hi = cdf.len(); |
| 1488 | while lo < hi { |
| 1489 | let mid = (lo + hi) / 2; |
| 1490 | if cdf[mid] <= u { |
| 1491 | lo = mid + 1; |
| 1492 | } else { |
| 1493 | hi = mid; |
| 1494 | } |
| 1495 | } |
| 1496 | if lo == 0 { |
| 1497 | 0 |
| 1498 | } else { |
| 1499 | lo - 1 |
| 1500 | } |
| 1501 | } |
| 1502 | |
| 1503 | impl Environment { |
| 1504 | fn load_hdr(path: &Path, intensity: f32) -> Result<Self, String> { |