mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Struct helpers
This commit is contained in:
parent
d9c75b1e0d
commit
3aff5a3c3f
|
@ -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)
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user