mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-15 13:35:34 -05:00
The overlap check now runs the pre-post part spacing scan on its snapshot, so the canvas label and posting agree. Too-close pairs are counted in the label and marked with an orange ring showing the gap, with hover details. A fully checked plate with no findings draws a green check instead of text; the status bar keeps the wording. Changing the plate's part spacing now stales the report, and repeated parts share one offset outline so automatic rechecks stay fast. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
71 lines
3.5 KiB
C#
71 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Diagnostics;
|
|
|
|
/// <summary>Read-only pair presentation; no geometry preparation or collision queries.</summary>
|
|
public static class OverlapPairPresentation
|
|
{
|
|
/// <summary>True for part-vs-clamp findings carried on the report (negative clamp slot).</summary>
|
|
public static bool IsClampFinding(PlateOverlapPair pair) => pair.PartBId < 0;
|
|
|
|
public static string Label(PlateOverlapPair pair) =>
|
|
IsClampFinding(pair) ? $"{pair.PartAId + 1}/clamp" : $"{pair.PartAId + 1}/{pair.PartBId + 1}";
|
|
|
|
public static string Details(PlateOverlapPair pair, Units capturedUnits, IFormatProvider provider = null)
|
|
{
|
|
var units = UnitsHelper.GetShortString(capturedUnits);
|
|
var head = IsClampFinding(pair)
|
|
? $"Clamp overlap: {pair.PartAName} / {pair.PartBName}"
|
|
: $"Pair {Label(pair)}: {pair.PartAName} / {pair.PartBName}";
|
|
return head + "\n"
|
|
+ $"Shared area ≈ {Number(pair.Area, provider)} {units}²\n"
|
|
+ $"Marker: ({Number(pair.Marker.X, provider)}, {Number(pair.Marker.Y, provider)}) {units}";
|
|
}
|
|
|
|
public static string Label(PlateSpacingPair pair, IFormatProvider provider = null) =>
|
|
$"{pair.PartAId + 1}/{pair.PartBId + 1} gap {Number(pair.Gap, provider)}";
|
|
|
|
public static string Details(PlateSpacingPair pair, Units capturedUnits, IFormatProvider provider = null)
|
|
{
|
|
var units = UnitsHelper.GetShortString(capturedUnits);
|
|
return $"Part spacing {pair.PartAId + 1}/{pair.PartBId + 1}: {pair.PartAName} / {pair.PartBName}\n"
|
|
+ $"Gap ≈ {Number(pair.Gap, provider)} {units}\n"
|
|
+ $"Marker: ({Number(pair.Marker.X, provider)}, {Number(pair.Marker.Y, provider)}) {units}";
|
|
}
|
|
|
|
// Significant figures adapt to scale: a positive sliver must never read as zero.
|
|
public static string Number(double value, IFormatProvider provider = null) =>
|
|
value.ToString("G6", provider ?? CultureInfo.CurrentCulture);
|
|
|
|
public static double MarkerHalfSize(int deviceDpi) => 6.0 * deviceDpi / 96;
|
|
public static double HitRadius(int deviceDpi) => 10.0 * deviceDpi / 96;
|
|
|
|
/// <summary>
|
|
/// Projects cached markers into a screen-pixel coordinate space. The pointer must
|
|
/// use that same space; view zoom never scales the DPI-adjusted hit radius.
|
|
/// Coincident or nearby markers return every matching pair in stable ID order.
|
|
/// </summary>
|
|
public static IReadOnlyList<PlateOverlapPair> HitTest(IEnumerable<PlateOverlapPair> pairs,
|
|
Func<Vector, Vector> worldToScreen, Vector pointer, int deviceDpi) =>
|
|
pairs.Where(pair => Hits(worldToScreen(pair.Marker), pointer, deviceDpi))
|
|
.OrderBy(pair => pair.PartAId).ThenBy(pair => pair.PartBId).ToArray();
|
|
|
|
/// <inheritdoc cref="HitTest(IEnumerable{PlateOverlapPair}, Func{Vector, Vector}, Vector, int)"/>
|
|
public static IReadOnlyList<PlateSpacingPair> HitTest(IEnumerable<PlateSpacingPair> pairs,
|
|
Func<Vector, Vector> worldToScreen, Vector pointer, int deviceDpi) =>
|
|
pairs.Where(pair => Hits(worldToScreen(pair.Marker), pointer, deviceDpi))
|
|
.OrderBy(pair => pair.PartAId).ThenBy(pair => pair.PartBId).ToArray();
|
|
|
|
private static bool Hits(Vector center, Vector pointer, int deviceDpi)
|
|
{
|
|
var radius = HitRadius(deviceDpi);
|
|
var dx = pointer.X - center.X;
|
|
var dy = pointer.Y - center.Y;
|
|
return dx * dx + dy * dy <= radius * radius;
|
|
}
|
|
}
|