LineRange.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Numerics;
  4. using System.Runtime.CompilerServices;
  5. using System.Text;
  6. namespace Veldrid.Common
  7. {
  8. public struct LineRange
  9. {
  10. public static implicit operator Vector4(LineRange range)
  11. {
  12. return new Vector4(range.MinX, range.MaxX, range.MinY, range.MaxY);
  13. }
  14. public static LineRange Zero { get; } = new LineRange(0, 0, 0, 0);
  15. public UInt32 Size { get; } = (uint)Unsafe.SizeOf<Vector4>();
  16. private float minX;
  17. private float maxX;
  18. private float minY;
  19. private float maxY;
  20. internal LineRange(float minX, float maxX, float minY, float maxY)
  21. {
  22. this.minX = minX;
  23. this.maxX = maxX;
  24. this.minY = minY;
  25. this.maxY = maxY;
  26. }
  27. public void SetLineRange(float minX, float maxX, float minY, float maxY)
  28. {
  29. MinX = minX;
  30. MaxX = maxX;
  31. MinY = minY;
  32. MaxY = maxY;
  33. }
  34. public float XLenght => MaxX - MinX;
  35. public float YLenght => MaxY - MinY;
  36. public Boolean IsEmpty => MinX >= MaxX || MinY >= MaxY;
  37. public float MinX
  38. {
  39. get => minX;
  40. set
  41. {
  42. if (minX != value)
  43. {
  44. minX = value;
  45. }
  46. }
  47. }
  48. public float MaxX
  49. {
  50. get => maxX;
  51. set
  52. {
  53. if (maxX != value)
  54. {
  55. maxX = value;
  56. }
  57. }
  58. }
  59. public float MinY
  60. {
  61. get => minY;
  62. set
  63. {
  64. if (minY != value)
  65. {
  66. minY = value;
  67. }
  68. }
  69. }
  70. public float MaxY
  71. {
  72. get => maxY;
  73. set
  74. {
  75. if (maxY != value)
  76. {
  77. maxY = value;
  78. }
  79. }
  80. }
  81. }
  82. }