feat: add IComparable<Box> and comparison operators to Box

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-23 10:36:23 -04:00
parent ceb9cc0b44
commit e04c9381f3
2 changed files with 114 additions and 2 deletions
+17 -2
View File
@@ -1,8 +1,9 @@
using OpenNest.Math;
using System;
using OpenNest.Math;
namespace OpenNest.Geometry
{
public class Box
public class Box : IComparable<Box>
{
public static readonly Box Empty = new Box();
@@ -214,5 +215,19 @@ namespace OpenNest.Geometry
{
return string.Format("[Box: X={0}, Y={1}, Width={2}, Length={3}]", X, Y, Width, Length);
}
public int CompareTo(Box other)
{
var cmp = Width.CompareTo(other.Width);
return cmp != 0 ? cmp : Length.CompareTo(other.Length);
}
public static bool operator >(Box a, Box b) => a.CompareTo(b) > 0;
public static bool operator <(Box a, Box b) => a.CompareTo(b) < 0;
public static bool operator >=(Box a, Box b) => a.CompareTo(b) >= 0;
public static bool operator <=(Box a, Box b) => a.CompareTo(b) <= 0;
}
}