why collision keeps two passes

senior grug (level 3 of 6)explanationteaches: adr-corner-tradeoff, adr-pass-orderneeds: paddle-face, wall-face

alreadyYou have read the collision lesson and know the x and y passes.

hereWhy collision stays split into two passes, the alternative rejected in the decision record, and the tradeoff it accepts.

Page: why collision keeps two passes

Job: explanation

Level: senior grug (level 3 of 6)

Source lines:

why grug give these 3 tool notes why grug give the proof why grug give the grill why grug give the why under an answer
explanation

this page says why the code has this shape and what a reader must be careful of.

Three panels read left to right: a ball overlapping a paddle and the top wall in a corner, the paddle pass pushing the ball out along x with the wall overlap still lit, and the wall pass correcting y until the ball rests clear with a moss check
The corner case that decided this: both overlaps lit, x answered, then y answered.

This page teaches the tradeoff behind the two-pass collision order: what a single combined test would have saved, and why the corner case refuses that saving.

why

The decision is written at docs/003-axis-separated-collision.md:3#accepted. A combined rectangle test would have to pick one overlap to fix when a ball meets a paddle and a wall in the same step. The other overlap would survive into the next step, and the correction would undo the first. Two passes give the corner one answer: x first, then y.

The rejected alternative is cheaper to write (one overlaps call, one rule), and the note at docs/003-axis-separated-collision.md:11#winner says what it costs: a combined test picks a winner by code order, so the corner's outcome depends on which if the author happened to write first, and nothing the player can see decides it. A reader chasing a bug that only shows at the corners would be reading an arbitrary rule. The two passes cost more lines and one extra push-out each, and they buy an answer the reader can verify axis by axis: each pass changes one coordinate, so the pair reads as two claims about two axes.

The calls show the order in step. The x move at update.ts:36#xpass runs before the paddle check, and the y move at update.ts:38#ypass runs before the wall check. Each pass changes one coordinate.

Two panels: a court with a torn gap in the right wall where the ball has crossed, a score slip changing from 2 to 3 with the 3 in amber; then the ball resting at the centre above an hourglass marked 24 with a dashed arrow toward the left paddle
Scoring runs after both passes, so a ball saved at the paddle face has left the goal line before the score is read.

what breaks

A single pass that checks both surfaces would need a rule for which correction wins. A corner hit would push the ball back into the paddle or through the floor, and the bug would only show at the edges of the window.

Skipping the push-out leaves the ball inside the paddle at the start of the next step. The guard sees the reversed velocity and lets the ball travel out; a corner hit can spend another step still overlapped. Both passes pay for their push-out.

where it fits

two collision passes, two answers teaches the mechanism at tier 2. This page carries the consequence of the choice. a goal changes one score, then waits runs after both passes, so a saved ball never scores.

try it

Move the paddle into a corner and watch which correction runs first. The proof prints both passes together; the decisive line is update.ts:62#hface.

source anchor: this line is in the file

run grep -n -E 'hface|vface' update.ts

It prints:

62:export function resolve_paddle_hits(game: Game): void { // hface: paddle contact corrects x only
73:export function resolve_wall_hits(game: Game): void { // vface: wall contact corrects y only

The cited file update.ts ships with this site at the same path. Run the command from the school folder, or open update.ts.

reference: every connection to this page
where this fits

This is reference. The next page in the reading order is at the bottom of the page.

learn first: two collision passes, two answers

goes on to: change one rule, follow the result, when this shape stops fitting

flowchart LR
  A0["two collision passes, two answers"]
  H["you are here: why collision keeps two passes"]
  B0["change one rule, follow the result"]
  B1["when this shape stops fitting"]
  A0 --> H
  H --> B0
  H --> B1

this badge records quiz answers with a difficulty from 1 to 6. it does not measure independence or responsibility.

grill: check what you know

Grug asks. Say the answer out loud, then tap. Grug remembers what you miss and asks again in the pop quiz.

the number is a question's difficulty from 1 to 6. a coloured chip marks a question that asks for a change, an effect or a judgment, declared in the quiz row. the rung badge records quiz answers: two right at a level and the levels below it, with a declared transfer question at level 5 or 6. it does not certify independence or responsibility. the questions are level 1 of 6 recall a fact; level 2 of 6 recall a detail; level 3 of 6 trace a path; level 4 of 6 trace a longer path; level 5 of 6 predict or judge; level 6 of 6 judge a transfer.

level 3 of 6Q1 · What does the two-pass decision give a corner hit?

try first, then show answer

2. One correction on each axis

why

The note at docs/003-axis-separated-collision.md:11#winner says a combined test would pick a winner by code order. The two passes answer the x and y questions separately.

level 3 of 6Q2 · Why does each pass push the ball clear?

try first, then show answer

1. To clear the overlap before the next step

why

resolve_paddle_hits at update.ts:62#hface pushes the ball clear in x. resolve_wall_hits at update.ts:73#vface clamps y. Both clear the overlap so the next step sees a new position.

level 5 of 6Q3 · A teammate merges the two passes into one rectangle check. Which failure follows from ADR 003?

try first, then show answer

1. The losing overlap survives and the ball can stick or cross the floor

why

ADR 003 says the losing overlap survives until the next step at docs/003-axis-separated-collision.md:11#winner. A ball left inside the paddle spends the next step travelling out. Scores change later in score_if_out.

level 5 of 6Q4 · A teammate resolves walls before paddles. What does the note say this changes?

try first, then show answer

1. It gives the corner a different winner and can undo the paddle correction

why

step moves in x at update.ts:36#xpass and in y at update.ts:38#ypass. Swapping the corrections gives the corner a different winner, which is the failure the note at docs/003-axis-separated-collision.md:15#enumerate warns about. The serve wait and ball speed are separate concerns.

level 3 of 6Q5 · What does each of the two passes spend on its own correction?

try first, then show answer

2. A push-out that moves the ball clear of the surface it passed

why

resolve_paddle_hits at update.ts:62#hface and resolve_wall_hits at update.ts:73#vface each carry a push-out: the paddle pass writes ball.x clear of the face, the wall pass clamps ball.y to the surface. The overlap each pass corrects is gone before the next step starts.

level 4 of 6Q6 · One combined test fixes the paddle overlap first, then returns. The wall overlap it skipped surfaces where?

try first, then show answer

3. In the next step, where the ball can be pushed back into the paddle or through the floor

why

docs/003-axis-separated-collision.md:11#winner says a combined test picks a winner by code order and the loser stays overlapped until the next step. The next step starts inside the paddle, and the correction there can push the ball back into the paddle or through the floor.