// Copyright (c) 2022 - schick Informatik // bsmd.AIS2Service [MonitorZone.cs]: %UserDisplayName% // Description: Represents a geographical area that should be checked against // ship positions using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace bsmd.AIS2Service { internal class MonitorZone { private List _vertices; public MonitorZone(List vertices) { _vertices = vertices; } public bool IsPointInPolygon4(GeoPoint testPoint) { bool result = false; int j = _vertices.Count() - 1; for (int i = 0; i < _vertices.Count(); i++) { if (_vertices[i].Lat < testPoint.Lat && _vertices[j].Lat >= testPoint.Lat || _vertices[j].Lat < testPoint.Lat && _vertices[i].Lat >= testPoint.Lat) { if (_vertices[i].Lon + (testPoint.Lat - _vertices[i].Lat) / (_vertices[j].Lat - _vertices[i].Lat) * (_vertices[j].Lon - _vertices[i].Lon) < testPoint.Lon) { result = !result; } } j = i; } return result; } } internal class GeoPoint { public GeoPoint(double lat, double lon) { Lat = lat; Lon = lon; } public double Lat { get; private set; } public double Lon { get; private set; } } }