public double Distance(double2 v) { double2 delta = v - this; double len = delta.Dot(delta); return (double)System.Math.Sqrt((double)len); }
public double2(double2 f) { x = f.x; y = f.y; }
public static double2 Lerp(double2 a, double2 b, double alpha) { return (a * (1.0f - alpha)) + (b * alpha); }
public double2 Rotate(double rot) { double2 result = new double2(); result.x = (double)(System.Math.Cos(rot) * x - System.Math.Sin(rot) * y); result.y = (double)(System.Math.Sin(rot) * x + System.Math.Cos(rot) * y); return result; }
public double2 Saturate(double2 v) { return v.Min(new double2(1, 1)).Max(new double2(0, 0)); }
public double2 Reflect(double2 normal) { return this - normal * this.Dot(normal) * 2.0f; //v = i - 2 * dot(i, n) * n. }
public double2 PowSign(double v) { double2 ret = new double2(); ret.x = System.Math.Sign(x) * (double)System.Math.Pow(System.Math.Abs(x), v); ret.y = System.Math.Sign(y) * (double)System.Math.Pow(System.Math.Abs(y), v); return ret; }
public double2 Min(double2 v) { double2 ret = new double2(); ret.x = x < v.x ? x : v.x; ret.y = y < v.y ? y : v.y; return ret; }
public double2 Max(double2 v) { double2 ret = new double2(); ret.x = x > v.x ? x : v.x; ret.y = y > v.y ? y : v.y; return ret; }
// math functions public double Dot(double2 v) { return (x * v.x) + (y * v.y); }