mirror of
				https://github.com/MaddyThorson/StrawberryBF.git
				synced 2025-11-04 01:41:33 +08:00 
			
		
		
		
	Struct helpers
This commit is contained in:
		@ -6,6 +6,9 @@ namespace Strawberry
 | 
				
			|||||||
		case Right = 1;
 | 
							case Right = 1;
 | 
				
			||||||
		case Left = -1;
 | 
							case Left = -1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Inline]
 | 
				
			||||||
 | 
							public float Angle => this == .Right ? Calc.Right : Calc.Left;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		public Facings Opposite()
 | 
							public Facings Opposite()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			if (this == .Right)
 | 
								if (this == .Right)
 | 
				
			||||||
 | 
				
			|||||||
@ -64,7 +64,7 @@ namespace Strawberry
 | 
				
			|||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		static public explicit operator Point(Vector a)
 | 
							static public explicit operator Point(Vector a)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return Point((int)a.X, (int)a.Y);
 | 
								return .((int)a.X, (int)a.Y);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
@ -82,37 +82,49 @@ namespace Strawberry
 | 
				
			|||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		static public Point operator+(Point a, Point b)
 | 
							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]
 | 
							[Inline]
 | 
				
			||||||
		static public Point operator-(Point a, Point b)
 | 
							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]
 | 
							[Inline, Commutable]
 | 
				
			||||||
		static public Point operator*(Point a, int b)
 | 
							static public Point operator*(Point a, int b)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
			return Point(a.X * b, a.Y * b);
 | 
								return .(a.X * b, a.Y * b);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		static public Point operator*(Point a, Point b)
 | 
							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]
 | 
							[Inline]
 | 
				
			||||||
		static public Point operator/(Point a, int b)
 | 
							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]
 | 
							[Inline]
 | 
				
			||||||
		static public Point operator/(Point a, Point b)
 | 
							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]
 | 
							[Inline, Commutable]
 | 
				
			||||||
 | 
				
			|||||||
@ -49,6 +49,9 @@ namespace Strawberry
 | 
				
			|||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		public float LengthSquared => X * X + Y * Y;
 | 
							public float LengthSquared => X * X + Y * Y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Inline]
 | 
				
			||||||
 | 
							public float Angle => Math.Atan2(Y, X);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		public Point Round()
 | 
							public Point Round()
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
@ -67,6 +70,12 @@ namespace Strawberry
 | 
				
			|||||||
			return Transform(this, mat);
 | 
								return Transform(this, mat);
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							[Inline]
 | 
				
			||||||
 | 
							static public Vector FromAngle(float radians)
 | 
				
			||||||
 | 
							{
 | 
				
			||||||
 | 
								return .(Math.Cos(radians), Math.Sin(radians));
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		[Inline]
 | 
							[Inline]
 | 
				
			||||||
		static public Vector Lerp(Vector a, Vector b, float t)
 | 
							static public Vector Lerp(Vector a, Vector b, float t)
 | 
				
			||||||
		{
 | 
							{
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user