public static void TestLookupSin() { var xv = VFloat(); var fsin = Ex.Lambda <FXY>(ExMHelpers.dLookupSinRad(xv.As <double>()), xv).Compile(); for (float x = -16.5f; x < 16.5f; x += 0.0001f) { AreEqual(fsin(x), Mathf.Sin(x), 0.00001f); } }
/// <summary> /// Switch between two functions such that the second function continues where the first left off. /// Eg. Switching from the polar equation (r=1, th=90t) to the xy equation (x=t,y=0) yields: /// t = 3 -> (0, -1) /// t = 4 -> (1, -1) /// t = 5 -> (2, -1) /// </summary> /// <param name="pivotVar">The variable upon which pivoting is performed. Should be either "p" (firing index) or "t" (time).</param> /// <param name="pivot">The value of the variable at which pivoting is performed</param> /// <param name="f1">Starting equation</param> /// <param name="f2">Equation after pivot</param> /// <returns></returns> public static ExTP Pivot(ExBPY pivotVar, ExBPY pivot, ExTP f1, ExTP f2) => ExMHelpers.Pivot <TExPI, Vector2>( pivot, f1, f2, pivotVar);
public static ExTP LaserRotateLerp(ExBPY rate, ExTP from, ExTP to) => bpi => ExMHelpers.LaserRotateLerp(to(bpi), from(bpi), bpi, rate(bpi));
/// <summary> /// Rotate between two parametrics (the magnitude of the resulting vector is the magnitude of the <paramref name="from"/> vector), closing <paramref name="rate"/> degrees of the gap per second. /// <para>This function uses the last returned value as its rotation source, only sampling the source parametric once.</para> /// </summary> /// <param name="rate">Degrees of gap to close per second</param> /// <param name="from">Source parametric</param> /// <param name="to">Target parametric</param> /// <returns></returns> public static ExTP TrueRotateLerpRate(ExBPY rate, ExTP from, ExTP to) { return(bpi => ExMHelpers.RotateLerp(to(bpi), from(bpi), bpi, true, true, rate(bpi))); }
/// <summary> /// Rotate between two parametrics (the magnitude of the resulting vector is the magnitude of the <paramref name="from"/> vector), closing <paramref name="ratio"/> fraction of the gap per second. /// <para>This function uses the last returned value as its rotation source, only sampling the source parametric once.</para> /// </summary> /// <remarks> /// Ratio is not multiplicative as in RotateLerpPercent. Instead, it accumulates like the function 1-e^-rt. /// This means that the rotation is faster during the first second than the second second, and so on. /// Use TrueRotateLerpRate for constant rotation rates. /// </remarks> /// <param name="ratio">Fraction of gap to close per second</param> /// <param name="from">Source parametric</param> /// <param name="to">Target parametric</param> /// <returns></returns> public static ExTP TrueRotateLerpPercent(ExBPY ratio, ExTP from, ExTP to) { return(bpi => ExMHelpers.RotateLerp(to(bpi), from(bpi), bpi, false, true, ratio(bpi))); }
/// <summary> /// See <see cref="BPYRepo.SoftmaxShift"/>. /// </summary> public static ExBPY SoftmaxShift(ExBPY sharpness, ExBPY pivot, ExBPY f1, ExBPY f2) => ExMHelpers.SoftmaxShift <TEx <float> >(sharpness, pivot, f1, f2, "x");
/// <summary> /// Apply a ease function on top of a target derivative function that uses time as a controller. /// </summary> /// <param name="smoother">Smoothing function (<see cref="ExMEasers"/>)</param> /// <param name="maxTime">Time over which to perform easing</param> /// <param name="fd">Target function</param> /// <returns></returns> public static ExBPY EaseFD([LookupMethod] Func <TEx <float>, TEx <float> > smoother, float maxTime, ExBPY fd) => ExMHelpers.EaseD(smoother, maxTime, fd, x => x.FloatVal, (x, y) => x.MakeCopyForType <TEx <float> >(y));
/// <summary> /// See <see cref="BPYRepo.SoftmaxShift"/>. /// </summary> public static ExBPY LogsumShift(string pivotVar, ExBPY sharpness, ExBPY pivot, ExBPY f1, ExBPY f2) => ExMHelpers.LogSumShift <TExPI>(sharpness, pivot, f1, f2, pivotVar);
/* * public static ExBPY Softmax(ExBPY sharpness, ExBPY[] against) => bpi => GenericMath.Softmax(sharpness(bpi), against.Select(x => x(bpi)).ToArray()); * * public static ExBPY Logsum(ExBPY sharpness, ExBPY[] against) => ExM.LogSum(sharpness, against); */ /// <summary> /// Smoothly pivot from one function to another. /// Functionality is similar to Pivot, but you must specify the direction, and because this relies on softmax, /// the value f2(t) - f2(pivot) + f1(pivot) must always be greater than f1(pivot) after the pivot point /// and less than before the pivot point (when sharpness is positive). /// </summary> /// <param name="pivotVar">The variable upon which pivoting is performed. Should be either "p" (firing index) or "t" (time) or a reference variable.</param> /// <param name="sharpness">The higher the absolute value of this, the more quickly the result will converge. /// Set negative for softmin.</param> /// <param name="pivot">The value of the variable at which pivoting is performed</param> /// <param name="f1">Starting equation</param> /// <param name="f2">Equation after pivot</param> /// <returns></returns> public static ExBPY SoftmaxShift(string pivotVar, ExBPY sharpness, ExBPY pivot, ExBPY f1, ExBPY f2) => ExMHelpers.SoftmaxShift <TExPI>(sharpness, pivot, f1, f2, pivotVar);
/// <summary> /// See <see cref="Parametrics.Pivot"/>. /// </summary> public static ExBPY Pivot(ExBPY pivotVar, ExBPY pivot, ExBPY f1, ExBPY f2) => ExMHelpers.Pivot <TExPI, float>(pivot, f1, f2, pivotVar);
/// <summary> /// Rotate a Vector3 by a quaternion. In Unity the rotation order is ZXY. /// The z-axis is mapped to IN. /// </summary> /// <param name="rotateBy">Quaternion rotation, in degrees, xyz</param> /// <param name="target">Target Vector3</param> /// <returns></returns> public static tv3 QRotate(tv3 rotateBy, tv3 target) => ExMHelpers.QRotate(QuaternionEuler(rotateBy), target);