Example #1
0
        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));
        }
Example #2
0
        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);
        }
Example #3
0
 public static FVec2 Lerp(FVec2 from, FVec2 to, Fix64 t)
 {
     return(t <= Fix64.Zero ? from : (t >= Fix64.One ? to : LerpUnclamped(from, to, t)));
 }
Example #4
0
 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));
 }
Example #5
0
 public static Fix64 Dot(FVec2 v0, FVec2 v1)
 {
     return(v0.x * v1.x + v0.y * v1.y);
 }
Example #6
0
 public static FVec2 Normalize(FVec2 v)
 {
     return(v * (Fix64.One / Fix64.Sqrt(v.x * v.x + v.y * v.y)));
 }
Example #7
0
 public static Fix64 DistanceSquared(FVec2 v0, FVec2 v1)
 {
     return((v1 - v0).Dot());
 }
Example #8
0
 public bool ApproxEquals(FVec2 vector, Fix64 tolerance)
 {
     return(this.Distance(vector) <= tolerance);
 }
Example #9
0
 public static Fix64 Distance(FVec2 v0, FVec2 v1)
 {
     return((v1 - v0).Magnitude());
 }
Example #10
0
 public bool AproxEqualsBox(FVec2 vector, Fix64 tolerance)
 {
     return
         ((Fix64.Abs(this.x - vector.x) <= tolerance) &&
          (Fix64.Abs(this.y - vector.y) <= tolerance));
 }
Example #11
0
 public Fix64 Dot(FVec2 vector)
 {
     return(this.x * vector.x + this.y * vector.y);
 }
Example #12
0
 public void Scale(FVec2 scale)
 {
     this.x *= scale.x;
     this.y *= scale.y;
 }
Example #13
0
 public Fix64 DistanceSquared(FVec2 vector)
 {
     return((vector - this).Dot());
 }
Example #14
0
 public Fix64 Distance(FVec2 vector)
 {
     return((vector - this).Magnitude());
 }