Added new mathematical types and enums related to drawing.
This commit is contained in:
parent
1a52f17990
commit
cde0fe2901
@ -1,5 +1,6 @@
|
|||||||
namespace Dashboard
|
namespace Dashboard
|
||||||
{
|
{
|
||||||
|
[Flags]
|
||||||
public enum Anchor
|
public enum Anchor
|
||||||
{
|
{
|
||||||
Auto = 0,
|
Auto = 0,
|
||||||
|
65
Dashboard.Common/Box2d.cs
Normal file
65
Dashboard.Common/Box2d.cs
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using System.Numerics;
|
using System.Drawing;
|
||||||
|
using System.Numerics;
|
||||||
|
|
||||||
namespace Dashboard
|
namespace Dashboard
|
||||||
{
|
{
|
||||||
@ -12,7 +13,7 @@ namespace Dashboard
|
|||||||
public float Near => Max.Z;
|
public float Near => Max.Z;
|
||||||
|
|
||||||
public Vector3 Size => Max - Min;
|
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)
|
public static Box3d Union(Box3d left, Box3d right)
|
||||||
{
|
{
|
||||||
@ -21,11 +22,25 @@ namespace Dashboard
|
|||||||
return new Box3d(min, max);
|
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)
|
public static Box3d Intersect(Box3d left, Box3d right)
|
||||||
{
|
{
|
||||||
Vector3 min = Vector3.Max(left.Min, right.Min);
|
Vector3 min = Vector3.Max(left.Min, right.Min);
|
||||||
Vector3 max = Vector3.Min(left.Max, right.Max);
|
Vector3 max = Vector3.Min(left.Max, right.Max);
|
||||||
return new Box3d(min, 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
23
Dashboard.Common/LineProperties.cs
Normal file
23
Dashboard.Common/LineProperties.cs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
17
Dashboard.Common/Origin.cs
Normal file
17
Dashboard.Common/Origin.cs
Normal file
@ -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,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user