get rid of hover
This commit is contained in:
parent
a546fe38b7
commit
f436e67368
@ -8,7 +8,6 @@
|
||||
const HEIGHT = 320;
|
||||
|
||||
let userPoint = { x: 5, y: 2 };
|
||||
let trackHover = true;
|
||||
|
||||
// Rectangle coordinates
|
||||
const blueRect = { x1: 6, y1: 1 }; // Blue rectangle corner
|
||||
@ -62,33 +61,16 @@
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function handleMouseMove(event) {
|
||||
if (!trackHover) return;
|
||||
|
||||
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)
|
||||
};
|
||||
}
|
||||
|
||||
function handleCanvasClick(event) {
|
||||
// Update position at click location before toggling tracking
|
||||
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
|
||||
// Snap 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;
|
||||
}
|
||||
|
||||
function toCanvasCoords(x, y) {
|
||||
@ -223,7 +205,7 @@
|
||||
<main>
|
||||
<h1>Line Segment Intersection</h1>
|
||||
<div class="canvas-container">
|
||||
<canvas bind:this={canvas} width={WIDTH} height={HEIGHT} on:mousemove={handleMouseMove} on:click={handleCanvasClick}></canvas>
|
||||
<canvas bind:this={canvas} width={WIDTH} height={HEIGHT} on:click={handleCanvasClick}></canvas>
|
||||
</div>
|
||||
|
||||
<div class="calculations">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user