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
850 return (
x() < rect.x() + rect.width() &&
x() +
width() > rect.x() &&
851 y() < rect.y() + rect.height() &&
y() +
height() > rect.y());
861 const auto xmin = std::min(lhs.x(), rhs.x());
862 const auto xmax = std::max(lhs.x() + lhs.width(),
863 rhs.x() + rhs.width());
864 const auto ymin = std::min(lhs.y(), rhs.y());
865 const auto ymax = std::max(lhs.y() + lhs.height(),
866 rhs.y() + rhs.height());
877 const auto x0 = std::max(lhs.x(), rhs.x());
878 const auto y0 = std::max(lhs.y(), rhs.y());
879 const auto w0 = std::min(lhs.x() + lhs.width(), rhs.x() + rhs.width()) - x0;
880 const auto h0 = std::min(lhs.y() + lhs.height(), rhs.y() + rhs.height()) - y0;
882 if (w0 < 0 || h0 < 0)
896 return rhs.right() <
right() &&
897 rhs.bottom() <
bottom() &&
898 rhs.left() >
left() &&
903 EGT_NODISCARD
constexpr Dim
x() const noexcept {
return m_origin.x(); }
905 EGT_NODISCARD
constexpr Dim
y() const noexcept {
return m_origin.y(); }
913 EGT_NODISCARD
constexpr Dim
width() const noexcept {
return m_size.width(); }
915 EGT_NODISCARD
constexpr Dim
height() const noexcept {
return m_size.height(); }
931template<
class Dim, detail::Compatible DimCompat>
934 os <<
"[" << rect.
x() <<
"," << rect.
y() <<
"-" <<
940template<
class Dim, detail::Compatible DimCompat>
943 lhs.size(lhs.size() - rhs);
948template<
class Dim, detail::Compatible DimCompat>
951 lhs.size(lhs.size() + rhs);
956template<
class Dim, detail::Compatible DimCompat>
959 lhs.size(lhs.size() * rhs);
964template<
class Dim, detail::Compatible DimCompat>
967 lhs.size(lhs.size() / rhs);
972template<
class Dim, detail::Compatible DimCompat>
975 lhs.point(lhs.point() + rhs);
980template<
class Dim, detail::Compatible DimCompat>
983 lhs.point(lhs.point() - rhs);
988template<
class Dim, detail::Compatible DimCompat>
991 lhs.point(lhs.point() * rhs);
996template<
class Dim, detail::Compatible DimCompat>
999 lhs.point(lhs.point() / rhs);
1004template<
class Dim, detail::Compatible DimCompat>
1007 return lhs.point() == rhs.point() &&
1008 lhs.size() == rhs.size();
1012template<
class Dim, detail::Compatible DimCompat>
1015 return !(lhs == rhs);
1025static_assert(detail::rule_of_5<Rect>(),
"must fulfill rule of 5");
1094 os <<
"[" << line.
start() <<
"-" << line.
end() <<
"]";
1112static_assert(detail::rule_of_5<Line>(),
"must fulfill rule of 5");
1151 EGT_NODISCARD EGT_API
bool empty() const noexcept;
1193static_assert(detail::rule_of_5<Arc>(),
"must fulfill rule of 5");
1242 this->y() + this->
radius() * std::sin(angle));
1250 os <<
"[" << circle.
center() <<
"-" << circle.
radius() <<
"]";
1261static_assert(detail::rule_of_5<Circle>(),
"must fulfill rule of 5");
1317 const auto x =
m_radiusa * std::cos(angle);
1318 const auto y =
m_radiusb * std::sin(angle);
1355static_assert(detail::rule_of_5<Ellipse>(),
"must fulfill rule of 5");
1361 os <<
"[" << ellipse.
center() <<
"-" << ellipse.
radiusa() <<
1362 "-" << ellipse.
radiusb() <<
"]";
An Arc consists of a radius and two angles.
Definition geometry.h:1123
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1129
EGT_NODISCARD constexpr float angle1() const noexcept
Get the angle1.
Definition geometry.h:1165
float m_angle2
Angle of the arc in radians.
Definition geometry.h:1183
constexpr void radius(Dim radius) noexcept
Set the radius.
Definition geometry.h:1154
constexpr ArcType(const PointType< Dim > ¢er={}, Dim radius={}, float angle1=0.0f, float angle2=0.0f) noexcept
Construct an Arc object.
Definition geometry.h:1139
Dim m_radius
Radius of the arc.
Definition geometry.h:1177
float m_angle1
Angle of the arc in radians.
Definition geometry.h:1180
EGT_NODISCARD constexpr Dim radius() const noexcept
Get the radius.
Definition geometry.h:1163
EGT_NODISCARD constexpr float angle2() const noexcept
Get the angle2.
Definition geometry.h:1167
constexpr void angle1(float angle) noexcept
Set the angle1.
Definition geometry.h:1156
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:1160
EGT_NODISCARD constexpr PointType< Dim > center() const noexcept
Get the center point.
Definition geometry.h:1169
PointType< Dim > m_center
Center point of the arc.
Definition geometry.h:1174
constexpr void angle2(float angle) noexcept
Set the angle2.
Definition geometry.h:1158
A basic circle with a center point and radius.
Definition geometry.h:1204
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:1239
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1210
constexpr CircleType(const PointType< Dim > ¢er={}, Dim radius={}) noexcept
Construct a Circle object.
Definition geometry.h:1218
EGT_NODISCARD constexpr RectType< Dim > rect() const noexcept
Get a Rect that covers the circle.
Definition geometry.h:1226
A basic ellipse with a center and 2 radii.
Definition geometry.h:1276
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1281
EGT_NODISCARD constexpr Dim perimeter() const noexcept
Get the total perimeter of the ellipse.
Definition geometry.h:1302
Dim m_radiusa
A radius.
Definition geometry.h:1342
EGT_NODISCARD constexpr Dim radiusa() const noexcept
Get the first radius of the ellipse.
Definition geometry.h:1330
EGT_NODISCARD constexpr Dim radiusb() const noexcept
Get the second radius of the ellipse.
Definition geometry.h:1332
constexpr void radiusa(const Dim radiusa) noexcept
Set the first radius of the ellipse.
Definition geometry.h:1323
constexpr void radiusb(const Dim radiusb) noexcept
Set the second radius of the ellipse.
Definition geometry.h:1325
Dim m_radiusb
B radius.
Definition geometry.h:1345
constexpr void center(const PointType< Dim > ¢er) noexcept
Set the center of the ellipse.
Definition geometry.h:1327
EGT_NODISCARD constexpr PointType< Dim > center() const noexcept
Get the center of the ellipse.
Definition geometry.h:1334
constexpr EllipseType(const PointType< Dim > ¢er={}, Dim radiusa={}, Dim radiusb={}) noexcept
Definition geometry.h:1288
PointType< Dim > m_center
Center point of the arc.
Definition geometry.h:1339
PointType< Dim > point_on_circumference(T angle) noexcept
Return the point on the circumference of the ellipse at the given angle.
Definition geometry.h:1315
A line, with a starting and ending point.
Definition geometry.h:1043
Dim DimType
Helper to reference the dimension type.
Definition geometry.h:1049
constexpr void end(const PointType< Dim > &end) noexcept
Set the end point of the line.
Definition geometry.h:1068
EGT_NODISCARD constexpr RectType< Dim > rect() const noexcept
Returns a rectangle containing the line.
Definition geometry.h:1073
PointType< Dim > m_end
End point of the line.
Definition geometry.h:1087
PointType< Dim > m_start
Start point of the line.
Definition geometry.h:1085
constexpr void start(const PointType< Dim > &start) noexcept
Set the start point of the line.
Definition geometry.h:1066
constexpr LineType(const PointType< Dim > &start, const PointType< Dim > &end) noexcept
Definition geometry.h:1055
EGT_NODISCARD constexpr PointType< Dim > start() const noexcept
Get the start point of the line.
Definition geometry.h:1061
EGT_NODISCARD constexpr PointType< Dim > end() const noexcept
Get the end point of the line.
Definition geometry.h:1063
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:913
EGT_NODISCARD constexpr Dim x() const noexcept
Get the x value.
Definition geometry.h:903
constexpr void x(Dim x) noexcept
Set the x value.
Definition geometry.h:908
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:927
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:858
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:920
constexpr void width(Dim width) noexcept
Set the width value.
Definition geometry.h:918
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:874
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:915
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:848
PointType< Dim, DimCompat > m_origin
Origin.
Definition geometry.h:925
EGT_NODISCARD constexpr bool contains(const RectType &rhs) const noexcept
Returns true if this rectangle contains the specified one.
Definition geometry.h:894
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:905
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:910
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:838
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
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