Files
dc-observatio/services/pcp-tgu-ops-ui/src/features/tgu-map-2d/geometry/pointInPolygon.ts
T
Дмитрий Соловьев c3a1a8b4a1 Add PCP architecture docs and TGU ops updates
Capture current PCP architecture notes, service-map prototypes, TGU operations UI/map work, local configuration updates, database helper scripts, and request/sample JSON artifacts.
2026-05-30 14:18:19 +03:00

22 lines
567 B
TypeScript

import type { GeoPoint } from "../model/mapTypes";
export function pointInPolygon(point: GeoPoint, polygon: GeoPoint[]): boolean {
if (polygon.length < 3) return false;
let inside = false;
for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {
const pi = polygon[i]!;
const pj = polygon[j]!;
const intersects =
pi.lat > point.lat !== pj.lat > point.lat &&
point.lon < ((pj.lon - pi.lon) * (point.lat - pi.lat)) / (pj.lat - pi.lat) + pi.lon;
if (intersects) {
inside = !inside;
}
}
return inside;
}