BoundingBox represents the minimum bounding rectangle (or box) for a geometry. It supports up to 4 dimensions (X, Y, Z, M).
| 67 | // BoundingBox represents the minimum bounding rectangle (or box) for a geometry. |
| 68 | // It supports up to 4 dimensions (X, Y, Z, M). |
| 69 | struct BoundingBox { |
| 70 | using XY = std::array<double, 2>; |
| 71 | using XYZ = std::array<double, 3>; |
| 72 | using XYM = std::array<double, 3>; |
| 73 | using XYZM = std::array<double, 4>; |
| 74 | |
| 75 | // Default constructor: initializes to an empty bounding box. |
| 76 | BoundingBox() : min{INF, INF, INF, INF}, max{-INF, -INF, -INF, -INF} {} |
| 77 | // Constructor with explicit min/max values. |
| 78 | BoundingBox(const XYZM& mins, const XYZM& maxes) : min(mins), max(maxes) {} |
| 79 | BoundingBox(const BoundingBox& other) = default; |
| 80 | BoundingBox& operator=(const BoundingBox&) = default; |
| 81 | |
| 82 | // Update the bounding box to include a 2D coordinate. |
| 83 | void updateXY(const XY& coord) { |
| 84 | updateInternal(coord); |
| 85 | } |
| 86 | // Update the bounding box to include a 3D coordinate (XYZ). |
| 87 | void updateXYZ(const XYZ& coord) { |
| 88 | updateInternal(coord); |
| 89 | } |
| 90 | // Update the bounding box to include a 3D coordinate (XYM). |
| 91 | void updateXYM(const XYM& coord) { |
| 92 | std::array<int, 3> dims = {0, 1, 3}; |
| 93 | for (int i = 0; i < 3; ++i) { |
| 94 | auto dim = dims[i]; |
| 95 | if (!std::isnan(min[dim]) && !std::isnan(max[dim])) { |
| 96 | min[dim] = std::min(min[dim], coord[i]); |
| 97 | max[dim] = std::max(max[dim], coord[i]); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 | // Update the bounding box to include a 4D coordinate (XYZM). |
| 102 | void updateXYZM(const XYZM& coord) { |
| 103 | updateInternal(coord); |
| 104 | } |
| 105 | |
| 106 | // Reset the bounding box to its initial empty state. |
| 107 | void reset() { |
| 108 | for (int i = 0; i < MAX_DIMENSIONS; ++i) { |
| 109 | min[i] = INF; |
| 110 | max[i] = -INF; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | // Invalidate the bounding box (set all values to NaN). |
| 115 | void invalidate() { |
| 116 | for (int i = 0; i < MAX_DIMENSIONS; ++i) { |
| 117 | min[i] = std::numeric_limits<double>::quiet_NaN(); |
| 118 | max[i] = std::numeric_limits<double>::quiet_NaN(); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | // Check if the bound for a given dimension is empty. |
| 123 | bool boundEmpty(int dim) const { |
| 124 | return std::isinf(min[dim] - max[dim]); |
| 125 | } |
| 126 |
no outgoing calls
no test coverage detected