Files
OpenNest/OpenNest.Core/Geometry/RingContainment.cs
T
ajandClaude Opus 5.5 409d30d29e refactor(core): share duplicated geometry helpers
Route the four identical even-odd ray casts through RingContainment.Contains and share the arc-intersection, span-pairing, overlap-region, lead-in, plate-offset, leader-edge, entity-copy and path-perimeter duplicates. Expressions and loop order are unchanged, so results are bit-identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-28 18:36:40 -05:00

27 lines
912 B
C#

using System.Collections.Generic;
namespace OpenNest.Geometry;
/// <summary>Even-odd point-in-ring test shared by callers that need the same answer bit for bit.</summary>
public static class RingContainment
{
/// <summary>
/// Even-odd ray cast of <paramref name="point"/> against the closed <paramref name="ring"/>
/// (the last vertex joins the first). The answer for a point on the ring is unspecified.
/// </summary>
public static bool Contains(IReadOnlyList<Vector> 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;
}
}