mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-01 16:51:34 -05:00
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>
27 lines
912 B
C#
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;
|
|
}
|
|
}
|