From 43e782f4c30dbbedc720dd56a5cb83ca91bc54e9 Mon Sep 17 00:00:00 2001 From: Dawn <93628226+DawnTheWitch@users.noreply.github.com> Date: Mon, 16 Oct 2023 20:32:27 -0400 Subject: [PATCH] Bounding Box Bug Fix --- src/AtomMode.ts | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/AtomMode.ts b/src/AtomMode.ts index 5d29e426..1cabe3dc 100644 --- a/src/AtomMode.ts +++ b/src/AtomMode.ts @@ -51,10 +51,7 @@ export function atomMouseDown(event: MouseEvent) { wasOut = false; const currentAtom = new AtomNode( identifier, - new Point( - event.clientX - offset.x, - event.clientY - atomMetrics.fontBoundingBoxDescent - offset.y - ), + new Point(event.clientX - offset.x, event.clientY - offset.y), atomMetrics.width, atomMetrics.fontBoundingBoxDescent + atomMetrics.actualBoundingBoxAscent ); @@ -75,10 +72,7 @@ export function atomMouseDown(event: MouseEvent) { export function atomMouseMove(event: MouseEvent) { const currentAtom = new AtomNode( identifier, - new Point( - event.clientX - offset.x, - event.clientY - atomMetrics.fontBoundingBoxDescent - offset.y - ), + new Point(event.clientX - offset.x, event.clientY - offset.y), atomMetrics.width, atomMetrics.fontBoundingBoxDescent + atomMetrics.actualBoundingBoxAscent ); @@ -101,10 +95,7 @@ export function atomMouseMove(event: MouseEvent) { export function atomMouseUp(event: MouseEvent) { const currentAtom = new AtomNode( identifier, - new Point( - event.clientX - offset.x, - event.clientY - atomMetrics.fontBoundingBoxDescent - offset.y - ), + new Point(event.clientX - offset.x, event.clientY - offset.y), atomMetrics.width, atomMetrics.fontBoundingBoxDescent + atomMetrics.actualBoundingBoxAscent ); @@ -130,7 +121,8 @@ export function atomMouseOut() { * @param color the color of the atom. */ export function drawAtom(thisAtom: AtomNode, color: string) { - atomMetrics = ctx.measureText(identifier); + ctx.textBaseline = "bottom"; + atomMetrics = ctx.measureText(thisAtom.identifier); ctx.fillStyle = color; ctx.strokeStyle = color; ctx.beginPath();