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()) {}
43 BoundingBox() : m_lowerLeft(std::numeric_limits<double>::lowest(), std::numeric_limits<double>::lowest()), {
…}
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);
84 BoundingBox(
const std::vector<T>& points,
size_t start,
size_t 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();
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());
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)
A class defining a bounding box.
Definition BoundingBox.hpp:40
auto & lowerLeft() const
Returns the lower left corner of the bounding box.
Definition BoundingBox.hpp:116
BoundingBox(const std::vector< T > &points)
Constructor taking a vector of coordinates types.
Definition BoundingBox.hpp:59
BoundingBox()
Default constructor.
Definition BoundingBox.hpp:43
double Width() const
Returns the bounding box width.
Definition BoundingBox.hpp:128
void Reset(const std::vector< T > &points)
Reset bounding box with a vector of coordinates types.
Definition BoundingBox.hpp:175
bool Overlaps(const BoundingBox &boundingBox) const
Checks if two bounding boxes overlaps.
Definition BoundingBox.hpp:234
bool Contains(const T &point) const
Checks if a point is inside a bounding box.
Definition BoundingBox.hpp:102
double Height() const
Returns the bounding box height.
Definition BoundingBox.hpp:132
BoundingBox(const Point &lowerLeft, const Point &upperRight)
Constructor taking the corner points of the bounding box.
Definition BoundingBox.hpp:49
void Extend(double factor)
Extends the bounding box by a factor.
Definition BoundingBox.hpp:135
Vector Delta() const
Return the delta of the bounding box.
Definition BoundingBox.hpp:229
static BoundingBox CreateBoundingBox(const T &first, const T &second)
Create a bounding box from two points.
Definition BoundingBox.hpp:151
bool operator!=(const BoundingBox &other) const
Not equal operator.
Definition BoundingBox.hpp:92
BoundingBox(const std::vector< T > &points, size_t start, size_t end)
Constructor taking a vector of coordinates types.
Definition BoundingBox.hpp:84
Point MassCentre() const
Returns the mass centre.
Definition BoundingBox.hpp:124
auto & upperRight() const
Returns the upper right corner.
Definition BoundingBox.hpp:120
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