From 77c39a8dd6830f7634bbc7b260caf9744c4673d1 Mon Sep 17 00:00:00 2001 From: Morion Date: Wed, 18 Nov 2026 11:50:53 -0500 Subject: [PATCH] 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). --- crates/compose/src/pattern.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/compose/src/pattern.rs b/crates/compose/src/pattern.rs index 5c0abb83..fa4d92fa 100644 --- a/crates/compose/src/pattern.rs +++ b/crates/compose/src/pattern.rs @@ -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 = [