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); }
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)); }
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)); }
public static FixedPoint Abs(FixedPoint fp) { if (fp >= FixedPoint.Zero) { return(fp); } return(fp * FixedPoint.NegativeOne); }
public static FixedPoint Atan(FixedPoint fp) { if (!ProcessedTableService.Instance.AtanData.ContainsKey(fp.Value)) { return(FixedPoint.NaN); } return(ProcessedTableService.Instance.AtanData[fp.Value]); }
public static FixedPoint Sign(FixedPoint fp) { if (fp.Equals(FixedPoint.Zero)) { return(FixedPoint.Zero); } return(fp > FixedPoint.Zero ? FixedPoint.One : FixedPoint.NegativeOne); }
public static FixedPoint Acos(FixedPoint fp) { var data = ProcessedTableService.Instance.AcosData; if (!data.ContainsKey(fp.Value)) { return(FixedPoint.NaN); } return(data[fp.Value]); }
public FixedPointVector2 NormalizeWithClampedMagnitude(FixedPoint clamp) { var magnitude = MathFixedPoint.ClampMagnitude(this, clamp); if (magnitude > FixedPoint.Zero) { return(this / magnitude); } return(this); }
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); }
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); }
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); }
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); }
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)]); }
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)]); }
public FixedPointVector2 CloneWithReplacedX(FixedPoint x) { return(new FixedPointVector2(x, Y)); }
public static FixedPoint Cos(FixedPoint fp) { return(TrigonometricLookup(fp, ProcessedTableService.Instance.CosData)); }
public static FixedPoint Cosh(FixedPoint fp) { return(HyperbolicLookup(Abs(fp), ProcessedTableService.Instance.CoshData, FixedPoint.Zero)); }
public static FixedPoint Asinh(FixedPoint fp) { return(HyperbolicLookup(fp, ProcessedTableService.Instance.AsinhData, FixedPoint.One)); }
public static FixedPoint Sin(FixedPoint fp) { return(TrigonometricLookup(fp, ProcessedTableService.Instance.SinData) * Sign(fp)); }
public static FixedPointVector2 From(int x, int y) { return(new FixedPointVector2(FixedPoint.From(x), FixedPoint.From(y))); }
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)); }
public static FixedPoint Min(FixedPoint a, FixedPoint b) { return(a < b ? a : b); }
public static FixedPoint Sinh(FixedPoint fp) { return(HyperbolicLookup(Abs(fp), ProcessedTableService.Instance.SinhData, FixedPoint.Zero) * Sign(fp)); }
public FixedPointVector2 CloneWithReplacedY(FixedPoint y) { return(new FixedPointVector2(X, y)); }
public void Deconstruct(out float x, out float y) { x = FixedPoint.ConvertToFloat(X); y = FixedPoint.ConvertToFloat(Y); }
public static FixedPoint Max(FixedPoint a, FixedPoint b) { return(a >= b ? a : b); }
public static FixedPointVector2 From(FixedPoint x, FixedPoint y) { return(new FixedPointVector2(x, y)); }
public static FixedPoint Floor(FixedPoint fp) { return(FixedPoint.FromExplicit((fp.Value >> FixedPoint.Q) << FixedPoint.Q)); }
FixedPointVector2(FixedPoint x, FixedPoint y) { X = x; Y = y; }
public static FixedPoint RoundToNearestStep(FixedPoint fp, FixedPoint step) { var floored = Floor(fp / step) * step; return(fp - floored > step / FixedPoint.Half ? floored + step : floored); }