LinearOperations.cs 747 B

123456789101112131415161718192021
  1. using System;
  2. using System.Linq.Expressions;
  3. namespace MonoGame.Extended.Tweening;
  4. public class LinearOperations<T>
  5. {
  6. static LinearOperations()
  7. {
  8. var a = Expression.Parameter(typeof(T));
  9. var b = Expression.Parameter(typeof(T));
  10. var c = Expression.Parameter(typeof(float));
  11. Add = Expression.Lambda<Func<T, T, T>>(Expression.Add(a, b), a, b).Compile();
  12. Subtract = Expression.Lambda<Func<T, T, T>>(Expression.Subtract(a, b), a, b).Compile();
  13. Multiply = Expression.Lambda<Func<T, float, T>>(Expression.Multiply(a, c), a, c).Compile();
  14. }
  15. public static Func<T, T, T> Add { get; }
  16. public static Func<T, T, T> Subtract { get; }
  17. public static Func<T, float, T> Multiply { get; }
  18. }