using System.Collections.Generic; namespace OpenNest.Geometry; /// Even-odd point-in-ring test shared by callers that need the same answer bit for bit. public static class RingContainment { /// /// Even-odd ray cast of against the closed /// (the last vertex joins the first). The answer for a point on the ring is unspecified. /// public static bool Contains(IReadOnlyList ring, Vector point) { var inside = false; var count = ring.Count; for (int i = 0, j = count - 1; i < count; j = i++) { var a = ring[i]; var b = ring[j]; if ((a.Y > point.Y) != (b.Y > point.Y) && point.X < (b.X - a.X) * (point.Y - a.Y) / (b.Y - a.Y) + a.X) inside = !inside; } return inside; } }