mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-11-16 18:15:34 -05:00
The overlap crosshair sat on the pair's area centroid. For a split,
holed or concave overlap, that point can be off the red material:
between two patches, in a hole, or inside a curve.
PlateOverlapPair.Marker is a point inside the pair's largest island.
It is the island's pole of inaccessibility (PolyLabel), searched to a
tenth of the island's area/perimeter within a 4096-cell budget. If
that bounded search does not land inside (a long thin sliver), the
marker falls back to the midpoint of the widest interior run of a
horizontal scan line placed between vertex heights.
The overlay crosshair, marker hit testing, hover coordinates
("Marker:") and the cutting-inspection ring now use the marker.
Centroid stays the true area centroid. View > Overlap Check > Display
> Centroids is now labelled Markers.
Before the marker existed, its call sites used the centroid. Two
patches, a covered frame, a half annulus and a thin crescent then put
it off the material; now all four land on it. Disabling the scan-line
fallback fails its test. On the 389-plate corpus, markers add about
0.4 ms per overlapping pair; pair and area results are unchanged.
79 lines
3.3 KiB
C#
79 lines
3.3 KiB
C#
using System.Globalization;
|
|
using OpenNest.CNC;
|
|
using OpenNest.Diagnostics;
|
|
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Tests.Diagnostics;
|
|
|
|
public class OverlapPairPresentationTests
|
|
{
|
|
[Theory]
|
|
[InlineData(Units.Inches, "in")]
|
|
[InlineData(Units.Millimeters, "mm")]
|
|
public void DetailsUseCapturedNamesSequenceIdsAndSuppliedUnits(Units units, string symbol)
|
|
{
|
|
var parts = new[] { Rectangle("cutoff"), Rectangle("left"), Rectangle("right") };
|
|
parts[0].BaseDrawing.IsCutOff = true;
|
|
var snapshot = PlateOverlapAnalyzer.Capture(parts);
|
|
parts[1].BaseDrawing.Name = "changed";
|
|
var pair = Assert.Single(PlateOverlapAnalyzer.Analyze(snapshot).Pairs);
|
|
Assert.Equal("2/3", OverlapPairPresentation.Label(pair));
|
|
var text = OverlapPairPresentation.Details(pair, units, CultureInfo.InvariantCulture);
|
|
Assert.Equal($"Pair 2/3: left / right\nShared area ≈ 16 {symbol}²\nMarker: (2, 2) {symbol}", text);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(1e-15)]
|
|
[InlineData(1e-100)]
|
|
[InlineData(double.Epsilon)]
|
|
[InlineData(0.000000123456)]
|
|
public void PositiveTinyValuesNeverFormatAsZero(double value)
|
|
{
|
|
var text = OverlapPairPresentation.Number(value, CultureInfo.InvariantCulture);
|
|
Assert.True(double.Parse(text, CultureInfo.InvariantCulture) > 0, text);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(96, 1)]
|
|
[InlineData(144, 1.5)]
|
|
[InlineData(192, 2)]
|
|
public void HitRadiusIsScreenSizedDpiScaledAndInclusive(int dpi, double factor)
|
|
{
|
|
Assert.Equal(6 * factor, OverlapPairPresentation.MarkerHalfSize(dpi));
|
|
Assert.Equal(10 * factor, OverlapPairPresentation.HitRadius(dpi));
|
|
var pairs = PlateOverlapAnalyzer.Analyze(new[] { Rectangle("a"), Rectangle("b") }).Pairs;
|
|
foreach (var zoom in new[] { 0.5, 20.0, 500.0 })
|
|
{
|
|
Vector ToScreen(Vector world) => new(100 + world.X * zoom, 200 - world.Y * zoom);
|
|
var center = ToScreen(pairs[0].Marker);
|
|
var radius = OverlapPairPresentation.HitRadius(dpi);
|
|
Assert.Single(OverlapPairPresentation.HitTest(pairs, ToScreen,
|
|
center + new Vector(radius, 0), dpi));
|
|
Assert.Empty(OverlapPairPresentation.HitTest(pairs, ToScreen,
|
|
center + new Vector(radius + 0.01, 0), dpi));
|
|
Assert.Empty(OverlapPairPresentation.HitTest(pairs, ToScreen,
|
|
center + new Vector(radius, radius), dpi));
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void CoincidentMarkersReturnEveryPairInIdOrderNotFragmentOrder()
|
|
{
|
|
var pairs = PlateOverlapAnalyzer.Analyze(new[] { Rectangle("a"), Rectangle("b"), Rectangle("c") }).Pairs;
|
|
var hits = OverlapPairPresentation.HitTest(pairs.Reverse(), p => p, new Vector(2, 2), 96);
|
|
Assert.Equal(new[] { "1/2", "1/3", "2/3" }, hits.Select(OverlapPairPresentation.Label));
|
|
Assert.All(hits, p => Assert.Single(p.Regions)); // One island per coincident pair.
|
|
}
|
|
|
|
private static Part Rectangle(string name)
|
|
{
|
|
var program = new Program(Mode.Absolute);
|
|
program.Codes.Add(new RapidMove(0, 0));
|
|
program.Codes.Add(new LinearMove(4, 0));
|
|
program.Codes.Add(new LinearMove(4, 4));
|
|
program.Codes.Add(new LinearMove(0, 4));
|
|
program.Codes.Add(new LinearMove(0, 0));
|
|
return new Part(new Drawing(name, program));
|
|
}
|
|
}
|