mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-12-03 08:39:25 -05:00
refactor: share duplicated fill, cache, settings and toggle code
- fill_plate and fill_area share one MCP fill helper - FillLinear uses FillHelpers.HasOverlappingParts - BestFitCache and FillResultCache entries derive from DrawingCacheEntry - NestDefaults and ClampSettings read through SettingsFile.TryReadText - MainForm view toggles share one ToggleView handler Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4b61d249c0
commit
d77693aaff
10 files changed
+178
-217
No files matched your search
@@ -504,39 +504,7 @@ namespace OpenNest.Engine.Fill
|
||||
List<Part> parts,
|
||||
out int overlapA,
|
||||
out int overlapB
|
||||
)
|
||||
{
|
||||
var checker = new PartOverlapChecker();
|
||||
|
||||
for (var i = 0; i < parts.Count; i++)
|
||||
{
|
||||
var b1 = parts[i].BoundingBox;
|
||||
|
||||
for (var j = i + 1; j < parts.Count; j++)
|
||||
{
|
||||
var b2 = parts[j].BoundingBox;
|
||||
|
||||
var overlapX =
|
||||
System.Math.Min(b1.Right, b2.Right) - System.Math.Max(b1.Left, b2.Left);
|
||||
var overlapY =
|
||||
System.Math.Min(b1.Top, b2.Top) - System.Math.Max(b1.Bottom, b2.Bottom);
|
||||
|
||||
if (overlapX <= Tolerance.Epsilon || overlapY <= Tolerance.Epsilon)
|
||||
continue;
|
||||
|
||||
if (checker.Overlaps(parts[i], parts[j]))
|
||||
{
|
||||
overlapA = i;
|
||||
overlapB = j;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
overlapA = -1;
|
||||
overlapB = -1;
|
||||
return false;
|
||||
}
|
||||
) => Strategies.FillHelpers.HasOverlappingParts(parts, out overlapA, out overlapB);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a seed pattern containing a single part positioned at the work area origin.
|
||||
|
||||
@@ -85,38 +85,20 @@ public static class FillResultCache
|
||||
}
|
||||
}
|
||||
|
||||
private static Entry GetEntry(Drawing source)
|
||||
private static Entry GetEntry(Drawing source) =>
|
||||
DrawingCacheEntry.GetOrCreate(
|
||||
_entries,
|
||||
_entriesLock,
|
||||
source,
|
||||
static drawing => new Entry(drawing)
|
||||
);
|
||||
|
||||
private sealed class Entry : DrawingCacheEntry
|
||||
{
|
||||
if (_entries.TryGetValue(source, out var entry) && entry.IsCurrentFor(source))
|
||||
return entry;
|
||||
|
||||
lock (_entriesLock)
|
||||
{
|
||||
if (_entries.TryGetValue(source, out entry) && entry.IsCurrentFor(source))
|
||||
return entry;
|
||||
|
||||
entry = new Entry(source);
|
||||
_entries.AddOrUpdate(source, entry);
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Entry
|
||||
{
|
||||
private readonly CNC.Program program;
|
||||
private readonly double sourceAngle;
|
||||
|
||||
public readonly ConcurrentDictionary<CacheKey, List<Part>> Results = new();
|
||||
|
||||
public Entry(Drawing source)
|
||||
{
|
||||
program = source.Program;
|
||||
sourceAngle = source.Source?.Angle ?? 0.0;
|
||||
}
|
||||
|
||||
public bool IsCurrentFor(Drawing source) =>
|
||||
ReferenceEquals(program, source.Program)
|
||||
&& sourceAngle == (source.Source?.Angle ?? 0.0);
|
||||
: base(source) { }
|
||||
}
|
||||
|
||||
private readonly record struct CacheKey(bool IsCanonical, double Width, double Height, double Spacing)
|
||||
@@ -127,6 +109,7 @@ public static class FillResultCache
|
||||
System.Math.Round(width, 2),
|
||||
System.Math.Round(height, 2),
|
||||
spacing
|
||||
) { }
|
||||
)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user