diff --git a/Dashboard.Common/Anchor.cs b/Dashboard.Common/Anchor.cs index 0505972..9b2579f 100644 --- a/Dashboard.Common/Anchor.cs +++ b/Dashboard.Common/Anchor.cs @@ -1,5 +1,6 @@ namespace Dashboard { + [Flags] public enum Anchor { Auto = 0, diff --git a/Dashboard.Common/Box2d.cs b/Dashboard.Common/Box2d.cs new file mode 100644 index 0000000..974228e --- /dev/null +++ b/Dashboard.Common/Box2d.cs @@ -0,0 +1,65 @@ +using System.ComponentModel.DataAnnotations; +using System.Drawing; +using System.Numerics; + +namespace Dashboard +{ + public readonly record struct Box2d(Vector2 Min, Vector2 Max) + { + public float Left => Min.X; + public float Right => Max.X; + public float Top => Min.Y; + public float Bottom => Max.Y; + + public Vector2 Size => Max - Min; + public Vector2 Center => (Min + Max) * 0.5f; + + public Box2d(RectangleF rectangle) + : this(new Vector2(rectangle.Left, rectangle.Top), new Vector2(rectangle.Right, rectangle.Bottom)) + { + } + + public Box2d(float x0, float y0, float x1, float y1) + : this(new Vector2(x0, y0), new Vector2(x1, y1)) + { + } + + public static Box2d FromPositionAndSize(Vector2 position, Vector2 size, Origin anchor = Origin.Center) + { + Vector2 half = size * 0.5f; + switch (anchor) + { + case Origin.Center: + return new Box2d(position - half, position + half); + case Origin.TopLeft: + return new Box2d(position, position + size); + default: + throw new NotImplementedException(); + } + } + + public static Box2d Union(Box2d left, Box2d right) + { + Vector2 min = Vector2.Min(left.Min, right.Min); + Vector2 max = Vector2.Max(left.Max, right.Max); + return new Box2d(min, max); + } + + public static Box2d Intersect(Box2d left, Box2d right) + { + Vector2 min = Vector2.Max(left.Min, right.Min); + Vector2 max = Vector2.Min(left.Max, right.Max); + return new Box2d(min, max); + } + + public static explicit operator RectangleF(Box2d box2d) + { + return new RectangleF((PointF)box2d.Center, (SizeF)box2d.Size); + } + + public static explicit operator Box2d(RectangleF rectangle) + { + return new Box2d(rectangle); + } + } +} diff --git a/Dashboard.Common/Box3d.cs b/Dashboard.Common/Box3d.cs index 1849546..e920fc8 100644 --- a/Dashboard.Common/Box3d.cs +++ b/Dashboard.Common/Box3d.cs @@ -1,4 +1,5 @@ -using System.Numerics; +using System.Drawing; +using System.Numerics; namespace Dashboard { @@ -12,7 +13,7 @@ namespace Dashboard public float Near => Max.Z; public Vector3 Size => Max - Min; - public Vector3 Center => Min + Size / 2f; + public Vector3 Center => Min + Size * 0.5f; public static Box3d Union(Box3d left, Box3d right) { @@ -21,11 +22,25 @@ namespace Dashboard return new Box3d(min, max); } + public static Box3d Union(Box3d box, Box2d bounds, float depth) + { + Vector3 min = Vector3.Min(box.Min, new Vector3(bounds.Left, bounds.Top, depth)); + Vector3 max = Vector3.Max(box.Max, new Vector3(bounds.Right, bounds.Bottom, depth)); + return new Box3d(min, max); + } + public static Box3d Intersect(Box3d left, Box3d right) { Vector3 min = Vector3.Max(left.Min, right.Min); Vector3 max = Vector3.Min(left.Max, right.Max); return new Box3d(min, max); } + + public static Box3d Intersect(Box3d box, Box2d bounds, float depth) + { + Vector3 min = Vector3.Max(box.Min, new Vector3(bounds.Min, depth)); + Vector3 max = Vector3.Min(box.Max, new Vector3(bounds.Max, depth)); + return new Box3d(min, max); + } } } diff --git a/Dashboard.Common/LineProperties.cs b/Dashboard.Common/LineProperties.cs new file mode 100644 index 0000000..047ab1c --- /dev/null +++ b/Dashboard.Common/LineProperties.cs @@ -0,0 +1,23 @@ +namespace Dashboard +{ + public enum BorderKind + { + Inset = -1, + Center = 0, + Outset = 1, + } + + public enum CapType + { + None, + Circular, + Rectangular, + } + + public enum CuspType + { + None, + Circular, + Rectangular, + } +} diff --git a/Dashboard.Common/Origin.cs b/Dashboard.Common/Origin.cs new file mode 100644 index 0000000..946cdcd --- /dev/null +++ b/Dashboard.Common/Origin.cs @@ -0,0 +1,17 @@ +namespace Dashboard +{ + public enum Origin + { + Center = 0, + + Left = (1 << 0), + Top = (1 << 1), + Right = (1 << 2), + Bottom = (1 << 3), + + TopLeft = Top | Left, + BottomLeft = Bottom | Left, + BottomRight = Bottom | Right, + TopRight = Top | Right, + } +}