feat: Point2D Record
This commit is contained in:
parent
c24f71c4af
commit
ea92bc8c07
|
@ -0,0 +1,19 @@
|
|||
using System;
|
||||
|
||||
namespace Syntriax.Engine.Physics2D.Primitives;
|
||||
|
||||
public record Point2D(float X, float Y)
|
||||
{
|
||||
public static Point2D operator +(Point2D left, Point2D right) => new(left.X + right.X, left.Y + right.Y);
|
||||
public static Point2D operator -(Point2D left, Point2D right) => new(left.X - right.X, left.Y - right.Y);
|
||||
public static Point2D operator *(Point2D point, float value) => new(point.X * value, point.Y * value);
|
||||
public static Point2D operator /(Point2D point, float value) => new(point.X / value, point.Y / value);
|
||||
|
||||
public static float Length(Point2D point) => MathF.Sqrt(LengthSqr(point));
|
||||
public static float LengthSqr(Point2D point) => point.X * point.X + point.Y * point.Y;
|
||||
|
||||
public static Point2D Normalize(Point2D point) => point / Length(point);
|
||||
public static float Cross(Point2D left, Point2D right) => left.X * right.Y - left.Y * right.X;
|
||||
public static float Angle(Point2D left, Point2D right) => MathF.Acos(Dot(left, right) / (Length(left) * Length(right)));
|
||||
public static float Dot(Point2D left, Point2D right) => left.X * right.X + left.Y * right.Y;
|
||||
}
|
Loading…
Reference in New Issue