38 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 39 #error "Only <final/final.h> can be included directly." 45 #include "final/util/fpoint.h" 46 #include "final/util/fsize.h" 47 #include "final/util/fstring.h" 60 FRect () noexcept =
default;
61 FRect (
int,
int, std::size_t, std::size_t) noexcept;
66 auto getClassName()
const ->
FString;
67 auto getX1()
const noexcept -> int;
68 auto getY1()
const noexcept -> int;
69 auto getX2()
const noexcept -> int;
70 auto getY2()
const noexcept -> int;
71 auto getX()
const noexcept -> int;
72 auto getY()
const noexcept -> int;
73 auto getPos()
const noexcept ->
FPoint;
74 auto getUpperLeftPos()
const noexcept ->
FPoint;
75 auto getUpperRightPos()
const noexcept ->
FPoint;
76 auto getLowerLeftPos()
const noexcept ->
FPoint;
77 auto getLowerRightPos()
const noexcept ->
FPoint;
78 auto getWidth()
const noexcept -> std::size_t;
79 auto getHeight()
const noexcept -> std::size_t;
80 auto getSize()
const noexcept ->
FSize;
83 void setX1 (
int) noexcept;
84 void setY1 (
int) noexcept;
85 void setX2 (
int) noexcept;
86 void setY2 (
int) noexcept;
87 void setX (
int) noexcept;
88 void setY (
int) noexcept;
89 void setPos (
int,
int) noexcept;
90 void setPos (
const FPoint&) noexcept;
91 void setWidth (std::size_t) noexcept;
92 void setHeight (std::size_t) noexcept;
93 void setSize (std::size_t, std::size_t) noexcept;
94 void setSize (
const FSize&) noexcept;
95 void setRect (
const FRect&) noexcept;
96 void setRect (
const FPoint&,
const FSize&) noexcept;
97 void setRect (
int,
int, std::size_t, std::size_t) noexcept;
98 void setCoordinates (
const FPoint&,
const FPoint&) noexcept;
99 void setCoordinates (
int,
int,
int,
int) noexcept;
102 auto isEmpty()
const -> bool;
105 auto x1_ref() & noexcept ->
int&;
106 auto y1_ref() & noexcept ->
int&;
107 auto x2_ref() & noexcept ->
int&;
108 auto y2_ref() & noexcept ->
int&;
111 void move (
int,
int) noexcept;
112 void move (
const FPoint&) noexcept;
113 void scaleBy (
int,
int) noexcept;
114 void scaleBy (
const FPoint&) noexcept;
115 auto contains (
int,
int)
const noexcept -> bool;
116 auto contains (
const FPoint&)
const noexcept -> bool;
117 auto contains (
const FRect&)
const noexcept -> bool;
118 auto overlap (
const FRect&)
const noexcept -> bool;
119 auto intersect (
const FRect&)
const noexcept ->
FRect;
120 auto combined (
const FRect&)
const noexcept ->
FRect;
130 friend inline auto operator + (
const FRect& r,
const FSize& s) ->
FRect 134 , std::size_t(r.X2 - r.X1) + 1 + s.getWidth()
135 , std::size_t(r.Y2 - r.Y1) + 1 + s.getHeight() };
138 friend inline auto operator - (
const FRect& r,
const FSize& s) ->
FRect 142 , std::size_t(r.X2 - r.X1) + 1 - s.getWidth()
143 , std::size_t(r.Y2 - r.Y1) + 1 - s.getHeight() };
146 friend inline auto operator == (
const FRect& r1,
const FRect& r2) ->
bool 148 return r1.X1 == r2.X1
154 friend inline auto operator != (
const FRect& r1,
const FRect& r2) ->
bool 156 return r1.X1 != r2.X1
162 friend inline auto operator << (std::ostream& outstr,
const FRect& r) -> std::ostream&
164 outstr << r.X1 <<
" " 171 friend inline auto operator >> (std::istream& instr,
FRect& r) -> std::istream&
181 r.setCoordinates (x1, y1, x2, y2);
188 inline FRect::FRect (
int x,
int y, std::size_t width, std::size_t height) noexcept
191 , X2{x + int(width) - 1}
192 , Y2{y + int(height) - 1}
196 inline auto FRect::getClassName()
const ->
FString 200 inline auto FRect::getX1()
const noexcept ->
int 204 inline auto FRect::getY1()
const noexcept ->
int 208 inline auto FRect::getX2()
const noexcept ->
int 212 inline auto FRect::getY2()
const noexcept ->
int 216 inline auto FRect::getX()
const noexcept ->
int 220 inline auto FRect::getY()
const noexcept ->
int 224 inline auto FRect::getPos()
const noexcept ->
FPoint 225 {
return { X1, Y1 }; }
228 inline auto FRect::getUpperLeftPos()
const noexcept ->
FPoint 229 {
return { X1, Y1 }; }
232 inline auto FRect::getUpperRightPos()
const noexcept ->
FPoint 233 {
return { X2, Y1 }; }
236 inline auto FRect::getLowerLeftPos()
const noexcept ->
FPoint 237 {
return { X1, Y2 }; }
240 inline auto FRect::getLowerRightPos()
const noexcept ->
FPoint 241 {
return { X2, Y2 }; }
244 inline auto FRect::getWidth()
const noexcept -> std::size_t
246 return static_cast<std::size_t
>(std::max(0, X2 - (X1 - 1)));
250 inline auto FRect::getHeight()
const noexcept -> std::size_t
252 return static_cast<std::size_t
>(std::max(0, Y2 - (Y1 - 1)));
256 inline auto FRect::getSize()
const noexcept ->
FSize 257 {
return {
FSize{getWidth(), getHeight()} }; }
260 inline void FRect::setX1 (
int n) noexcept
264 inline void FRect::setY1 (
int n) noexcept
268 inline void FRect::setX2 (
int n) noexcept
272 inline void FRect::setY2 (
int n) noexcept
276 inline void FRect::setX (
int n) noexcept
278 const int dX = X2 - X1;
284 inline void FRect::setY (
int n) noexcept
286 const int dY = Y2 - Y1;
292 inline void FRect::setPos (
int x,
int y) noexcept
294 const int dX = X2 - X1;
295 const int dY = Y2 - Y1;
303 inline void FRect::setPos (
const FPoint& p) noexcept
305 const int dX = X2 - X1;
306 const int dY = Y2 - Y1;
314 inline void FRect::setWidth (std::size_t w) noexcept
315 { X2 = X1 + int(w) - 1; }
318 inline void FRect::setHeight (std::size_t h) noexcept
319 { Y2 = Y1 + int(h) - 1; }
322 inline void FRect::setSize (std::size_t width, std::size_t height) noexcept
324 X2 = X1 + int(width) - 1;
325 Y2 = Y1 + int(height) - 1;
329 inline void FRect::setSize (
const FSize& s) noexcept
331 X2 = X1 + int(s.getWidth()) - 1;
332 Y2 = Y1 + int(s.getHeight()) - 1;
336 inline void FRect::setRect (
const FRect& r) noexcept
345 inline void FRect::setRect (
const FPoint& p,
const FSize& s) noexcept
349 X2 = p.getX() + int(s.getWidth()) - 1;
350 Y2 = p.getY() + int(s.getHeight()) - 1;
354 inline void FRect::setRect (
int x,
int y, std::size_t width, std::size_t height) noexcept
358 X2 = x + int(width) - 1;
359 Y2 = y + int(height) - 1;
363 inline void FRect::setCoordinates (
const FPoint& p1,
const FPoint& p2) noexcept
365 setCoordinates (p1.getX(), p1.getY(), p2.getX(), p2.getY());
369 inline void FRect::setCoordinates (
int x1,
int y1,
int x2,
int y2) noexcept
378 inline auto FRect::isEmpty()
const ->
bool 379 {
return X2 == X1 - 1 && Y2 == Y1 - 1; }
382 inline auto FRect::x1_ref() & noexcept ->
int&
386 inline auto FRect::y1_ref() & noexcept ->
int&
390 inline auto FRect::x2_ref() & noexcept ->
int&
394 inline auto FRect::y2_ref() & noexcept ->
int&
398 inline void FRect::move (
int dx,
int dy) noexcept
407 inline void FRect::move (
const FPoint& d) noexcept
416 inline void FRect::scaleBy (
int dx,
int dy) noexcept
423 inline void FRect::scaleBy (
const FPoint& d) noexcept
430 inline auto FRect::contains (
int x,
int y)
const noexcept ->
bool 432 return x >= X1 && x <= X2
433 && y >= Y1 && y <= Y2;
437 inline auto FRect::contains (
const FPoint& p)
const noexcept ->
bool 439 return p.getX() >= X1 && p.getX() <= X2
440 && p.getY() >= Y1 && p.getY() <= Y2;
444 inline auto FRect::contains (
const FRect& r)
const noexcept ->
bool 446 return r.X1 >= X1 && r.X2 <= X2
447 && r.Y1 >= Y1 && r.Y2 <= Y2;
451 inline auto FRect::overlap (
const FRect &r)
const noexcept ->
bool 453 return ( std::max(X1, r.X1) <= std::min(X2, r.X2)
454 && std::max(Y1, r.Y1) <= std::min(Y2, r.Y2) );
Definition: class_template.cpp:25