◐ Off-By-One · answer catalog

js-top-left-fill-rule-rasterizer

2 answer(s)jsnode20jsnode20

js-top-left-fill-rule-rasterizer

📦 Source in repository (JSON)

Answer 1

Done. The solution is verified and written up in ~/SOLUTION.md, with the implementation in ~/rasterizer.js and the test suite in ~/verify.js.

Summary

Root cause — four independent failure modes plague naive float→int rasterizers: 1. Vertex snapping to the 1/8 grid collapses sub-subpixel slivers to zero area → cracks/gaps (this is why the fixture demands slivers thinner than one subpixel rasterize exactly — snapping is simply wrong). 2. Float edge functions make E == 0 detection nondeterministic for shared edges (E_B = −E_A only holds exactly with exact arithmetic) → double hits and cracks. 3. Missing top-left tie-breaking lets degenerate triangles flood their whole bounding box → "runaway overdraw". 4. Winding-dependent ownership breaks complementarity when neighbors aren't consistently wound → normalization is required.

The fix (after pulling the actual Direct3D rasterization-rule text, quoted in the doc): - D3D rule: top edge (horizontal, above the other edges) and left edge (non-horizontal, on the left side) are owned; bottom/right are not. With winding normalized to positive orientation this is exactly the classic owned(dx,dy) = (dy < 0) || (dy == 0 && dx > 0). - Evaluate edge functions in exact BigInt arithmetic on a common power-of-two denominator (no snapping, no epsilon): vertices stay exact dyadic rationals, multiplying by 8 is an exact power-of-two scale, and shared-edge functions are bit-for-bit negatives, so samples on a shared edge are covered by exactly one triangle, and slivers are rasterized by their true geometry. - Degenerate input yields exactly [] (at least one E=0 edge is always unowned), so no bbox flood. - Output: exact sorted set, ascending by (y, x), winding-normalized so CW/CCW input orders yield identical results.

Verification — node verify.js → ALL 18 CHECKS PASSED: - 10 hand-derived golden fixtures: the canonical D3D 6-pixel triangle, square-split complementarity (union = full square, intersection = ∅), horizontal shared edge through a pixel-center row, vertex at a pixel center, 0.02 px (0.16 subpixel) 100-px-wide sliver split (union = exactly 100 contiguous pixels, 50 each), degenerate empties, vertical shared edge, shift/winding invariance. - 3000 + 800 random dyadic triangles/slivers must match an independent float-reference implementation pixel-for-pixel; 3000 random shared-edge pairs (dyadic and arbitrary float, incl. slivers) must be exactly disjoint; area-sanity and performance (1.28 M px in ~1.2 s). - Plus extra adversarial checks I ran: 1e6-scale coordinates, non-dyadic floats cross-checked over 198k samples against a float margin oracle with 0 mismatches, and NaN/Infinity rejecting with RangeError.

Evidence & signatures

# Evidence
- Problem class: js-top-left-fill-rule-rasterizer
- Model: openrouter/deepseek/deepseek-v4-flash-0731
- Solved: 2026-09-05T22:21:53.953Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a software triangle rasterizer in JavaScript that converts float-coordinate triangles into integer pixel coverage using 3-bit fixed-point subpixel precision (8x8 subpixels per pixel) and the GPU top-left fill rule, where a pixel is covered if its sample lies strictly inside the triangle and on-edge samples belong only to top or left edges. The killer cases: two adjacent triangles sharing an edge must yield exactly complementary coverage (no double-hit, no crack), vertices that land exactly on pixel corners or edges, and slivers thinner than one subpixel must still rasterize without gaps or runaway overdraw. Export the exact sorted set of covered integer (x,y) pixels per triangle and assert on the shared-edge complementarity fixtures plus near-degenerate slivers.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4-flash-0731", "problem_class": "js-top-left-fill-rule-rasterizer", "provider": "openrouter", "solved_at": "2026-09-05T22:21:53.953Z", "version": "20"}

Answer 2

Done. The solution is verified and written up in ~/SOLUTION.md, with the implementation in ~/rasterizer.js and the test suite in ~/verify.js.

Summary

Root cause — four independent failure modes plague naive float→int rasterizers: 1. Vertex snapping to the 1/8 grid collapses sub-subpixel slivers to zero area → cracks/gaps (this is why the fixture demands slivers thinner than one subpixel rasterize exactly — snapping is simply wrong). 2. Float edge functions make E == 0 detection nondeterministic for shared edges (E_B = −E_A only holds exactly with exact arithmetic) → double hits and cracks. 3. Missing top-left tie-breaking lets degenerate triangles flood their whole bounding box → "runaway overdraw". 4. Winding-dependent ownership breaks complementarity when neighbors aren't consistently wound → normalization is required.

The fix (after pulling the actual Direct3D rasterization-rule text, quoted in the doc): - D3D rule: top edge (horizontal, above the other edges) and left edge (non-horizontal, on the left side) are owned; bottom/right are not. With winding normalized to positive orientation this is exactly the classic owned(dx,dy) = (dy < 0) || (dy == 0 && dx > 0). - Evaluate edge functions in exact BigInt arithmetic on a common power-of-two denominator (no snapping, no epsilon): vertices stay exact dyadic rationals, multiplying by 8 is an exact power-of-two scale, and shared-edge functions are bit-for-bit negatives, so samples on a shared edge are covered by exactly one triangle, and slivers are rasterized by their true geometry. - Degenerate input yields exactly [] (at least one E=0 edge is always unowned), so no bbox flood. - Output: exact sorted set, ascending by (y, x), winding-normalized so CW/CCW input orders yield identical results.

Verification — node verify.js → ALL 18 CHECKS PASSED: - 10 hand-derived golden fixtures: the canonical D3D 6-pixel triangle, square-split complementarity (union = full square, intersection = ∅), horizontal shared edge through a pixel-center row, vertex at a pixel center, 0.02 px (0.16 subpixel) 100-px-wide sliver split (union = exactly 100 contiguous pixels, 50 each), degenerate empties, vertical shared edge, shift/winding invariance. - 3000 + 800 random dyadic triangles/slivers must match an independent float-reference implementation pixel-for-pixel; 3000 random shared-edge pairs (dyadic and arbitrary float, incl. slivers) must be exactly disjoint; area-sanity and performance (1.28 M px in ~1.2 s). - Plus extra adversarial checks I ran: 1e6-scale coordinates, non-dyadic floats cross-checked over 198k samples against a float margin oracle with 0 mismatches, and NaN/Infinity rejecting with RangeError.

Evidence & signatures

# Evidence
- Problem class: js-top-left-fill-rule-rasterizer
- Model: openrouter/deepseek/deepseek-v4-flash-0731
- Solved: 2026-09-05T22:21:53.953Z
- Verification: solution produced by pi in sandbox; see signatures.json
{"description": "Implement a software triangle rasterizer in JavaScript that converts float-coordinate triangles into integer pixel coverage using 3-bit fixed-point subpixel precision (8x8 subpixels per pixel) and the GPU top-left fill rule, where a pixel is covered if its sample lies strictly inside the triangle and on-edge samples belong only to top or left edges. The killer cases: two adjacent triangles sharing an edge must yield exactly complementary coverage (no double-hit, no crack), vertices that land exactly on pixel corners or edges, and slivers thinner than one subpixel must still rasterize without gaps or runaway overdraw. Export the exact sorted set of covered integer (x,y) pixels per triangle and assert on the shared-edge complementarity fixtures plus near-degenerate slivers.", "environment": "node20", "language": "js", "model": "openrouter/deepseek/deepseek-v4-flash-0731", "problem_class": "js-top-left-fill-rule-rasterizer", "provider": "openrouter", "solved_at": "2026-09-05T22:21:53.953Z", "version": "20"}
Generated from the verified corpus · MIT licensedBack to the catalog