MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / pointInPolygon

Function pointInPolygon

src/components/CropPlanningSection.tsx:1456–1467  ·  view source on GitHub ↗
(point: [number, number], polygon: [number, number][])

Source from the content-addressed store, hash-verified

1454function getMetersPerLng(latitude: number) {
1455 return 111320 * Math.cos((latitude * Math.PI) / 180);
1456}
1457
1458function pointInPolygon(point: [number, number], polygon: [number, number][]) {
1459 let inside = false;
1460 for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
1461 const xi = polygon[i][0];
1462 const yi = polygon[i][1];
1463 const xj = polygon[j][0];
1464 const yj = polygon[j][1];
1465 const intersect = yi > point[1] !== yj > point[1] && point[0] < ((xj - xi) * (point[1] - yi)) / (yj - yi || 1e-9) + xi;
1466 if (intersect) inside = !inside;
1467 }
1468 return inside;
1469}
1470

Callers 1

generateFullFieldGridFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected