22 std::array<double, 2> xy_{};
34 constexpr double x() const noexcept {
return xy_[0]; }
36 constexpr double y() const noexcept {
return xy_[1]; }
42 double *
data() noexcept {
return xy_.data(); }
47 const double *
data() const noexcept {
return xy_.data(); }
49 constexpr bool isNull()
const {
return x() == 0 &&
y() == 0; }
145 return a.
x() == b.
x() && a.
y() == b.
y();
168 double x0_ = 0, y0_ = 0, w_ = 0, h_ = 0;
182 : x0_(a.x()), y0_(a.y()), w_(b.x() - a.x()), h_(b.y() - a.y())
186 constexpr double left()
const {
return x0_; }
188 constexpr double right()
const {
return x0_ + w_; }
190 constexpr double top()
const {
return y0_; }
192 constexpr double bottom()
const {
return y0_ + h_; }
194 constexpr double width()
const {
return w_; }
196 constexpr double height()
const {
return h_; }
204 Box2(
double x,
double y,
double w,
double h) : x0_(x), y0_(y), w_(w), h_(h) {}
216 bool isValid()
const {
return w_ > 0 && h_ > 0; }
222 bool isEmpty()
const {
return w_ <= 0 || h_ <= 0; }
224 bool isNull()
const {
return w_ == 0 && h_ == 0; }
266 double x = std::max(
left(), b.
left()), y = std::max(
top(), b.
top()),
268 return r < x || t < y ?
Box2{} :
Box2{{x, y}, {r, t}};
285 constexpr Point2 center()
const {
return {x0_ + w_ * .5, y0_ + h_ * .5}; }
296 return {{std::min(x0_, b.x0_), std::min(y0_, b.y0_)},
320 double x = 0,
y = 0,
z = 0;
322static_assert(std::is_standard_layout<Point3>::value &&
sizeof(
Point3) == 3 *
sizeof(double));
323static_assert(std::is_standard_layout<Point2>::value &&
sizeof(
Point2) == 2 *
sizeof(double));
bool contains(double x, double y) const
Inclusive point-in-box test on coordinates; same as contains(Point2(x, y)).
Definition geometry.hpp:235
constexpr double left() const
X of the origin corner; the minimum x when width() >= 0.
Definition geometry.hpp:186
constexpr Point2 center() const
Midpoint (left() + width() / 2, top() + height() / 2).
Definition geometry.hpp:285
Box2(double x, double y, double w, double h)
Box from an origin corner and a size, all stored as given.
Definition geometry.hpp:204
bool isValid() const
True when width and height are both > 0.
Definition geometry.hpp:216
bool isEmpty() const
True when width <= 0 or height <= 0.
Definition geometry.hpp:222
Box2 adjusted(double l, double t, double r, double b) const
Copy with each edge moved by an offset, in XY plane units.
Definition geometry.hpp:280
Box2 normalized() const
Copy with non-negative width and height covering the same two corners.
Definition geometry.hpp:210
bool intersects(Box2 b) const
Strict overlap test.
Definition geometry.hpp:253
constexpr double bottom() const
top() + height(); the maximum y when height() >= 0.
Definition geometry.hpp:192
bool contains(Point2 p) const
Inclusive point-in-box test.
Definition geometry.hpp:243
constexpr double width() const
Signed extent along x in XY plane units; negative when not normalized.
Definition geometry.hpp:194
bool isNull() const
True when width and height are both exactly 0 (one zero side is empty, not null).
Definition geometry.hpp:224
Box2 intersected(Box2 b) const
Overlap of this box and b.
Definition geometry.hpp:264
Box2 united(Box2 b) const
Bounding box of this box and b.
Definition geometry.hpp:294
constexpr Box2()=default
Null box at the origin: width and height 0, so isNull() and isEmpty() hold.
Point2 topLeft() const
Corner (left(), top()), the origin corner.
Definition geometry.hpp:228
constexpr double right() const
left() + width(); the maximum x when width() >= 0.
Definition geometry.hpp:188
constexpr double top() const
Y of the origin corner; the minimum y when height() >= 0.
Definition geometry.hpp:190
constexpr Box2(Point2 a, Point2 b)
Box spanning from corner a to corner b.
Definition geometry.hpp:181
constexpr double height() const
Signed extent along y in XY plane units; negative when not normalized.
Definition geometry.hpp:196
Point2 bottomRight() const
Corner (right(), bottom()).
Definition geometry.hpp:226
Point or displacement vector in the horizontal (XY) plane.
Definition geometry.hpp:21
constexpr Point2(double x, double y)
Construct a point from its coordinates.
Definition geometry.hpp:32
friend constexpr bool operator!=(Point2 a, Point2 b)
Negation of operator==.
Definition geometry.hpp:153
static constexpr double dotProduct(Point2 a, Point2 b)
Dot product a.x * b.x + a.y * b.y.
Definition geometry.hpp:56
friend constexpr Point2 operator/(Point2 a, double s)
Divide a point by a divisor.
Definition geometry.hpp:135
const double * data() const noexcept
Read-only pointer to the two contiguous coordinates {x, y}.
Definition geometry.hpp:47
friend constexpr Point2 operator-(Point2 a, Point2 b)
Component-wise difference, the displacement from b to a.
Definition geometry.hpp:114
Point2 & operator+=(Point2 p)
Add p component-wise in place.
Definition geometry.hpp:84
constexpr double y() const noexcept
Y coordinate in XY plane units.
Definition geometry.hpp:36
friend constexpr Point2 operator*(double s, Point2 a)
Scale a point by a factor, factor first; same result as a * s.
Definition geometry.hpp:128
friend constexpr Point2 operator+(Point2 a, Point2 b)
Component-wise sum.
Definition geometry.hpp:107
friend constexpr bool operator==(Point2 a, Point2 b)
Exact component-wise equality, with no tolerance.
Definition geometry.hpp:143
Point2 & operator*=(double s)
Multiply both coordinates by s in place.
Definition geometry.hpp:62
constexpr double x() const noexcept
X coordinate in XY plane units.
Definition geometry.hpp:34
Point2 & operator-=(Point2 p)
Subtract p component-wise in place.
Definition geometry.hpp:95
friend constexpr Point2 operator*(Point2 a, double s)
Scale a point by a factor.
Definition geometry.hpp:121
double * data() noexcept
Pointer to the two contiguous coordinates {x, y}.
Definition geometry.hpp:42
constexpr bool isNull() const
True when both coordinates compare equal to 0 (-0.0 counts, NaN does not).
Definition geometry.hpp:49
constexpr Point2()=default
Construct the origin (0, 0).
Point2 & operator/=(double s)
Divide both coordinates by s in place.
Definition geometry.hpp:73
The Qt-free MeshKit library: job events and progress (meshkit::runtime), the neutral mesh model,...
Plain x, y, z coordinate triple; the vertex type of meshkit::Mesh.
Definition geometry.hpp:308
double x
Horizontal x coordinate in XY plane units; default 0.
Definition geometry.hpp:320
double z
Vertical coordinate (elevation) in Z units; default 0.
Definition geometry.hpp:320
double y
Horizontal y coordinate in XY plane units; default 0.
Definition geometry.hpp:320