RegionOp.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #nullable enable
  2. namespace Terminal.Gui;
  3. /// <summary>
  4. /// Specifies the operation to perform when combining two regions or a <see cref="Region"/> with a
  5. /// <see cref="Rectangle"/>>, defining how their
  6. /// rectangular areas are merged, intersected, or subtracted.
  7. /// </summary>
  8. /// <remarks>
  9. /// <para>
  10. /// Each operation modifies the first region's set of rectangles based on the second (op) region or rectangle,
  11. /// producing a new set of non-overlapping rectangles. The operations align with set theory, enabling flexible
  12. /// manipulation for TUI layout, clipping, or drawing. Developers can choose between granular outputs (e.g.,
  13. /// <see cref="Union"/>) that preserve detailed rectangles or minimal outputs (e.g., <see cref="MinimalUnion"/>)
  14. /// that reduce the rectangle count for compactness.
  15. /// </para>
  16. /// </remarks>
  17. public enum RegionOp
  18. {
  19. /// <summary>
  20. /// Subtracts the second (op) region or rectangle from the first region, removing any areas where the op overlaps
  21. /// the first region. The result includes only the portions of the first region that do not intersect with the op.
  22. /// <para>
  23. /// For example, if the first region contains rectangle A = (0,0,10,10) and the op is B = (5,5,5,5), the result
  24. /// would include rectangles covering A minus the overlapping part of B, such as (0,0,10,5), (0,5,5,5), and
  25. /// (5,10,5,5).
  26. /// </para>
  27. /// <para>
  28. /// If the op region is empty or null, the operation has no effect unless the first region is also empty, in
  29. /// which case it clears the first region.
  30. /// </para>
  31. /// </summary>
  32. Difference = 0,
  33. /// <summary>
  34. /// Intersects the first region with the second (op) region or rectangle, retaining only the areas where both
  35. /// regions overlap. The result includes rectangles covering the common areas, excluding any parts unique to either
  36. /// region.
  37. /// <para>
  38. /// For example, if the first region contains A = (0,0,10,10) and the op is B = (5,5,5,5), the result would be
  39. /// a single rectangle (5,5,5,5), representing the intersection.
  40. /// </para>
  41. /// <para>
  42. /// If either region is empty or null, the result clears the first region, as there’s no intersection possible.
  43. /// </para>
  44. /// </summary>
  45. Intersect = 1,
  46. /// <summary>
  47. /// Performs a union (inclusive-or) of the first region and the second (op) region or rectangle, combining all
  48. /// areas covered by either region into a single contiguous region without holes (unless explicitly subtracted).
  49. /// <para>
  50. /// The formal union (∪) includes all points in at least one rectangle, producing a granular set of
  51. /// non-overlapping rectangles that cover the combined area. For example, if the first region contains A =
  52. /// (0,0,5,5) and the op is B = (5,0,5,5), the result might include (0,0,5,5) and (5,0,5,5) unless minimized.
  53. /// </para>
  54. /// <para>
  55. /// This operation uses granular output (preserving detailed rectangles). To minimize the result use
  56. /// <see cref="MinimalUnion"/> instead.
  57. /// </para>
  58. /// <para>
  59. /// If the op region is empty or null, the first region remains unchanged.
  60. /// </para>
  61. /// </summary>
  62. Union = 2,
  63. /// <summary>
  64. /// Performs a minimal union (inclusive-or) of the first region and the second (op) region or rectangle, merging adjacent or
  65. /// overlapping rectangles into the smallest possible set of non-overlapping rectangles that cover the combined
  66. /// area.
  67. /// <para>
  68. /// This operation minimizes the number of rectangles, producing a more compact representation compared to
  69. /// <see cref="Union"/>. For example, if the first region contains A = (0,0,5,5) and the op is B = (5,0,5,5),
  70. /// the result would be a single rectangle (0,0,10,5), reducing redundancy.
  71. /// </para>
  72. /// <para>
  73. /// This operation always minimizes the output and has lower performance than <see cref="Union"/>.
  74. /// </para>
  75. /// <para>
  76. /// If the op region is empty or null, the first region remains unchanged.
  77. /// </para>
  78. /// </summary>
  79. MinimalUnion = 3,
  80. /// <summary>
  81. /// Performs an exclusive-or (XOR) of the first region and the second (op) region or rectangle, retaining only the
  82. /// areas that are unique to each region—i.e., areas present in one region but not both.
  83. /// <para>
  84. /// For example, if the first region contains A = (0,0,10,10) and the op is B = (5,5,5,5), the result would
  85. /// include rectangles covering (0,0,10,5), (0,5,5,5), (5,10,5,5), and (5,5,5,5), excluding the intersection
  86. /// (5,5,5,5).
  87. /// </para>
  88. /// <para>
  89. /// If the op region is empty or null, this operation excludes the first region from itself (clearing it) or
  90. /// adds the first region to the op (if op is empty), depending on the logic.
  91. /// </para>
  92. /// </summary>
  93. XOR = 4,
  94. /// <summary>
  95. /// Subtracts the first region from the second (op) region or rectangle, retaining only the areas of the op that do
  96. /// not overlap with the first region. The result replaces the first region with these areas.
  97. /// <para>
  98. /// For example, if the first region contains A = (5,5,5,5) and the op is B = (0,0,10,10), the result would
  99. /// include rectangles covering B minus A, such as (0,0,10,5), (0,5,5,5), and (5,10,5,5).
  100. /// </para>
  101. /// <para>
  102. /// If the first region is empty or null, the op region replaces the first region. If the op region is empty,
  103. /// the first region is cleared.
  104. /// </para>
  105. /// </summary>
  106. ReverseDifference = 5,
  107. /// <summary>
  108. /// Replaces the first region entirely with the second (op) region or rectangle, discarding the first region's
  109. /// current rectangles and adopting the op's rectangles.
  110. /// <para>
  111. /// For example, if the first region contains (0,0,5,5) and the op is (10,10,5,5), the first region will be
  112. /// cleared and replaced with (10,10,5,5).
  113. /// </para>
  114. /// <para>
  115. /// If the op region is empty or null, the first region is cleared. This operation is useful for resetting or
  116. /// overwriting region state.
  117. /// </para>
  118. /// </summary>
  119. Replace = 6
  120. }