LineRange.cs 2.1 KB

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