public static FVec2 NormalizeSafe(FVec2 v) { Fix64 dis = Fix64.Sqrt(v.x * v.x + v.y * v.y); if (dis == Fix64.Zero) { return(new FVec2()); } return(v * (Fix64.One / dis)); }
public static FVec2 ClampMagnitude(FVec2 v, Fix64 maxLength) { FVec2 nor = v; Fix64 sqrMagnitude = nor.SqrMagnitude(); if (sqrMagnitude > (maxLength * maxLength)) { nor = nor * (maxLength / Fix64.Sqrt(sqrMagnitude)); } return(nor); }
public static FVec2 Lerp(FVec2 from, FVec2 to, Fix64 t) { return(t <= Fix64.Zero ? from : (t >= Fix64.One ? to : LerpUnclamped(from, to, t))); }
public static FVec2 LerpUnclamped(FVec2 from, FVec2 to, Fix64 t) { return(new FVec2(from.x + (to.x - from.x) * t, from.y + (to.y - from.y) * t)); }
public static Fix64 Dot(FVec2 v0, FVec2 v1) { return(v0.x * v1.x + v0.y * v1.y); }
public static FVec2 Normalize(FVec2 v) { return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y))); }
public static Fix64 Distance(FVec2 v0, FVec2 v1) { return((v1 - v0).Magnitude()); }
public static Fix64 DistanceSquared(FVec2 v0, FVec2 v1) { return((v1 - v0).Dot()); }
public bool AproxEqualsBox(FVec2 vector, Fix64 tolerance) { return ((Fix64.Abs(this.x - vector.x) <= tolerance) && (Fix64.Abs(this.y - vector.y) <= tolerance)); }
public bool ApproxEquals(FVec2 vector, Fix64 tolerance) { return(this.Distance(vector) <= tolerance); }
public Fix64 Dot(FVec2 vector) { return(this.x * vector.x + this.y * vector.y); }
public void Scale(FVec2 scale) { this.x *= scale.x; this.y *= scale.y; }
public Fix64 DistanceSquared(FVec2 vector) { return((vector - this).Dot()); }
public Fix64 Distance(FVec2 vector) { return((vector - this).Magnitude()); }
public void Set(FVec2 v) { this.x = v.x; this.y = v.y; }