export * from './hull.js'; import { makeHull } from './hull.js'; export function getPointsFromEl(el) { const rect = el.getBoundingClientRect(); return [ { x: rect.left, y: rect.top }, { x: rect.right, y: rect.top }, { x: rect.right, y: rect.bottom }, { x: rect.left, y: rect.bottom }, ]; } export function makeHullFromElements(els) { const points = els.flatMap((el) => getPointsFromEl(el)); return makeHull(points); } export function pointInPolygon(point, polygon) { let inside = false; for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) { const xi = polygon[i].x; const yi = polygon[i].y; const xj = polygon[j].x; const yj = polygon[j].y; const intersect = yi > point.y !== yj > point.y && point.x < ((xj - xi) * (point.y - yi)) / (yj - yi) + xi; if (intersect) inside = !inside; } return inside; }