feat: Point2D Record

This commit is contained in:
Syntriax 2024-01-22 12:29:25 +03:00
parent c24f71c4af
commit ea92bc8c07
1 changed files with 19 additions and 0 deletions

View File

@ -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;
}