style(shapes): remove redundant usings and document PipeSizes bound

This commit is contained in:
2026-04-10 17:31:22 -04:00
parent 57863e16e9
commit d215d02844
2 changed files with 22 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
namespace OpenNest.Shapes namespace OpenNest.Shapes
{ {
@@ -7,7 +6,7 @@ namespace OpenNest.Shapes
{ {
public readonly record struct Entry(string Label, double OuterDiameter); public readonly record struct Entry(string Label, double OuterDiameter);
public static IReadOnlyList<Entry> All { get; } = new List<Entry> public static IReadOnlyList<Entry> All { get; } = new[]
{ {
new Entry("1/8", 0.405), new Entry("1/8", 0.405),
new Entry("1/4", 0.540), new Entry("1/4", 0.540),
@@ -61,9 +60,19 @@ namespace OpenNest.Shapes
return false; return false;
} }
/// <summary>
/// Returns all pipe sizes whose outer diameter is less than or equal to <paramref name="maxOD"/>.
/// The bound is inclusive.
/// </summary>
public static IEnumerable<Entry> GetFittingSizes(double maxOD) public static IEnumerable<Entry> GetFittingSizes(double maxOD)
{ {
return All.Where(e => e.OuterDiameter <= maxOD); foreach (var entry in All)
{
if (entry.OuterDiameter <= maxOD)
{
yield return entry;
}
}
} }
} }
} }

View File

@@ -46,6 +46,16 @@ public class PipeSizesTests
Assert.DoesNotContain(results, e => e.Label == "4"); Assert.DoesNotContain(results, e => e.Label == "4");
} }
[Fact]
public void GetFittingSizes_ExactBoundary_IsInclusive()
{
// NPS 3 has OD 3.500; passing maxOD = 3.500 should include it.
var results = PipeSizes.GetFittingSizes(3.500).ToList();
Assert.Contains(results, e => e.Label == "3");
Assert.DoesNotContain(results, e => e.Label == "3 1/2");
}
[Fact] [Fact]
public void GetFittingSizes_MaxSmallerThanSmallest_ReturnsEmpty() public void GetFittingSizes_MaxSmallerThanSmallest_ReturnsEmpty()
{ {