forked from 1b-agent/opencadstudio-upstream
Symptom: open a non-UTM drawing, most lines/polylines/hatches/etc. vanish — only ~5% of indexed entities reachable from a huge query (walking the nodes flat showed all 2975 items present, but recursing through `node.children` from root reached only 161). Root cause: when straddler items piled up at an INTERNAL node and the count exceeded LEAF_CAPACITY, `insert()` re-invoked `split()` on that node. `split()` allocates four fresh children and assigns them to `node.children = Some([...])` — overwriting the existing children pointer and orphaning the entire previous subtree (the descendant nodes still hold their items; nothing reaches them). Splitting an internal node is futile anyway: straddlers don't fit smaller children either. Fix: gate the split on `children.is_none()` so only leaves split. Internal nodes accumulate straddlers as a linear-scan list — slower per-query for big strad- dler counts, but correct. Adds a regression test (`many_straddlers_dont_orphan_subtree`) that floods an internal node with straddlers and verifies a huge query still returns every inserted handle. Bonus: `examples/dump_index_stats.rs` — standalone tool that loads a DWG/DXF and dumps per-type counts (indexed / unbounded / top-level / block-internal) plus a sample of bboxes. Useful for future bug triage; built and ran cleanly against the file that exposed this. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>