Commit b742fc99 authored by Mahmoud Aglan's avatar Mahmoud Aglan

fix: domino endpoint hit radius increased + only check active endpoints

- Snap radius 45→60 for easier endpoint tapping
- hitTestEndpoints only checks currently active (highlighted) endpoints
- Empty board returns hit on any canvas tap when endpoint is active
- Simplified pointerdown handler (no early endpoint intercept)
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 7ef3695b
......@@ -118,6 +118,8 @@ export class DominoBoard {
}
hitTestEndpoints(screenX, screenY) {
if (!this.activeEndpoint) return null;
const rect = this.canvas.getBoundingClientRect();
const canvasX = (screenX - rect.left) * (this.width / rect.width);
const canvasY = (screenY - rect.top) * (this.height / rect.height);
......@@ -130,15 +132,23 @@ export class DominoBoard {
const leftEp = this.layout.endpoints.left;
const rightEp = this.layout.endpoints.right;
const radius = getSnapRadius() / this.zoom;
const radius = getSnapRadius();
// Empty board: tap anywhere = center placement
if (!leftEp && !rightEp && this.activeEndpoint) {
// Empty board: tap anywhere on canvas = center placement
if (!leftEp && !rightEp) {
return { end: 'right', value: null };
}
if (leftEp && dist(worldX, worldY, leftEp.x, leftEp.y) < radius) return { end: 'left', value: leftEp.value };
if (rightEp && dist(worldX, worldY, rightEp.x, rightEp.y) < radius) return { end: 'right', value: rightEp.value };
// Check which endpoints are active
const checkLeft = this.activeEndpoint === 'left' || this.activeEndpoint === 'both';
const checkRight = this.activeEndpoint === 'right' || this.activeEndpoint === 'both';
if (checkLeft && leftEp && dist(worldX, worldY, leftEp.x, leftEp.y) < radius) {
return { end: 'left', value: leftEp.value };
}
if (checkRight && rightEp && dist(worldX, worldY, rightEp.x, rightEp.y) < radius) {
return { end: 'right', value: rightEp.value };
}
return null;
}
......@@ -274,14 +284,6 @@ export class DominoBoard {
let lastPanX = 0, lastPanY = 0;
this.canvas.addEventListener('pointerdown', (e) => {
// Check endpoint tap first
if (this.activeEndpoint && this.onEndpointTap) {
const hit = this.hitTestEndpoints(e.clientX, e.clientY);
if (hit) {
this.onEndpointTap(hit);
return;
}
}
startX = e.clientX;
startY = e.clientY;
lastPanX = this.pan.x;
......
......@@ -155,7 +155,7 @@ function getEndpoint(tiles, chain, side) {
return { x: ex, y: ey, value: endValue, end: side };
}
export function getSnapRadius() { return 45; }
export function getSnapRadius() { return 60; }
export function hitTestEndpoint(px, py, endpoint) {
if (!endpoint) return false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment