@hkdigital/lib-sveltekit 0.1.76 → 0.1.77

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Check if a point lies within a polygon
3
+ *
4
+ * @param {number} xPct - X-coordinate as percentage
5
+ * @param {number} yPct - Y-coordinate as percentage
6
+ * @param {Array} polygon - Array of [x, y] points
7
+ *
8
+ * @returns {boolean} True if the point lies within the polygon
9
+ */
10
+ export function isPointInPolygon(xPct, yPct, polygon) {
11
+ let inside = false;
12
+ for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
13
+ const xi = polygon[i][0];
14
+ const yi = polygon[i][1];
15
+ const xj = polygon[j][0];
16
+ const yj = polygon[j][1];
17
+
18
+ const intersect =
19
+ yi > yPct !== yj > yPct &&
20
+ xPct < ((xj - xi) * (yPct - yi)) / (yj - yi) + xi;
21
+ if (intersect) {
22
+ inside = !inside;
23
+ }
24
+ }
25
+ return inside;
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hkdigital/lib-sveltekit",
3
- "version": "0.1.76",
3
+ "version": "0.1.77",
4
4
  "author": {
5
5
  "name": "HKdigital",
6
6
  "url": "https://hkdigital.nl"
File without changes