MathExtended.cs 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using Microsoft.Xna.Framework;
  2. namespace MonoGame.Extended;
  3. public static class MathExtended
  4. {
  5. public const float Epsilon = 0.0001f;
  6. /// <summary>
  7. /// Represents the smallest positive value that can be added to 1.0 to produce a distinguishable result.
  8. /// This value is approximately 1.19209290e-7 and is useful for floating-point comparisons.
  9. /// </summary>
  10. public const float MachineEpsilon = 1.19209290e-7f;
  11. /// <summary>
  12. /// Calculates a new <see cref="Vector2"/> with the component-wise minimum values from two given
  13. /// <see cref="Vector2"/> values.
  14. /// </summary>
  15. /// <param name="first">The first Vector2 value.</param>
  16. /// <param name="second">The second Vector2 value.</param>
  17. /// <returns>
  18. /// The calculated <see cref="Vector2"/> value with the component-wise minimum values.</returns>
  19. public static Vector2 CalculateMinimumVector2(Vector2 first, Vector2 second)
  20. {
  21. return new Vector2
  22. {
  23. X = first.X < second.X ? first.X : second.X,
  24. Y = first.Y < second.Y ? first.Y : second.Y
  25. };
  26. }
  27. /// <summary>
  28. /// Calculates a new <see cref="Vector2"/> with the component-wise minimum values from two given
  29. /// <see cref="Vector2"/> values.
  30. /// </summary>
  31. /// <param name="first">The first Vector2 value.</param>
  32. /// <param name="second">The second Vector2 value.</param>
  33. /// <param name="result">
  34. /// When this method returns, contains the calculated <see cref="Vector2"/> value with the component-wise minimum
  35. /// values. This parameter is passed uninitialized.
  36. /// </param>
  37. public static void CalculateMinimumVector2(Vector2 first, Vector2 second, out Vector2 result)
  38. {
  39. result.X = first.X < second.X ? first.X : second.X;
  40. result.Y = first.Y < second.Y ? first.Y : second.Y;
  41. }
  42. /// <summary>
  43. /// Calculates a new <see cref="Vector2"/> with the component-wise minimum values from two given
  44. /// <see cref="Vector2"/> values.
  45. /// </summary>
  46. /// <param name="first">The first Vector2 value.</param>
  47. /// <param name="second">The second Vector2 value.</param>
  48. /// <returns>The calculated <see cref="Vector2"/> value with the component-wise maximum values.</returns>
  49. public static Vector2 CalculateMaximumVector2(Vector2 first, Vector2 second)
  50. {
  51. return new Vector2
  52. {
  53. X = first.X > second.X ? first.X : second.X,
  54. Y = first.Y > second.Y ? first.Y : second.Y
  55. };
  56. }
  57. /// <summary>
  58. /// Calculates a new <see cref="Vector2"/> with the component-wise values from two given
  59. /// <see cref="Vector2"/> values.
  60. /// </summary>
  61. /// <param name="first">The first Vector2 value.</param>
  62. /// <param name="second">The second Vector2 value.</param>
  63. /// <param name="result">
  64. /// When this method returns, contains the calculated <see cref="Vector2"/> value with the component-wise maximum
  65. /// values. This parameter is passed uninitialized.
  66. /// </param>
  67. public static void CalculateMaximumVector2(Vector2 first, Vector2 second, out Vector2 result)
  68. {
  69. result.X = first.X > second.X ? first.X : second.X;
  70. result.Y = first.Y > second.Y ? first.Y : second.Y;
  71. }
  72. }