fix(core): arc bounding box inflated for near-zero sweep arcs
Arcs with sweep angles smaller than Tolerance.Epsilon were treated as full circles by IsBetweenRad's shortcut check, causing UpdateBounds to expand the bounding box to Center ± Radius. This made zoom-to-fit zoom out far beyond the actual part extents. Skip cardinal angle expansion when sweep is near-zero so the bounding box uses only the arc's start/end points. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -404,10 +404,12 @@ namespace OpenNest.Geometry
|
|||||||
maxY = startpt.Y;
|
maxY = startpt.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var sweep = SweepAngle();
|
||||||
|
if (sweep > Tolerance.Epsilon)
|
||||||
|
{
|
||||||
var angle1 = StartAngle;
|
var angle1 = StartAngle;
|
||||||
var angle2 = EndAngle;
|
var angle2 = EndAngle;
|
||||||
|
|
||||||
// switch the angle to counter clockwise.
|
|
||||||
if (IsReversed)
|
if (IsReversed)
|
||||||
Generic.Swap(ref angle1, ref angle2);
|
Generic.Swap(ref angle1, ref angle2);
|
||||||
|
|
||||||
@@ -424,6 +426,7 @@ namespace OpenNest.Geometry
|
|||||||
|
|
||||||
if (Angle.IsBetweenRad(Angle.TwoPI, angle1, angle2))
|
if (Angle.IsBetweenRad(Angle.TwoPI, angle1, angle2))
|
||||||
maxX = Center.X + Radius;
|
maxX = Center.X + Radius;
|
||||||
|
}
|
||||||
|
|
||||||
boundingBox.X = minX;
|
boundingBox.X = minX;
|
||||||
boundingBox.Y = minY;
|
boundingBox.Y = minY;
|
||||||
|
|||||||
@@ -2,14 +2,18 @@ using OpenNest.Geometry;
|
|||||||
using OpenNest.IO;
|
using OpenNest.IO;
|
||||||
using OpenNest.Math;
|
using OpenNest.Math;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
using Xunit.Abstractions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace OpenNest.Tests.Geometry;
|
namespace OpenNest.Tests.Geometry;
|
||||||
|
|
||||||
public class EllipseConverterTests
|
public class EllipseConverterTests
|
||||||
{
|
{
|
||||||
|
private readonly ITestOutputHelper _output;
|
||||||
private const double Tol = 1e-10;
|
private const double Tol = 1e-10;
|
||||||
|
|
||||||
|
public EllipseConverterTests(ITestOutputHelper output) => _output = output;
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void EvaluatePoint_AtZero_ReturnsMajorAxisEnd()
|
public void EvaluatePoint_AtZero_ReturnsMajorAxisEnd()
|
||||||
{
|
{
|
||||||
@@ -245,6 +249,26 @@ public class EllipseConverterTests
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void DxfImport_ArcBoundingBoxes_Diagnostic()
|
||||||
|
{
|
||||||
|
var path = @"C:\Users\aisaacs\Desktop\11ga tab.dxf";
|
||||||
|
if (!System.IO.File.Exists(path)) return;
|
||||||
|
|
||||||
|
var result = Dxf.Import(path);
|
||||||
|
var all = (System.Collections.Generic.IEnumerable<IBoundable>)result.Entities;
|
||||||
|
var bbox = all.GetBoundingBox();
|
||||||
|
_output.WriteLine($"Overall: X={bbox.X:F4} Y={bbox.Y:F4} W={bbox.Length:F4} H={bbox.Width:F4}");
|
||||||
|
|
||||||
|
for (var i = 0; i < result.Entities.Count; i++)
|
||||||
|
{
|
||||||
|
var e = result.Entities[i];
|
||||||
|
var b = e.BoundingBox;
|
||||||
|
var flag = (b.Length > 1 || b.Width > 1) ? " ***" : "";
|
||||||
|
_output.WriteLine($"{i + 1,3}. {e.GetType().Name,-8} X={b.X:F4} Y={b.Y:F4} W={b.Length:F4} H={b.Width:F4}{flag}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ToOpenNest_FlippedNormalZ_ProducesCorrectArcs()
|
public void ToOpenNest_FlippedNormalZ_ProducesCorrectArcs()
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user