mirror of
https://github.com/ajisaacs/OpenNest.git
synced 2026-10-02 06:38:48 -04:00
DxfImport_ArcBoundingBoxes_Diagnostic read a drawing from one user's desktop, returned early elsewhere and asserted nothing, so the near-zero sweep bounding-box fix (4053f1f) had no regression test that could fail. Replace it with ArcBoundingBoxTests: a forward and a reversed arc with a sweep below Tolerance.Epsilon must be bounded by its endpoints, and an ordinary arc crossing 90 degrees must still reach the top of its circle. With the4053f1fguard reverted, both near-zero cases fail (the box grows to the full circle); with it in place all three pass.
55 lines
1.8 KiB
C#
55 lines
1.8 KiB
C#
using OpenNest.Geometry;
|
|
|
|
namespace OpenNest.Tests.Geometry;
|
|
|
|
/// <summary>
|
|
/// An arc whose sweep is below <c>Tolerance.Epsilon</c> must not be bounded as a full
|
|
/// circle: its box covers only the endpoints. Ordinary arcs still reach the cardinal
|
|
/// extents they cross.
|
|
/// </summary>
|
|
public class ArcBoundingBoxTests
|
|
{
|
|
private const double Tol = 1e-9;
|
|
|
|
[Theory]
|
|
[InlineData(false)]
|
|
[InlineData(true)]
|
|
public void NearZeroSweep_BoundsCoverOnlyTheEndpoints(bool reversed)
|
|
{
|
|
var center = new Vector(10, 20);
|
|
const double radius = 50;
|
|
const double a = 0.3;
|
|
const double b = 0.3 + 1e-6; // sweep well below Tolerance.Epsilon (1e-5)
|
|
|
|
var arc = reversed
|
|
? new Arc(center, radius, b, a, reversed: true)
|
|
: new Arc(center, radius, a, b);
|
|
|
|
var x1 = center.X + radius * System.Math.Cos(a);
|
|
var y1 = center.Y + radius * System.Math.Sin(a);
|
|
var x2 = center.X + radius * System.Math.Cos(b);
|
|
var y2 = center.Y + radius * System.Math.Sin(b);
|
|
var box = arc.BoundingBox;
|
|
|
|
Assert.Equal(System.Math.Min(x1, x2), box.X, Tol);
|
|
Assert.Equal(System.Math.Min(y1, y2), box.Y, Tol);
|
|
Assert.Equal(System.Math.Max(x1, x2), box.X + box.Length, Tol);
|
|
Assert.Equal(System.Math.Max(y1, y2), box.Y + box.Width, Tol);
|
|
}
|
|
|
|
[Fact]
|
|
public void ArcCrossingQuarterTurn_StillReachesTopOfCircle()
|
|
{
|
|
const double radius = 10;
|
|
const double a = 0.1;
|
|
var arc = new Arc(new Vector(0, 0), radius, a, System.Math.PI - a);
|
|
|
|
var box = arc.BoundingBox;
|
|
|
|
Assert.Equal(-radius * System.Math.Cos(a), box.X, Tol);
|
|
Assert.Equal(radius * System.Math.Sin(a), box.Y, Tol);
|
|
Assert.Equal(radius * System.Math.Cos(a), box.X + box.Length, Tol);
|
|
Assert.Equal(radius, box.Y + box.Width, Tol);
|
|
}
|
|
}
|