2025-02-07 14:51:31 +01:00

51 lines
1.3 KiB
C#

using System;
using System.Numerics;
namespace Passer.LinearAlgebra {
public class Vector2Of<T> where T : IComparable<T> {
public T x;
public T y;
public Vector2Of(T x, T y) {
this.x = x;
this.y = y;
}
}
public class Vector2Int : Vector2Of<int> {
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<float> {
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;
}
}
}