示例#1
0
        public static FixedPoint Atan2(FixedPoint y, FixedPoint x)
        {
            if (y.Equals(FixedPoint.Zero) && x.Equals(FixedPoint.Zero))
            {
                return(FixedPoint.Zero);
            }

            var coefficient1 = FixedPoint.Pi / FixedPoint.Four;
            var coefficient2 = FixedPoint.Three * coefficient1;
            var absY         = Abs(y) + FixedPoint.Kludge; // + 1e-10      // kludge to prevent 0/0 condition

            FixedPoint angle;

            if (x >= FixedPoint.Zero)
            {
                var r = (x - absY) / (x + absY);
                angle = coefficient1 - coefficient1 * r;
            }
            else
            {
                var r = (x + absY) / (absY - x);
                angle = coefficient2 - coefficient1 * r;
            }

            if (y < FixedPoint.Zero)
            {
                return(angle * FixedPoint.NegativeOne); // negate if in quad III or IV
            }
            return(angle);
        }
示例#2
0
        public static FixedPoint Round(FixedPoint fp)
        {
            var integer   = fp.Value >> FixedPoint.Q;
            var remainder = fp.Value - (integer << FixedPoint.Q);

            return(remainder >= FixedPoint.Half.Value
                ? FixedPoint.FromExplicit((integer + 1) << FixedPoint.Q)
                : FixedPoint.FromExplicit(integer << FixedPoint.Q));
        }
示例#3
0
        public static FixedPoint Ceiling(FixedPoint fp)
        {
            var integer   = fp.Value >> FixedPoint.Q;
            var remainder = fp.Value - (integer << FixedPoint.Q);

            return(remainder > 0
                ? FixedPoint.FromExplicit((integer + 1) << FixedPoint.Q)
                : FixedPoint.FromExplicit(integer << FixedPoint.Q));
        }
示例#4
0
        public static FixedPoint Abs(FixedPoint fp)
        {
            if (fp >= FixedPoint.Zero)
            {
                return(fp);
            }

            return(fp * FixedPoint.NegativeOne);
        }
示例#5
0
        public static FixedPoint Atan(FixedPoint fp)
        {
            if (!ProcessedTableService.Instance.AtanData.ContainsKey(fp.Value))
            {
                return(FixedPoint.NaN);
            }

            return(ProcessedTableService.Instance.AtanData[fp.Value]);
        }
示例#6
0
        public static FixedPoint Sign(FixedPoint fp)
        {
            if (fp.Equals(FixedPoint.Zero))
            {
                return(FixedPoint.Zero);
            }

            return(fp > FixedPoint.Zero ? FixedPoint.One : FixedPoint.NegativeOne);
        }
示例#7
0
        public static FixedPoint Acos(FixedPoint fp)
        {
            var data = ProcessedTableService.Instance.AcosData;

            if (!data.ContainsKey(fp.Value))
            {
                return(FixedPoint.NaN);
            }

            return(data[fp.Value]);
        }
示例#8
0
        public FixedPointVector2 NormalizeWithClampedMagnitude(FixedPoint clamp)
        {
            var magnitude = MathFixedPoint.ClampMagnitude(this, clamp);

            if (magnitude > FixedPoint.Zero)
            {
                return(this / magnitude);
            }

            return(this);
        }
示例#9
0
        public static FixedPoint Tanh(FixedPoint fp)
        {
            var sinh = Sinh(fp);
            var cosh = Cosh(fp);

            if (sinh.Equals(FixedPoint.Zero) || cosh.Equals(FixedPoint.Zero))
            {
                return(FixedPoint.Zero);
            }

            return(sinh / cosh);
        }
示例#10
0
        static FixedPoint TrigonometricLookup(FixedPoint fp, IReadOnlyDictionary <FixedPoint, FixedPoint> data)
        {
            var value = Round(Abs(fp) / FixedPoint.Pi * TrigonometricSteps);

            var flip = (Floor(value / TrigonometricSteps) % FixedPoint.Two).Equals(FixedPoint.Zero);

            var result = flip
                ? data[value % TrigonometricSteps]
                : data[value % TrigonometricSteps] * FixedPoint.NegativeOne;

            return(result);
        }
示例#11
0
        public static FixedPoint Tan(FixedPoint fp)
        {
            var sin = Sin(fp);
            var cos = Cos(fp);

            if (sin.Equals(FixedPoint.Zero) || cos.Equals(FixedPoint.Zero))
            {
                return(FixedPoint.Zero);
            }

            return(sin / cos);
        }
示例#12
0
        public static FixedPoint Sqrt2(FixedPoint fp)
        {
            var estimate = fp / FixedPoint.Two + FixedPoint.One;
            var n1       = (estimate + fp / estimate) / FixedPoint.Two;

            while (n1 < estimate)
            {
                estimate = n1;
                n1       = (estimate + fp / estimate) / FixedPoint.Two;
            }

            return(estimate);
        }
示例#13
0
        static FixedPoint HyperbolicLookup
            (FixedPoint fp, IReadOnlyDictionary <FixedPoint, FixedPoint> data, FixedPoint nanIfLessThan)
        {
            if (fp < nanIfLessThan)
            {
                return(FixedPoint.NaN);
            }

            if (fp > FixedPoint.Zero && fp < HyperbolicMediumResolution)
            {
                return(data[RoundToNearestStep(fp, HyperbolicHighResolutionStep)]);
            }

            if (fp >= HyperbolicMediumResolution && fp < HyperbolicLowResolution)
            {
                return(data[RoundToNearestStep(fp, HyperbolicMediumResolutionStep)]);
            }

            return(data[RoundToNearestStep(fp, HyperbolicLowResolutionStep)]);
        }
示例#14
0
        public static FixedPoint Sqrt(FixedPoint fp)
        {
            var data = ProcessedTableService.Instance.SqrtData;

            if (fp < FixedPoint.Zero)
            {
                return(FixedPoint.NaN);
            }

            if (fp > FixedPoint.Zero && fp < SqrtMediumResolution)
            {
                return(data[RoundToNearestStep(fp, SqrtHighResolutionStep)]);
            }

            if (fp >= SqrtMediumResolution && fp < SqrtLowResolution)
            {
                return(data[RoundToNearestStep(fp, SqrtMediumResolutionStep)]);
            }

            return(data[RoundToNearestStep(fp, SqrtLowResolutionStep)]);
        }
示例#15
0
 public FixedPointVector2 CloneWithReplacedX(FixedPoint x)
 {
     return(new FixedPointVector2(x, Y));
 }
示例#16
0
 public static FixedPoint Cos(FixedPoint fp)
 {
     return(TrigonometricLookup(fp, ProcessedTableService.Instance.CosData));
 }
示例#17
0
 public static FixedPoint Cosh(FixedPoint fp)
 {
     return(HyperbolicLookup(Abs(fp), ProcessedTableService.Instance.CoshData, FixedPoint.Zero));
 }
示例#18
0
 public static FixedPoint Asinh(FixedPoint fp)
 {
     return(HyperbolicLookup(fp, ProcessedTableService.Instance.AsinhData, FixedPoint.One));
 }
示例#19
0
 public static FixedPoint Sin(FixedPoint fp)
 {
     return(TrigonometricLookup(fp, ProcessedTableService.Instance.SinData) * Sign(fp));
 }
示例#20
0
 public static FixedPointVector2 From(int x, int y)
 {
     return(new FixedPointVector2(FixedPoint.From(x), FixedPoint.From(y)));
 }
示例#21
0
 public static FixedPointVector2 Interpolate(FixedPointVector2 v1, FixedPointVector2 v2, FixedPoint time)
 {
     return(new FixedPointVector2(v1.X * (FixedPoint.One - time) + v2.X * time
                                  , v1.Y * (FixedPoint.One - time) + v2.Y * time));
 }
示例#22
0
 public static FixedPoint Min(FixedPoint a, FixedPoint b)
 {
     return(a < b ? a : b);
 }
示例#23
0
 public static FixedPoint Sinh(FixedPoint fp)
 {
     return(HyperbolicLookup(Abs(fp), ProcessedTableService.Instance.SinhData, FixedPoint.Zero) * Sign(fp));
 }
示例#24
0
 public FixedPointVector2 CloneWithReplacedY(FixedPoint y)
 {
     return(new FixedPointVector2(X, y));
 }
示例#25
0
 public void Deconstruct(out float x, out float y)
 {
     x = FixedPoint.ConvertToFloat(X);
     y = FixedPoint.ConvertToFloat(Y);
 }
示例#26
0
 public static FixedPoint Max(FixedPoint a, FixedPoint b)
 {
     return(a >= b ? a : b);
 }
示例#27
0
 public static FixedPointVector2 From(FixedPoint x, FixedPoint y)
 {
     return(new FixedPointVector2(x, y));
 }
示例#28
0
 public static FixedPoint Floor(FixedPoint fp)
 {
     return(FixedPoint.FromExplicit((fp.Value >> FixedPoint.Q) << FixedPoint.Q));
 }
示例#29
0
 FixedPointVector2(FixedPoint x, FixedPoint y)
 {
     X = x;
     Y = y;
 }
示例#30
0
        public static FixedPoint RoundToNearestStep(FixedPoint fp, FixedPoint step)
        {
            var floored = Floor(fp / step) * step;

            return(fp - floored > step / FixedPoint.Half ? floored + step : floored);
        }