Implement missing origin calculations.
This commit is contained in:
+36
-12
@@ -25,19 +25,43 @@ namespace Dashboard
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Box2d FromPositionAndSize(Vector2 position, Vector2 size, Origin anchor = Origin.Center)
|
public static Box2d FromPositionAndSize(Vector2 position, Vector2 size, Origin anchor = Origin.Center) =>
|
||||||
|
// Hoping the redundent additions+muls become conditional fma instructions.
|
||||||
|
anchor switch
|
||||||
{
|
{
|
||||||
Vector2 half = size * 0.5f;
|
Origin.Left => new Box2d(
|
||||||
switch (anchor)
|
position + (size * new Vector2(0.0f, -0.5f)),
|
||||||
{
|
position + (size * new Vector2(1.0f, 0.5f))
|
||||||
case Origin.Center:
|
),
|
||||||
return new Box2d(position - half, position + half);
|
Origin.TopLeft => new Box2d(position, position + size),
|
||||||
case Origin.TopLeft:
|
Origin.Top => new Box2d(
|
||||||
return new Box2d(position, position + size);
|
position + (size * new Vector2(-0.5f, 0f)),
|
||||||
default:
|
position + (size * new Vector2(0.5f, 1f))),
|
||||||
throw new NotImplementedException();
|
Origin.TopRight => new Box2d(
|
||||||
}
|
position + (size * new Vector2(-1.0f, 0.0f)),
|
||||||
}
|
position + (size * new Vector2(0.0f, 1.0f))
|
||||||
|
),
|
||||||
|
Origin.Right => new Box2d(
|
||||||
|
position + (size * new Vector2(-1.0f, -0.5f)),
|
||||||
|
position + (size * new Vector2(0.0f, 0.5f))
|
||||||
|
),
|
||||||
|
Origin.BottomRight => new Box2d(
|
||||||
|
position + (size * new Vector2(-1.0f, -1.0f)),
|
||||||
|
position + (size * new Vector2(0.0f, 0.0f))
|
||||||
|
),
|
||||||
|
Origin.Bottom => new Box2d(
|
||||||
|
position + (size * new Vector2(-0.5f, -1.0f)),
|
||||||
|
position + (size * new Vector2(0.5f, 0.0f))
|
||||||
|
),
|
||||||
|
Origin.BottomLeft => new Box2d(
|
||||||
|
position + (size * new Vector2(0.0f, -1.0f)),
|
||||||
|
position + (size * new Vector2(1.0f, 0.0f))
|
||||||
|
),
|
||||||
|
Origin.Center => new Box2d(
|
||||||
|
position + (size * new Vector2(-0.5f, -0.5f)),
|
||||||
|
position + (size * new Vector2(0.5f, 0.5f))),
|
||||||
|
_ => throw new ArgumentOutOfRangeException(nameof(anchor)),
|
||||||
|
};
|
||||||
|
|
||||||
public static Box2d Union(Box2d left, Box2d right)
|
public static Box2d Union(Box2d left, Box2d right)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user