MathExtended.cs 3.2 KB

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