30 #include "MeshKernel/Point.hpp"
43 BoundingBox() : m_lowerLeft(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest()),
44 m_upperRight(std::numeric_limits<double>::max(), std::numeric_limits<double>::max()) {}
68 void Reset(
const std::vector<T>& points);
76 void Reset(
const std::vector<T>& points,
size_t start,
size_t end);
84 BoundingBox(
const std::vector<T>& points,
size_t start,
size_t end)
86 Reset(points, start, end);
94 return other.m_lowerLeft != m_lowerLeft || other.m_upperRight != m_upperRight;
101 template <
typename T>
105 return point.x >= m_lowerLeft.
x && point.x <= m_upperRight.
x &&
106 point.y >= m_lowerLeft.
y && point.y <= m_upperRight.
y;
116 [[nodiscard]]
auto&
lowerLeft()
const {
return m_lowerLeft; }
120 [[nodiscard]]
auto&
upperRight()
const {
return m_upperRight; }
128 double Width()
const {
return m_upperRight.
x - m_lowerLeft.
x; }
132 double Height()
const {
return m_upperRight.
y - m_lowerLeft.
y; }
138 const double width =
Width();
139 const double height =
Height();
140 m_lowerLeft.
x -= width * factor;
141 m_lowerLeft.
y -= height * factor;
142 m_upperRight.
x += width * factor;
143 m_upperRight.
y += height * factor;
150 template <std::derived_from<Po
int> T>
153 const auto lowerLeftX = std::min(first.x, second.x);
154 const auto lowerLeftY = std::min(first.y, second.y);
155 const auto upperRightX = std::max(first.x, second.x);
156 const auto upperRightY = std::max(first.y, second.y);
158 return BoundingBox({lowerLeftX, lowerLeftY}, {upperRightX, upperRightY});
167 static BoundingBox Merge(
const BoundingBox& b1,
const BoundingBox& b2);
170 static BoundingBox CreateNonOverlappingBoundingBox();
174 template <
typename T>
178 if (points.size() > 0)
180 Reset(points, 0, points.size() - 1);
184 m_lowerLeft =
Point(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest());
185 m_upperRight =
Point(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
190 template <
typename T>
193 double minx = std::numeric_limits<double>::max();
194 double maxx = std::numeric_limits<double>::lowest();
195 double miny = std::numeric_limits<double>::max();
196 double maxy = std::numeric_limits<double>::lowest();
198 for (
size_t i = start; i <= end; ++i)
200 const auto& point = points[i];
204 minx = std::min(minx, point.x);
205 maxx = std::max(maxx, point.x);
206 miny = std::min(miny, point.y);
207 maxy = std::max(maxy, point.y);
210 m_lowerLeft =
Point(minx, miny);
211 m_upperRight =
Point(maxx, maxy);
219 return {lowerLeft, upperRight};
224 Point lowerLeft(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
225 Point upperRight(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest());
226 return {lowerLeft, upperRight};
231 return Vector(m_upperRight.x - m_lowerLeft.x, m_upperRight.y - m_lowerLeft.y);
236 const auto& otherLowerleft = other.
lowerLeft();
237 const auto& otherUpperRight = other.
upperRight();
238 if (m_upperRight.x < otherLowerleft.x ||
239 otherUpperRight.x < m_lowerLeft.x ||
240 m_upperRight.y < otherLowerleft.y ||
241 otherUpperRight.y < m_lowerLeft.y)