30#include "MeshKernel/Point.hpp"
46 BoundingBox() : m_lowerLeft(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest()),
47 m_upperRight(std::numeric_limits<double>::max(), std::numeric_limits<double>::max()) {}
82 BoundingBox(
const std::vector<T>& points,
size_t start,
size_t end)
84 Reset(points, start, end);
91 void Reset(
const std::vector<T>& points);
97 void Reset(
const std::span<const T> points);
104 template <
typename T>
105 void Reset(
const std::vector<T>& points,
size_t start,
size_t end);
112 template <
typename T>
113 void Reset(
const std::span<const T> points,
size_t start,
size_t end);
120 return other.m_lowerLeft != m_lowerLeft || other.m_upperRight != m_upperRight;
127 template <
typename T>
131 return point.x >= m_lowerLeft.
x && point.x <= m_upperRight.
x &&
132 point.y >= m_lowerLeft.
y && point.y <= m_upperRight.
y;
142 [[nodiscard]]
const auto&
lowerLeft()
const {
return m_lowerLeft; }
150 [[nodiscard]]
const auto&
upperRight()
const {
return m_upperRight; }
162 double Width()
const {
return m_upperRight.
x - m_lowerLeft.
x; }
166 double Height()
const {
return m_upperRight.
y - m_lowerLeft.
y; }
172 const double width =
Width();
173 const double height =
Height();
174 m_lowerLeft.
x -= width * factor;
175 m_lowerLeft.
y -= height * factor;
176 m_upperRight.
x += width * factor;
177 m_upperRight.
y += height * factor;
184 template <std::derived_from<Po
int> T>
187 const auto lowerLeftX = std::min(first.x, second.x);
188 const auto lowerLeftY = std::min(first.y, second.y);
189 const auto upperRightX = std::max(first.x, second.x);
190 const auto upperRightY = std::max(first.y, second.y);
192 return BoundingBox({lowerLeftX, lowerLeftY}, {upperRightX, upperRightY});
201 static BoundingBox Merge(
const BoundingBox& b1,
const BoundingBox& b2);
204 static BoundingBox CreateNonOverlappingBoundingBox();
211 Reset(std::span(points));
217 if (points.size() > 0)
219 Reset(points, 0, points.size() - 1);
223 m_lowerLeft =
Point(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest());
224 m_upperRight =
Point(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
232 Reset(std::span(points), start, end);
238 double minx = std::numeric_limits<double>::max();
239 double maxx = std::numeric_limits<double>::lowest();
240 double miny = std::numeric_limits<double>::max();
241 double maxy = std::numeric_limits<double>::lowest();
243 for (
size_t i = start; i <= end; ++i)
245 const auto& point = points[i];
249 minx = std::min(minx, point.x);
250 maxx = std::max(maxx, point.x);
251 miny = std::min(miny, point.y);
252 maxy = std::max(maxy, point.y);
255 m_lowerLeft =
Point(minx, miny);
256 m_upperRight =
Point(maxx, maxy);
264 return {lowerLeft, upperRight};
269 Point lowerLeft(std::numeric_limits<double>::max(), std::numeric_limits<double>::max());
270 Point upperRight(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest());
271 return {lowerLeft, upperRight};
276 return Vector(m_upperRight.x - m_lowerLeft.x, m_upperRight.y - m_lowerLeft.y);
281 const auto& otherLowerleft = other.
lowerLeft();
282 const auto& otherUpperRight = other.
upperRight();
283 if (m_upperRight.x < otherLowerleft.x ||
284 otherUpperRight.x < m_lowerLeft.x ||
285 m_upperRight.y < otherLowerleft.y ||
286 otherUpperRight.y < m_lowerLeft.y)
A class defining a bounding box.
Definition BoundingBox.hpp:43
BoundingBox(const std::vector< T > &points)
Constructor taking a vector of coordinates types.
Definition BoundingBox.hpp:71
const auto & lowerLeft() const
Returns the lower left corner of the bounding box.
Definition BoundingBox.hpp:142
BoundingBox()
Default constructor.
Definition BoundingBox.hpp:46
double Width() const
Returns the bounding box width.
Definition BoundingBox.hpp:162
void Reset(const std::vector< T > &points)
Reset bounding box with a vector of coordinates types.
Definition BoundingBox.hpp:209
bool Overlaps(const BoundingBox &boundingBox) const
Checks if two bounding boxes overlaps.
Definition BoundingBox.hpp:279
bool Contains(const T &point) const
Checks if a point is inside a bounding box.
Definition BoundingBox.hpp:128
double Height() const
Returns the bounding box height.
Definition BoundingBox.hpp:166
BoundingBox(const Point &lowerLeft, const Point &upperRight)
Constructor taking the corner points of the bounding box.
Definition BoundingBox.hpp:52
void Extend(double factor)
Extends the bounding box by a factor.
Definition BoundingBox.hpp:169
auto & lowerLeft()
Returns the lower left corner of the bounding box.
Definition BoundingBox.hpp:146
const auto & upperRight() const
Returns the upper right corner.
Definition BoundingBox.hpp:150
Vector Delta() const
Return the delta of the bounding box.
Definition BoundingBox.hpp:274
BoundingBox(const std::span< const T > points)
Constructor taking a vector of coordinates types.
Definition BoundingBox.hpp:62
auto & upperRight()
Returns the upper right corner.
Definition BoundingBox.hpp:154
static BoundingBox CreateBoundingBox(const T &first, const T &second)
Create a bounding box from two points.
Definition BoundingBox.hpp:185
bool operator!=(const BoundingBox &other) const
Not equal operator.
Definition BoundingBox.hpp:118
BoundingBox(const std::vector< T > &points, size_t start, size_t end)
Constructor taking a vector of coordinates types.
Definition BoundingBox.hpp:82
Point MassCentre() const
Returns the mass centre.
Definition BoundingBox.hpp:158
A struct describing a point in a two-dimensional space.
Definition Point.hpp:41
double x
X-coordinate.
Definition Point.hpp:43
double y
Y-coordinate.
Definition Point.hpp:44
A class defining a vector.
Definition Vector.hpp:39
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37