17#include <egt/detail/math.h>
18#include <egt/detail/meta.h>
61template <
class Dim, detail::Compatible DimCompat = detail::Compatible::normal>
167 m_y + radius * std::sin(angle));
178 return std::atan2(point.m_x -
m_x,
m_y - point.m_y);
188 return std::hypot(point.m_x -
m_x, point.m_y -
m_y);
192 EGT_NODISCARD
constexpr Dim
x() const noexcept {
return m_x; }
194 EGT_NODISCARD
constexpr Dim
y() const noexcept {
return m_y; }
197 constexpr void x(Dim
x)
noexcept {
m_x =
x; }
199 constexpr void y(Dim
y)
noexcept {
m_y =
y; }
209template<
class Dim, detail::Compatible DimCompat>
216template<
class Dim, detail::Compatible DimCompat>
219 return lhs.x() == rhs.x() && lhs.y() == rhs.y();
223template<detail::Compatible DimCompat>
231template<
class Dim, detail::Compatible DimCompat>
234 return !(lhs == rhs);
238template<
class Dim, detail::Compatible DimCompat>
246template<
class Dim, detail::Compatible DimCompat>
254template<
class Dim, detail::Compatible DimCompat>
262template<
class Dim, detail::Compatible DimCompat>
270template<
class Dim, detail::Compatible DimCompat,
class T>
278template<
class Dim, detail::Compatible DimCompat,
class T>
286template<
class Dim, detail::Compatible DimCompat,
class T>
294template<
class Dim, detail::Compatible DimCompat,
class T>
302template<
class Dim, detail::Compatible DimCompat>
305 os <<
"[" << point.
x() <<
"," << point.
y() <<
"]";
316static_assert(detail::rule_of_5<Point>(),
"must fulfill rule of 5");
339template<
class Dim, detail::Compatible DimCompat = detail::Compatible::normal>
372 EGT_NODISCARD
constexpr bool empty() const noexcept
475template<
class Dim, detail::Compatible DimCompat>
478 return lhs.width() == rhs.width() && lhs.height() == rhs.height();
482template<detail::Compatible DimCompat>
490template<
class Dim, detail::Compatible DimCompat>
493 return !(lhs == rhs);
497template<
class Dim, detail::Compatible DimCompat>
505template<
class Dim, detail::Compatible DimCompat>
513template<
class Dim, detail::Compatible DimCompat>
521template<
class Dim, detail::Compatible DimCompat>
529template<
class Dim, detail::Compatible DimCompat,
class T>
537template<
class Dim, detail::Compatible DimCompat,
class T>
545template<
class Dim, detail::Compatible DimCompat,
class T>
553template<
class Dim, detail::Compatible DimCompat,
class T>
561template<
class Dim, detail::Compatible DimCompat>
564 os << size.width() <<
"x" << size.height();
575static_assert(detail::rule_of_5<Size>(),
"must fulfill rule of 5");
593template<
class Dim, detail::Compatible DimCompat = detail::Compatible::normal>
612 assert(
width() >= 0);
636 template<
typename Dim2>
673 EGT_NODISCARD
constexpr Dim
area() const noexcept
754 EGT_NODISCARD
constexpr Dim
top() const noexcept
762 EGT_NODISCARD
constexpr Dim
left() const noexcept
770 EGT_NODISCARD
constexpr Dim
bottom() const noexcept
778 EGT_NODISCARD
constexpr Dim
right() const noexcept
829 EGT_NODISCARD
constexpr bool empty() const noexcept
863 return (
x() < rect.x() + rect.width() &&
x() +
width() > rect.x() &&
864 y() < rect.y() + rect.height() &&
y() +
height() > rect.y());
874 const auto xmin = std::min(lhs.x(), rhs.x());
875 const auto xmax = std::max(lhs.x() + lhs.width(),
876 rhs.x() + rhs.width());
877 const auto ymin = std::min(lhs.y(), rhs.y());
878 const auto ymax = std::max(lhs.y() + lhs.height(),
879 rhs.y() + rhs.height());
890 const auto x0 = std::max(lhs.x(), rhs.x());
891 const auto y0 = std::max(lhs.y(), rhs.y());
892 const auto w0 = std::min(lhs.x() + lhs.width(), rhs.x() + rhs.width()) - x0;
893 const auto h0 = std::min(lhs.y() + lhs.height(), rhs.y() + rhs.height()) - y0;
895 if (w0 < 0 || h0 < 0)
909 return rhs.right() <
right() &&
910 rhs.bottom() <
bottom() &&
911 rhs.left() >
left() &&
916 EGT_NODISCARD
constexpr Dim
x() const noexcept {
return m_origin.x(); }
918 EGT_NODISCARD
constexpr Dim
y() const noexcept {
return m_origin.y(); }
926 EGT_NODISCARD
constexpr Dim
width() const noexcept {
return m_size.width(); }
928 EGT_NODISCARD
constexpr Dim
height() const noexcept {
return m_size.height(); }
944template<
class Dim, detail::Compatible DimCompat>
947 os <<
"[" << rect.
x() <<
"," << rect.
y() <<
"-" <<
953template<
class Dim, detail::Compatible DimCompat>
956 lhs.size(lhs.size() - rhs);
961template<
class Dim, detail::Compatible DimCompat>
964 lhs.size(lhs.size() + rhs);
969template<
class Dim, detail::Compatible DimCompat>
972 lhs.size(lhs.size() * rhs);
977template<
class Dim, detail::Compatible DimCompat>
980 lhs.size(lhs.size() / rhs);
985template<
class Dim, detail::Compatible DimCompat>
988 lhs.point(lhs.point() + rhs);
993template<
class Dim, detail::Compatible DimCompat>
996 lhs.point(lhs.point() - rhs);
1001template<
class Dim, detail::Compatible DimCompat>
1004 lhs.point(lhs.point() * rhs);
1009template<
class Dim, detail::Compatible DimCompat>
1012 lhs.point(lhs.point() / rhs);
1017template<
class Dim, detail::Compatible DimCompat>
1020 return lhs.point() == rhs.point() &&
1021 lhs.size() == rhs.size();
1025template<
class Dim, detail::Compatible DimCompat>
1028 return !(lhs == rhs);
1038static_assert(detail::rule_of_5<Rect>(),
"must fulfill rule of 5");
1107 os <<
"[" << line.
start() <<
"-" << line.
end() <<
"]";
1125static_assert(detail::rule_of_5<Line>(),
"must fulfill rule of 5");
1161 template<
class Dim2>
1173 EGT_NODISCARD EGT_API
bool empty() const noexcept;
1215static_assert(detail::rule_of_5<Arc>(),
"must fulfill rule of 5");
1252 template<
class Dim2>
1277 this->y() + this->
radius() * std::sin(angle));
1285 os <<
"[" << circle.
center() <<
"-" << circle.
radius() <<
"]";
1296static_assert(detail::rule_of_5<Circle>(),
"must fulfill rule of 5");
1332 template<
class Dim2>
1358 const auto x =
m_radiusa * std::cos(angle);
1359 const auto y =
m_radiusb * std::sin(angle);
1396static_assert(detail::rule_of_5<Ellipse>(),
"must fulfill rule of 5");
1409 os <<
"[" << ellipse.
center() <<
"-" << ellipse.
radiusa() <<
1410 "-" << ellipse.
radiusb() <<
"]";
An Arc consists of a radius and two angles.
Definition geometry.h:1136
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1142
EGT_NODISCARD constexpr float angle1() const noexcept
Get the angle1.
Definition geometry.h:1187
float m_angle2
Angle of the arc in radians.
Definition geometry.h:1205
constexpr void radius(Dim radius) noexcept
Set the radius.
Definition geometry.h:1176
constexpr ArcType(const PointType< Dim > ¢er={}, Dim radius={}, float angle1=0.0f, float angle2=0.0f) noexcept
Construct an Arc object.
Definition geometry.h:1152
Dim m_radius
Radius of the arc.
Definition geometry.h:1199
float m_angle1
Angle of the arc in radians.
Definition geometry.h:1202
EGT_NODISCARD constexpr Dim radius() const noexcept
Get the radius.
Definition geometry.h:1185
constexpr ArcType(const ArcType< Dim2 > &a)
Definition geometry.h:1162
EGT_NODISCARD constexpr float angle2() const noexcept
Get the angle2.
Definition geometry.h:1189
constexpr void angle1(float angle) noexcept
Set the angle1.
Definition geometry.h:1178
EGT_NODISCARD EGT_API bool empty() const noexcept
Returns true if the arc has no radius.
constexpr void center(const PointType< Dim > ¢er) noexcept
Set the center point.
Definition geometry.h:1182
EGT_NODISCARD constexpr PointType< Dim > center() const noexcept
Get the center point.
Definition geometry.h:1191
PointType< Dim > m_center
Center point of the arc.
Definition geometry.h:1196
constexpr void angle2(float angle) noexcept
Set the angle2.
Definition geometry.h:1180
A basic circle with a center point and radius.
Definition geometry.h:1233
PointType< Dim > point_on_circumference(T angle) const noexcept
Return the point on the circumference of the circle at the given angle.
Definition geometry.h:1274
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1239
constexpr CircleType(const PointType< Dim > ¢er={}, Dim radius={}) noexcept
Construct a Circle object.
Definition geometry.h:1247
EGT_NODISCARD constexpr RectType< Dim > rect() const noexcept
Get a Rect that covers the circle.
Definition geometry.h:1261
constexpr CircleType(const CircleType< Dim2 > &c)
Definition geometry.h:1253
A basic ellipse with a center and 2 radii.
Definition geometry.h:1311
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1316
EGT_NODISCARD constexpr Dim perimeter() const noexcept
Get the total perimeter of the ellipse.
Definition geometry.h:1343
Dim m_radiusa
A radius.
Definition geometry.h:1383
constexpr EllipseType(const EllipseType< Dim2 > &e)
Definition geometry.h:1333
EGT_NODISCARD constexpr Dim radiusa() const noexcept
Get the first radius of the ellipse.
Definition geometry.h:1371
EGT_NODISCARD constexpr Dim radiusb() const noexcept
Get the second radius of the ellipse.
Definition geometry.h:1373
constexpr void radiusa(const Dim radiusa) noexcept
Set the first radius of the ellipse.
Definition geometry.h:1364
constexpr void radiusb(const Dim radiusb) noexcept
Set the second radius of the ellipse.
Definition geometry.h:1366
Dim m_radiusb
B radius.
Definition geometry.h:1386
constexpr void center(const PointType< Dim > ¢er) noexcept
Set the center of the ellipse.
Definition geometry.h:1368
EGT_NODISCARD constexpr PointType< Dim > center() const noexcept
Get the center of the ellipse.
Definition geometry.h:1375
constexpr EllipseType(const PointType< Dim > ¢er={}, Dim radiusa={}, Dim radiusb={}) noexcept
Definition geometry.h:1323
PointType< Dim > m_center
Center point of the arc.
Definition geometry.h:1380
PointType< Dim > point_on_circumference(T angle) noexcept
Return the point on the circumference of the ellipse at the given angle.
Definition geometry.h:1356
A line, with a starting and ending point.
Definition geometry.h:1056
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1062
constexpr void end(const PointType< Dim > &end) noexcept
Set the end point of the line.
Definition geometry.h:1081
EGT_NODISCARD constexpr RectType< Dim > rect() const noexcept
Returns a rectangle containing the line.
Definition geometry.h:1086
PointType< Dim > m_end
End point of the line.
Definition geometry.h:1100
PointType< Dim > m_start
Start point of the line.
Definition geometry.h:1098
constexpr void start(const PointType< Dim > &start) noexcept
Set the start point of the line.
Definition geometry.h:1079
constexpr LineType(const PointType< Dim > &start, const PointType< Dim > &end) noexcept
Definition geometry.h:1068
EGT_NODISCARD constexpr PointType< Dim > start() const noexcept
Get the start point of the line.
Definition geometry.h:1074
EGT_NODISCARD constexpr PointType< Dim > end() const noexcept
Get the end point of the line.
Definition geometry.h:1076
Simple x,y coordinate.
Definition geometry.h:63
constexpr PointType & operator*=(const PointType &rhs) noexcept
PointType operator.
Definition geometry.h:105
constexpr PointType & operator-=(const PointType &rhs) noexcept
PointType operator.
Definition geometry.h:97
constexpr PointType & operator/=(const T &rhs) noexcept
PointType operator.
Definition geometry.h:149
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:69
PointType point_on_circumference(T radius, T angle) const noexcept
If this point is the center of a circle, return a new point that is on the circumference of the circl...
Definition geometry.h:164
EGT_NODISCARD constexpr Dim x() const noexcept
Get the x value.
Definition geometry.h:192
constexpr void x(Dim x) noexcept
Set the x value.
Definition geometry.h:197
constexpr PointType & operator/=(const PointType &rhs) noexcept
PointType operator.
Definition geometry.h:113
constexpr PointType & operator*=(const T &rhs) noexcept
PointType operator.
Definition geometry.h:140
Dim m_y
Y value.
Definition geometry.h:205
constexpr PointType & operator+=(const PointType &rhs) noexcept
PointType operator.
Definition geometry.h:89
EGT_NODISCARD T angle_to(const PointType &point) const noexcept
Return the angle in radians from this point to get to another.
Definition geometry.h:176
constexpr PointType() noexcept=default
Dim m_x
X value.
Definition geometry.h:203
constexpr PointType & operator-=(const T &rhs) noexcept
PointType operator.
Definition geometry.h:131
EGT_NODISCARD Dim distance_to(const PointType &point) const noexcept
Calculate the straight line distance to another point.
Definition geometry.h:186
constexpr PointType(const PointType< Dim2 > &p)
Definition geometry.h:83
EGT_NODISCARD constexpr Dim y() const noexcept
Get the y value.
Definition geometry.h:194
constexpr void y(Dim y) noexcept
Set the y value.
Definition geometry.h:199
constexpr PointType & operator+=(const T &rhs) noexcept
PointType operator.
Definition geometry.h:122
A rectangle with a point and a size.
Definition geometry.h:595
constexpr RectType() noexcept=default
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:601
constexpr RectType(const SizeType< Dim, DimCompat > &size) noexcept
Construct a rectangle with the specified size and the point being at the default origin 0,...
Definition geometry.h:622
constexpr RectType & operator-=(const SizeType< Dim, DimCompat > &rhs) noexcept
RectType operator.
Definition geometry.h:650
constexpr void grow_around_center(Dim radius) noexcept
Grow the rectangle around its center by the specified radius.
Definition geometry.h:702
EGT_NODISCARD constexpr Dim left() const noexcept
Get the left side the rectangle.
Definition geometry.h:762
EGT_NODISCARD constexpr Dim width() const noexcept
Get the width value.
Definition geometry.h:926
EGT_NODISCARD constexpr Dim x() const noexcept
Get the x value.
Definition geometry.h:916
constexpr void x(Dim x) noexcept
Set the x value.
Definition geometry.h:921
constexpr void shrink_around_center(Dim radius) noexcept
Shrink the rectangle around its center by the specified radius.
Definition geometry.h:713
constexpr RectType(Dim x, Dim y, Dim width, Dim height) noexcept
Definition geometry.h:632
constexpr void point(const PointType< Dim, DimCompat > &p) noexcept
Set the rectangle's origin to the specified point.
Definition geometry.h:730
SizeType< Dim, DimCompat > m_size
Size.
Definition geometry.h:940
static constexpr RectType merge(const RectType &lhs, const RectType &rhs) noexcept
Merge two rectangles together into one super rectangle that contains them both.
Definition geometry.h:871
EGT_NODISCARD constexpr bool empty() const noexcept
Returns true if the rectangle has no width or height.
Definition geometry.h:829
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_left() const noexcept
Get the top left point of the rectangle.
Definition geometry.h:788
constexpr void height(Dim height) noexcept
Set the height value.
Definition geometry.h:933
constexpr void width(Dim width) noexcept
Set the width value.
Definition geometry.h:931
constexpr RectType(const RectType< Dim2 > &r)
Definition geometry.h:637
EGT_NODISCARD constexpr Dim bottom() const noexcept
Get the bottom side the rectangle.
Definition geometry.h:770
EGT_NODISCARD constexpr PointType< Dim, DimCompat > top_right() const noexcept
Get the top right point of the rectangle.
Definition geometry.h:796
constexpr void move_to_center(const PointType< Dim, DimCompat > ¢er) noexcept
Move the rectangle's center to the specified point.
Definition geometry.h:689
EGT_NODISCARD constexpr Dim top() const noexcept
Get the top side of the rectangle.
Definition geometry.h:754
EGT_NODISCARD constexpr const SizeType< Dim, DimCompat > & size() const noexcept
Get the SizeType of the rectangle.
Definition geometry.h:738
constexpr void size(const SizeType< Dim, DimCompat > &size) noexcept
Set the SizeType of the rectangle.
Definition geometry.h:746
EGT_NODISCARD constexpr const PointType< Dim, DimCompat > & point() const noexcept
Get the PointType of the rectangle.
Definition geometry.h:722
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_right() const noexcept
Get the bottom right point of the rectangle.
Definition geometry.h:812
constexpr void clear() noexcept
Clear the rectangle by giving it no width or height.
Definition geometry.h:820
static constexpr RectType intersection(const RectType &lhs, const RectType &rhs) noexcept
Return the intersecting rectangle of two rectangles, if any.
Definition geometry.h:887
EGT_NODISCARD constexpr PointType< Dim, DimCompat > bottom_left() const noexcept
Get the bottom left point of the rectangle.
Definition geometry.h:804
constexpr RectType & operator+=(const SizeType< Dim, DimCompat > &rhs) noexcept
RectType operator.
Definition geometry.h:643
EGT_NODISCARD constexpr Dim height() const noexcept
Get the height value.
Definition geometry.h:928
EGT_NODISCARD constexpr Dim right() const noexcept
Get the right side the rectangle.
Definition geometry.h:778
EGT_NODISCARD constexpr bool intersect(const RectType &rect) const noexcept
Determine if two rectangles intersect, or, overlap.
Definition geometry.h:861
PointType< Dim, DimCompat > m_origin
Origin.
Definition geometry.h:938
EGT_NODISCARD constexpr bool contains(const RectType &rhs) const noexcept
Returns true if this rectangle contains the specified one.
Definition geometry.h:907
EGT_NODISCARD constexpr PointType< Dim, DimCompat > center() const noexcept
Return the center point of the rectangle.
Definition geometry.h:681
constexpr RectType & operator+=(const PointType< Dim, DimCompat > &rhs) noexcept
RectType operator.
Definition geometry.h:657
EGT_NODISCARD constexpr Dim y() const noexcept
Get the y value.
Definition geometry.h:918
constexpr RectType & operator-=(const PointType< Dim, DimCompat > &rhs) noexcept
RectType operator.
Definition geometry.h:664
constexpr void y(Dim y) noexcept
Set the y value.
Definition geometry.h:923
EGT_NODISCARD constexpr bool intersect(const PointType< Dim, DimCompat > &point) const noexcept
Returns true if the specified point is inside the rectangle.
Definition geometry.h:851
EGT_NODISCARD constexpr Dim area() const noexcept
Calculate the area of the rectangle.
Definition geometry.h:673
Simple width and height.
Definition geometry.h:341
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:347
constexpr SizeType & operator-=(const SizeType &rhs) noexcept
SizeType operator.
Definition geometry.h:397
constexpr SizeType & operator+=(const SizeType &rhs) noexcept
SizeType operator.
Definition geometry.h:389
EGT_NODISCARD constexpr Dim width() const noexcept
Get the width value.
Definition geometry.h:457
constexpr SizeType & operator-=(const T &rhs) noexcept
SizeType operator.
Definition geometry.h:431
EGT_NODISCARD constexpr bool empty() const noexcept
Returns true if the size has no width or height.
Definition geometry.h:372
constexpr void height(Dim height) noexcept
Set the height value.
Definition geometry.h:464
constexpr void width(Dim width) noexcept
Set the width value.
Definition geometry.h:462
constexpr SizeType(const SizeType< Dim2 > &s)
Definition geometry.h:361
Dim m_height
Height.
Definition geometry.h:468
constexpr SizeType & operator/=(const T &rhs) noexcept
SizeType operator.
Definition geometry.h:449
constexpr void clear() noexcept
Clear the size.
Definition geometry.h:383
EGT_NODISCARD constexpr Dim height() const noexcept
Get the height value.
Definition geometry.h:459
constexpr SizeType & operator+=(const T &rhs) noexcept
SizeType operator.
Definition geometry.h:422
constexpr SizeType() noexcept=default
constexpr SizeType & operator*=(const T &rhs) noexcept
SizeType operator.
Definition geometry.h:440
Dim m_width
Width.
Definition geometry.h:471
constexpr SizeType & operator/=(const SizeType &rhs) noexcept
SizeType operator.
Definition geometry.h:413
constexpr SizeType & operator*=(const SizeType &rhs) noexcept
SizeType operator.
Definition geometry.h:405
PointType< DefaultDim, detail::Compatible::normal > Point
Helper type alias.
Definition geometry.h:314
SizeType< float, detail::Compatible::normal > SizeF
Helper type alias.
Definition geometry.h:582
constexpr bool float_equal(const float f1, const float f2)
Safe equal comparison of float values.
Definition math.h:107
Compatible
Geometry types compatibility type.
Definition geometry.h:45
constexpr Color operator-(T scalar, const Color &rhs)
Color operator.
Definition color.h:526
constexpr bool operator!=(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:509
EGT_API std::ostream & operator<<(std::ostream &os, const Color &color)
Overloaded std::ostream insertion operator.
constexpr Color operator+(T scalar, const Color &rhs)
Color operator.
Definition color.h:516
constexpr Color operator/(T scalar, const Color &rhs)
Color operator.
Definition color.h:546
constexpr bool operator==(const Color &lhs, const Color &rhs)
Color operator.
Definition color.h:500
constexpr Color operator*(T scalar, const Color &rhs)
Color operator.
Definition color.h:536
int DefaultDim
Define the default dimension type used for geometry.
Definition geometry.h:34
EGT framework namespace.
Definition animation.h:24