Symptoms • Circle & rectangle tables: dashed “+” seats appear scattered below / to the right of the card body. • Changing Edit Seats count shuffles them, but they never line up around the outline.
All seat‐placement formulas use the wrong base coordinates:
| Shape | Function(s) | What’s wrong |
|---|---|---|
| Circle | createCircleTable and updateTableSeats |
• Radius uses the circle’s full half‑width (100 px) instead ofwidth / 2 − seatRadius ⇒ every seat centre sits on the border; add the seat’s own 20 px radius and it ends up outside. • + 10 margin is incorrectly added to left/top, shifting everything down/right. |
| Rectangle | createRectangleTable and updateTableSeats |
• The computed (x, y) is a point on the rectangle’s border; subtracting only 20 px pushes the seat centre on the edge, so its 40 px body hangs outside. • Extra + 10 margin (update path) shifts seats down/right. |
👉 Add these constants once (top of js/canvas.js and js/drag‑drop.js or a shared helpers.js):
const SEAT_R = 20; // half of .seat 40 px diameterReplace in createCircleTable and in the circle branch of updateTableSeats:
-const radius = width / 2; // old
+const radius = width / 2 - SEAT_R; // new: keep centre inside border
-seat.style.left = (centerX + radius * Math.cos(angle) - 20 + 10) + 'px';
-seat.style.top = (centerY + radius * Math.sin(angle) - 20 + 10) + 'px';
+seat.style.left = (centerX + radius * Math.cos(angle) - SEAT_R) + 'px';
+seat.style.top = (centerY + radius * Math.sin(angle) - SEAT_R) + 'px';Replace in createRectangleTable and in the rectangle branch of updateTableSeats:
-seat.style.left = (x - 20 + 10) + 'px';
-seat.style.top = (y - 20 + 10) + 'px';
+seat.style.left = (x - SEAT_R) + 'px';
+seat.style.top = (y - SEAT_R) + 'px';(No other math changes needed—the (x, y) values already traverse the rectangle perimeter correctly.)
Extract a helper, e.g. function placeSeat(seat, x, y), to avoid duplicating the ‑SEAT_R logic.
- Adding a new circle table with 8 seats shows a perfect octagon of
+seats hugging the border. - Adding a new rectangle table shows seats evenly spaced around all four edges.
- Using Edit Seats (change to 6 → 8 → 10, etc.) never shifts existing seats off‑border.
- No
+ 10magic offsets remain; seat maths uses onlySEAT_R. - Drag‑and‑drop, JSON import/export, and print still function.
Agent hint: Only the four snippets above need patching. Run the test matrix after each file save; visual diff will immediately confirm success.