Read a pattern exactly when its coarse grid coordinate is not finite

plane_value blended four samples of a coarse grid, and a point so far out that the grid overflowed made the blend NaN although the pattern itself was finite there. It now reads the exact point in that case. The test checks every procedural at the extreme coordinates and fails without the fix (Cells at infinity gave NaN).
This commit is contained in:
Morion committed 2026-11-18 11:50:53 -05:00
1 parent 8e7bc663fd
commit 77c39a8dd6
1 file changed
+22
+22
View File
@@ -484,6 +484,11 @@ fn plane_value(pattern: &Procedural, point: Vec3, context: &PatternContext) -> f
let Some(cells) = cells else { return pattern_value(pattern, point, context) };
let grid = point.truncate() * cells - 0.5;
// A point so far out that the grid overflows has no neighbours to blend: read it exactly
if !grid.is_finite() {
return pattern_value(pattern, point, context);
}
let base = grid.floor();
let fraction = grid - base;
let at = |dx: f32, dy: f32| pattern_value(pattern, ((base + Vec2::new(dx, dy) + 0.5) / cells).extend(point.z), context);
@@ -862,6 +867,23 @@ mod tests {
}
}
#[test]
fn a_pattern_read_from_a_coarse_image_takes_extreme_coordinates() {
let coarse = PatternContext { pixels: Some(4), ..PatternContext::default() };
let exact = PatternContext::default();
for kind in ProceduralKind::ALL {
let pattern = Procedural::new(kind);
for x in [f32::MAX, -f32::MAX, f32::INFINITY, f32::NEG_INFINITY] {
let point = Vec3::new(x, 0.125, 0.0);
// Whatever a pattern does with such a point exactly, the blend must not make it worse
if pattern_value(&pattern, point, &exact).is_finite() {
let value = plane_value(&pattern, point, &coarse);
assert!(value.is_finite(), "{kind:?} at x = {x}: {value}");
}
}
}
}
#[test]
fn geometric_tilings_take_extreme_coordinates() {
let tilings = [