Skip to content

Commit

Permalink
#3635 - simplify findClosestElementFromPoint function
Browse files Browse the repository at this point in the history
  • Loading branch information
chgayane committed Dec 8, 2023
1 parent 38e3320 commit a77c8be
Showing 1 changed file with 1 addition and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,7 @@ export function findLabelPoint(
}

function findClosestElementFromPoint(point): Element {
const elements = document.elementsFromPoint(point.x, point.y);
let closest = elements[0];
let smallestDistance = Infinity;
for (const element of elements) {
const coords = element.getBoundingClientRect();
const distance = Vec2.dist(new Vec2(coords.x, coords.y), new Vec2(point));
if (element.id === 'polymer-editor-canvas') {
continue;
}
if (distance < smallestDistance) {
closest = element;
smallestDistance = distance;
break;
}
}
return closest;
return document.elementsFromPoint(point.x, point.y)[0];
}
export function getSearchFunction(
initialAngle: number,
Expand Down

0 comments on commit a77c8be

Please sign in to comment.