Struct helpers

This commit is contained in:
Maddy Thorson 2021-02-13 16:50:50 -08:00
parent d9c75b1e0d
commit 3aff5a3c3f
3 changed files with 31 additions and 7 deletions

View File

@ -6,6 +6,9 @@ namespace Strawberry
case Right = 1;
case Left = -1;
[Inline]
public float Angle => this == .Right ? Calc.Right : Calc.Left;
public Facings Opposite()
{
if (this == .Right)

View File

@ -64,7 +64,7 @@ namespace Strawberry
[Inline]
static public explicit operator Point(Vector a)
{
return Point((int)a.X, (int)a.Y);
return .((int)a.X, (int)a.Y);
}
[Inline]
@ -82,37 +82,49 @@ namespace Strawberry
[Inline]
static public Point operator+(Point a, Point b)
{
return Point(a.X + b.X, a.Y + b.Y);
return .(a.X + b.X, a.Y + b.Y);
}
[Inline]
static public Point operator-(Point a, Point b)
{
return Point(a.X - b.X, a.Y - b.Y);
return .(a.X - b.X, a.Y - b.Y);
}
[Inline, Commutable]
static public Point operator*(Point a, int b)
{
return Point(a.X * b, a.Y * b);
return .(a.X * b, a.Y * b);
}
[Inline]
static public Point operator*(Point a, Point b)
{
return Point(a.X * b.X, a.Y * b.Y);
return .(a.X * b.X, a.Y * b.Y);
}
[Inline]
static public Point operator/(Point a, int b)
{
return Point(a.X / b, a.Y / b);
return .(a.X / b, a.Y / b);
}
[Inline, Commutable]
static public Vector operator*(Point a, float b)
{
return .(a.X * b, a.Y * b);
}
[Inline]
static public Vector operator/(Point a, float b)
{
return .(a.X / b, a.Y / b);
}
[Inline]
static public Point operator/(Point a, Point b)
{
return Point(a.X / b.X, a.Y / b.Y);
return .(a.X / b.X, a.Y / b.Y);
}
[Inline, Commutable]

View File

@ -49,6 +49,9 @@ namespace Strawberry
[Inline]
public float LengthSquared => X * X + Y * Y;
[Inline]
public float Angle => Math.Atan2(Y, X);
[Inline]
public Point Round()
{
@ -67,6 +70,12 @@ namespace Strawberry
return Transform(this, mat);
}
[Inline]
static public Vector FromAngle(float radians)
{
return .(Math.Cos(radians), Math.Sin(radians));
}
[Inline]
static public Vector Lerp(Vector a, Vector b, float t)
{