Delaunay: exact orientation and in-circle predicates, loud degenerate input, Galaxy zone-linked guard

Double-precision filter with BigInteger fallback replaces the circumcentre test; the super-triangle is far enough out
that no float input reaches it. Collinear points link along the line, duplicate or non-finite points throw, and
Galaxy refuses a zone no link reaches. The exact oracle replaces ScenarioTests' double brute force.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Nibu 2026-11-13 15:36:20 +00:00 • committed by soul
commit f428ab1d88
4 changed files with 319 additions and 48 deletions

View file

@ -451,6 +451,21 @@ public class Galaxy
}
}
// A zone no link reaches would throw far from here, placing homes or the entrance; refuse it where it is made.
public static void RequireEveryZoneLinked(GalaxyZone[] zones, IEnumerable<(GalaxyZone, GalaxyZone)> links)
{
if (zones.Length < 2) return;
var linked = new HashSet<GalaxyZone>();
foreach (var link in links)
{
linked.Add(link.Item1);
linked.Add(link.Item2);
}
var stranded = zones.Where(zone => !linked.Contains(zone)).ToList();
if (stranded.Count > 0)
throw new InvalidOperationException($"Triangulation left {stranded.Count} of {zones.Length} zones unlinked, first at {stranded[0].Position}");
}
private void GenerateLinks(float linkDensity, Action<string> progressCallback = null)
{
progressCallback?.Invoke("Triangulating Zone Positions");
@ -460,6 +475,7 @@ public class Galaxy
var links = Delaunay.Edges(Zones.Select(z => z.Position).ToArray())
.Select(edge => (Zones[edge.a], Zones[edge.b]))
.ToList();
RequireEveryZoneLinked(Zones, links);
progressCallback?.Invoke("Eliminating Zone Links");
if (progressCallback != null) Thread.Sleep(500); // Inserting Delay to make it seem like it's doing more work lmao