c3a1a8b4a1
Capture current PCP architecture notes, service-map prototypes, TGU operations UI/map work, local configuration updates, database helper scripts, and request/sample JSON artifacts.
22 lines
567 B
TypeScript
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;
|
|
}
|
|
|