# Dispatch Assignment: Explorer M2 Fix 2 (Frustum Culling & Edge Cases)

**Assigned Agent:** `explorer_m2_fix_2`  
**Role:** Frustum Culling & Edge Cases Explorer  
**Working Directory:** `c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_2`  
**Project Scope:** `c:\Projects\FreeExile\.agents\teamwork\orchestrator_11\PROJECT.md`  
**Authoritative Request:** `c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md` (specifically section `## 2026-10-01T19:19:13Z` - R2)  

## Previous Failure Output & Feedback
Reviewer M2-2 and Challenger M2-1 reported:
- In `tile_map_renderer.js:150–152`, rectangular canvas AABB culling:
  `if (destX + 1024 < 0 || destX > vpW || destY + 512 < 0 || destY > vpH) continue;`
  tests the rectangular canvas bounding box ($1024 \times 512$) rather than the isometric diamond of actual tiles.
- Because the diamond only fills the center of the $1024 \times 512$ canvas (empty transparent corners), chunks whose empty corners touch the screen are considered visible and blitted, adding 2–3 phantom draw calls and needlessly evicting active chunks!
- Minor bug: `const vpW = (viewport && viewport.clientWidth) || 390;` treats `0` as falsy, rendering a fallback frame when viewport is 0x0.

## Mission
Investigate and design tight isometric diamond culling:
1. Formulate a tight intersection test between the chunk's actual diamond tile area and the viewport rectangle $[0, vpW] \times [0, vpH]$:
   - What is the condition for a tile $(tx, ty)$ or diamond chunk $[minTx, maxTx] \times [minTy, maxTy]$ to intersect the screen?
   - How can we eliminate phantom chunks whose empty corners touch the canvas AABB but have no visible tiles?
2. Fix edge cases:
   - When `viewport.clientWidth === 0 || viewport.clientHeight === 0`, return early immediately without performing any draw calls or chunk lookups.
   - Clean handling of negative camera coordinates, `NaN`, and extreme pans.
3. Coordinate with `explorer_m2_fix_1`'s chunk size recommendations ($8 \times 8$ or $16 \times 16$) to provide the exact culling code snippet for Worker M2.

Write report.md and handoff.md in your directory and notify parent when complete.

## 2026-10-01T20:26:41Z
You are Frustum Culling & Edge Cases Explorer.
Your working directory is: c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_2
Your dispatch assignment is: c:\Projects\FreeExile\.agents\teamwork\explorer_m2_fix_2\DISPATCH.md
MANDATORY: Read the authoritative user request at:
c:\Projects\FreeExile\.agents\teamwork\ORIGINAL_REQUEST.md (specifically section ## 2026-10-01T19:19:13Z - R2).
Also consult c:\Projects\FreeExile\.agents\teamwork\reviewer_m2_2\handoff.md and c:\Projects\FreeExile\.agents\teamwork\challenger_m2_1\handoff.md.

Analyze frustum diamond culling math and edge cases:
1. Formulate tight diamond polygon culling to eliminate phantom chunk draw calls.
2. Fix 0x0 viewport early exit.
3. Handle negative coords, extreme pans, and NaN.

Write report.md and handoff.md in your directory and notify parent when complete.
