From 323a767abc09922240059d624b2561cc8985ae62 Mon Sep 17 00:00:00 2001 From: Adam Jeniski Date: Fri, 2 Jan 2026 11:52:20 -0500 Subject: [PATCH] update point B position on click before freezing tracking --- line-segment-intersection/src/App.svelte | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/line-segment-intersection/src/App.svelte b/line-segment-intersection/src/App.svelte index 08f237e..e1bc327 100644 --- a/line-segment-intersection/src/App.svelte +++ b/line-segment-intersection/src/App.svelte @@ -76,7 +76,20 @@ }; } - function handleCanvasClick() { + function handleCanvasClick(event) { + // If we're about to turn off tracking, update position one last time + if (trackHover) { + const rect = canvas.getBoundingClientRect(); + const mouseX = event.clientX - rect.left; + const mouseY = event.clientY - rect.top; + + // Add half grid unit offset for snapping to closest grid intersection + userPoint = { + x: Math.floor((mouseX + GRID_SIZE / 2) / GRID_SIZE), + y: Math.floor((HEIGHT - mouseY + GRID_SIZE / 2) / GRID_SIZE) + }; + } + trackHover = !trackHover; }