From ed605fe55bcce74fd03bf47c91c75b76772e8860 Mon Sep 17 00:00:00 2001 From: Mitchell McCaffrey Date: Sat, 13 Feb 2021 10:20:55 +1100 Subject: [PATCH] Added bounding box check to fog edge snapping --- src/helpers/drawing.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/helpers/drawing.js b/src/helpers/drawing.js index 40132e1..d94ccd7 100644 --- a/src/helpers/drawing.js +++ b/src/helpers/drawing.js @@ -484,10 +484,19 @@ export function getSnappingVertex( let closestDistance = Number.MAX_VALUE; let closestPosition; - for (let i = 0; i < shapes.length; i++) { - // TODO: Check bounds before checking all points - // const bounds = boundingBoxes[i]; + // Check bounds before checking all points + const bounds = boundingBoxes[i]; + const offsetMin = Vector2.subtract(bounds.min, gridCellSize); + const offsetMax = Vector2.add(bounds.max, gridCellSize); + if ( + brushPosition.x < offsetMin.x || + brushPosition.x > offsetMax.x || + brushPosition.y < offsetMin.y || + brushPosition.y > offsetMax.y + ) { + continue; + } const shape = shapes[i]; // Include shape points and holes let pointArray = [shape.data.points, ...shape.data.holes];