Engine-Pong/Game/Physics2D/Primitives/Vector2D.cs

20 lines
1.1 KiB
C#

using System;
namespace Syntriax.Engine.Physics2D.Primitives;
public record Vector2D(float X, float Y)
{
public static Vector2D operator +(Vector2D left, Vector2D right) => new(left.X + right.X, left.Y + right.Y);
public static Vector2D operator -(Vector2D left, Vector2D right) => new(left.X - right.X, left.Y - right.Y);
public static Vector2D operator *(Vector2D point, float value) => new(point.X * value, point.Y * value);
public static Vector2D operator /(Vector2D point, float value) => new(point.X / value, point.Y / value);
public static float Length(Vector2D point) => MathF.Sqrt(LengthSqr(point));
public static float LengthSqr(Vector2D point) => point.X * point.X + point.Y * point.Y;
public static Vector2D Normalize(Vector2D point) => point / Length(point);
public static float Cross(Vector2D left, Vector2D right) => left.X * right.Y - left.Y * right.X;
public static float Angle(Vector2D left, Vector2D right) => MathF.Acos(Dot(left, right) / (Length(left) * Length(right)));
public static float Dot(Vector2D left, Vector2D right) => left.X * right.X + left.Y * right.Y;
}