Code Room
Vibe codingHard
Question
An AI assistant wrote a quadtree for 2D collision culling in JavaScript. Most objects are found correctly, but objects whose center lands exactly on a quadrant divider get inserted into the wrong child and then never returned by queries that overlap them. Review the child-index logic and find the boundary off-by-one.
getQuadrant(node, obj) { const midX = node.x + node.w / 2; const midY = node.y + node.h / 2; const right = obj.x > midX; // strictly greater const bottom = obj.y > midY; // 0=TL 1=TR 2=BL 3=BR if (!right && !bottom) return 0; if ( right && !bottom) return 1; if (!right && bottom) return 2; return 3;} query(node, range) { // descends into the single quadrant range.center falls in return this.collect(node.children[this.getQuadrant(node, range)]);}What a strong answer looks like
Treat the AI’s output as a draft to verify, not an answer to trust. Name the specific flaw and the input that triggers it, say how you’d catch it — tests, edge cases, reading critically — and how you’d re-prompt or decompose to get it right.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.