/// <summary> /// Gets the cycle offset for a time value. /// </summary> /// <typeparam name="T">The type of animation value.</typeparam> /// <param name="time">The time value.</param> /// <param name="startTime">The start time.</param> /// <param name="endTime">The end time.</param> /// <param name="startValue">In: The animation value at <paramref name="startTime"/>.</param> /// <param name="endValue">In: The animation value at <paramref name="endTime"/>.</param> /// <param name="traits">The traits of the animation value.</param> /// <param name="loopBehavior">The post-loop behavior.</param> /// <param name="cycleOffset"> /// Out: The cycle offset. /// </param> /// <remarks> /// The cycle offset is <see cref="IAnimationValueTraits{T}.SetIdentity"/> if the /// <see cref="LoopBehavior"/> is unequal to <see cref="LoopBehavior.CycleOffset"/> or if the /// <paramref name="time"/> is in the regular cycle (between the first and the last key frame). /// </remarks> internal static void GetCycleOffset <T>(TimeSpan time, TimeSpan startTime, TimeSpan endTime, ref T startValue, ref T endValue, IAnimationValueTraits <T> traits, LoopBehavior loopBehavior, ref T cycleOffset) { Debug.Assert(endTime > startTime, "Invalid start and end time."); TimeSpan length = endTime - startTime; // Handle cycle offset. if (loopBehavior == LoopBehavior.CycleOffset && length != TimeSpan.Zero) { traits.Invert(ref startValue, ref startValue); traits.Add(ref startValue, ref endValue, ref cycleOffset); if (time < startTime) { long numberOfPeriods = (time.Ticks - endTime.Ticks) / length.Ticks; Debug.Assert(numberOfPeriods < 0, "Negative number of periods expected."); traits.Multiply(ref cycleOffset, (int)numberOfPeriods, ref cycleOffset); } else if (time > endTime) { long numberOfPeriods = (time.Ticks - startTime.Ticks) / length.Ticks; Debug.Assert(numberOfPeriods > 0, "Positive number of periods expected."); traits.Multiply(ref cycleOffset, (int)numberOfPeriods, ref cycleOffset); } else { traits.SetIdentity(ref cycleOffset); } } }
public static T Multiply <T>(this IAnimationValueTraits <T> traits, T value, int factor) { traits.Multiply(ref value, factor, ref value); return(value); }