using System; using RynthCore.Plugin.RynthNav; namespace RynthNav.RouteTests; // Walks keep to the trip's own path (TripFollow.cs, 2026-11-27): each re-plan aims a few yards along the walk the // markers draw; off it, back to it; progress never goes back, so a walk that doubles back isn't cut across. // Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here. internal static partial class Program { private static void RunFollow() { Run(nameof(FollowAimsAlongTheWalk), FollowAimsAlongTheWalk); Run(nameof(FollowRejoinsWhenOff), FollowRejoinsWhenOff); Run(nameof(FollowNeverCutsBack), FollowNeverCutsBack); Run(nameof(FollowHeights), FollowHeights); } // An L: 100 yd east, then 100 yd north. private static WorldPt[] LWalk() => new[] { new WorldPt(1000, 1000, 0), new WorldPt(1100, 1000, 0), new WorldPt(1100, 1100, 0) }; private static void FollowAimsAlongTheWalk() { var f = new TripFollow(1, 0, LWalk()); Near(f.Length, 200, 1e-6, "the walk's length"); WorldPt a = f.Aim(1000, 1000, out double off, out bool atEnd); Near(a.X, 1000 + TripFollow.AheadUnits, 1e-6, "from the start: AheadUnits along"); Check(!atEnd && off < 1e-6, "on the walk, not at its end"); // At the corner, the aim goes round it (north), not straight on east across the field. a = f.Aim(1090, 1000, out off, out atEnd); Near(a.X, 1100, 1e-6, "past the corner: on the north leg (x)"); Near(a.Y, 1000 + (90 + TripFollow.AheadUnits - 100), 1e-6, "past the corner: on the north leg (y)"); // A little to the side of the walk still counts as on it. a = f.Aim(1100 - 5, 1050, out off, out atEnd); Near(off, 5, 1e-6, "5 yd to the side"); Near(a.Y, 1050 + TripFollow.AheadUnits, 1e-6, "aims along from the nearest point"); // Near the end: the step's own point, and planned to it as before. a = f.Aim(1100, 1090, out off, out atEnd); Check(atEnd && a.X == 1100 && a.Y == 1100, "near the end: the end itself"); Near(f.Progress, 190, 1e-6, "progress is where you are on it"); } private static void FollowRejoinsWhenOff() { var f = new TripFollow(1, 0, LWalk()); f.Aim(1050, 1000, out _, out _); // Knocked 30 yd off the walk: aim back at it, a little past its nearest point, not 28 yd ahead. WorldPt a = f.Aim(1060, 970, out double off, out bool atEnd); Near(off, 30, 1e-6, "30 yd off"); Near(a.X, 1060 + TripFollow.RejoinUnits, 1e-6, "back to the walk, just past its nearest point"); Near(a.Y, 1000, 1e-6, "on the walk"); Near(f.Progress, 50, 1e-6, "progress doesn't move while off"); Check(!atEnd, "not the end"); } private static void FollowNeverCutsBack() { // A hairpin: 100 east, 10 north, 100 back west. From the start of the way back, the first leg is 10 yd away. var hairpin = new[] { new WorldPt(0, 0, 0), new WorldPt(100, 0, 0), new WorldPt(100, 10, 0), new WorldPt(0, 10, 0) }; var f = new TripFollow(1, 0, hairpin); for (double x = 0; x <= 100; x += 10) f.Aim(x, 0, out _, out _); f.Aim(100, 10, out _, out _); f.Aim(80, 10, out _, out _); Near(f.Progress, 130, 1e-6, "on the way back, 130 yd along"); // Standing between the legs, nearer the first: the first leg is behind the window, so it isn't picked. WorldPt a = f.Aim(60, 4, out double off, out _); Check(Math.Abs(off - 6) < 1e-6, $"measured from the way back (6 yd), not the first leg (4 yd): {off:F2}"); Check(a.Y == 10 && a.X < 60, $"the aim keeps going west on the way back ({a.X:F1}, {a.Y:F1})"); Check(f.Progress >= 130, "progress never goes back"); // Two points are the least a walk is. bool threw = false; try { _ = new TripFollow(1, 0, new[] { new WorldPt(0, 0, 0) }); } catch (ArgumentException) { threw = true; } Check(threw, "one point isn't a walk"); } private static void FollowHeights() { var ramp = new[] { new WorldPt(0, 0, 10), new WorldPt(100, 0, 30) }; var f = new TripFollow(1, 0, ramp); Near(f.At(50).H, 20, 1e-6, "the height between the points"); var flat = new[] { new WorldPt(0, 0, double.NaN), new WorldPt(100, 0, double.NaN) }; Check(double.IsNaN(new TripFollow(1, 0, flat).At(50).H), "no heights given: none made up (the walker uses its own)"); } }