/// <summary> /// Construct an interpolation /// </summary> /// <param name="y0">min value on y axis</param> /// <param name="y1">max value on y axis</param> /// <param name="duration">duration of interpolation</param> /// <param name="ease">easing function</param> public Interpolation(float y0, float y1, float duration = 1, EEasingFunction ease = EEasingFunction.Linear) { if (duration == 0) { throw new ArgumentException("Duration cannot = 0 in an interpolation"); } Y1 = y1; Y0 = y0; Duration = duration; EasingFunction = ease; _ease = ease.Function(); YSpan = Y1 - Y0; }
public void Works() { // Arrange Interpolation interp = new Interpolation(1, 2, 2, EEasingFunction.Linear); // Act float t0 = interp.Interpolate(0); float t1 = interp.Interpolate(1); float t2 = interp.Interpolate(2); bool failed = false; foreach (EEasingFunction funcName in UTEnum.GetEnumAsArray <EEasingFunction>()) { DEasingFunction func = funcName.Function(); float zero = func(0); float one = func(1); if (zero != 0 || one != 1) { failed = true; break; } if (funcName.ToString().StartsWith("InOut")) { float point5 = func(0.5f); if (point5 != 0.5f) { failed = true; break; } } } // Assert Assert.That(t0 == 1); Assert.That(t1 == 1.5); Assert.That(t2 == 2); Assert.That(!failed); }