diff --git a/LinearAlgebra/Vector2.cs b/LinearAlgebra/Vector2.cs index 88bc2de..e76d12a 100644 --- a/LinearAlgebra/Vector2.cs +++ b/LinearAlgebra/Vector2.cs @@ -1,6 +1,9 @@ +using System; +using System.Numerics; + namespace Passer.LinearAlgebra { - public class Vector2Of { + public class Vector2Of where T : IComparable { public T x; public T y; @@ -12,8 +15,37 @@ namespace Passer.LinearAlgebra { public class Vector2Int : Vector2Of { public Vector2Int(int x, int y) : base(x, y) { } + + public static Vector2Int operator -(Vector2Int v1, Vector2Int v2) { + return new Vector2Int(v1.x - v2.x, v1.y - v2.y); + } + + public float magnitude { + get { + return (float)Math.Sqrt(this.x * this.x + this.y * this.y); + } + } + + public static float Distance(Vector2Int v1, Vector2Int v2) { + return (v1 - v2).magnitude; + } } + public class Vector2Float : Vector2Of { public Vector2Float(float x, float y) : base(x, y) { } + + public static Vector2Float operator -(Vector2Float v1, Vector2Float v2) { + return new Vector2Float(v1.x - v2.x, v1.y - v2.y); + } + + public float magnitude { + get { + return (float)Math.Sqrt(this.x * this.x + this.y * this.y); + } + } + + public static float Distance(Vector2Float v1, Vector2Float v2) { + return (v1 - v2).magnitude; + } } } \ No newline at end of file