34 #if !defined (USE_FINAL_H) && !defined (COMPILE_FINAL_CUT) 35 #error "Only <final/final.h> can be included directly." 42 #include "final/ftypes.h" 43 #include "final/util/fstring.h" 59 FSize () noexcept =
default;
60 template<
typename W
idthT,
typename HeightT>
61 FSize (WidthT, HeightT) noexcept;
68 auto getClassName()
const ->
FString;
69 auto getWidth()
const noexcept -> std::size_t;
70 auto getHeight()
const noexcept -> std::size_t;
71 auto getArea()
const noexcept -> std::size_t;
72 void setWidth (std::size_t) noexcept;
73 void setHeight (std::size_t) noexcept;
74 void setSize (
const FSize&) noexcept;
75 void setSize (std::size_t, std::size_t) noexcept;
78 auto isEmpty()
const noexcept -> bool;
81 auto width_ref() & noexcept -> std::size_t&;
82 auto height_ref() & noexcept -> std::size_t&;
85 void scaleBy (
int,
int) noexcept;
86 void scaleBy (
const FPoint&) noexcept;
91 std::size_t height{0};
94 friend inline auto operator < (
const FSize& s1,
const FSize& s2) ->
bool 96 return s1.width < s2.width && s1.height < s2.height;
99 friend inline auto operator <= (
const FSize& s1,
const FSize& s2) ->
bool 101 return s1.width <= s2.width && s1.height <= s2.height;
104 friend inline auto operator == (
const FSize& s1,
const FSize& s2) ->
bool 106 return s1.width == s2.width && s1.height == s2.height;
109 friend inline auto operator != (
const FSize& s1,
const FSize& s2) ->
bool 111 return s1.width != s2.width || s1.height != s2.height;
114 friend inline auto operator >= (
const FSize& s1,
const FSize& s2) ->
bool 116 return s1.width >= s2.width && s1.height >= s2.height;
119 friend inline auto operator > (
const FSize& s1,
const FSize& s2) ->
bool 121 return s1.width > s2.width && s1.height > s2.height;
124 friend inline auto operator + (
const FSize& s1,
const FSize& s2) ->
FSize 126 constexpr std::size_t max = std::numeric_limits<std::size_t>::max();
127 const std::size_t w = ( s1.width < max - s2.width) ? s1.width + s2.width : max;
128 const std::size_t h = ( s1.height < max - s2.height) ? s1.height + s2.height : max;
129 return {
FSize{w, h} };
132 friend inline auto operator - (
const FSize& s1,
const FSize& s2) ->
FSize 134 const std::size_t w = ( s1.width >= s2.width ) ? s1.width - s2.width : 0;
135 const std::size_t h = ( s1.height >= s2.height ) ? s1.height - s2.height : 0;
136 return {
FSize{w, h} };
139 friend inline auto operator << (std::ostream& outstr,
const FSize& s) -> std::ostream&
141 outstr << s.width <<
" " << s.height;
145 friend inline auto operator >> (std::istream& instr,
FSize& s) -> std::istream&
158 template<
typename W
idthT,
typename HeightT>
159 inline FSize::FSize (WidthT w, HeightT h) noexcept
160 : width{
static_cast<std::size_t
>(w > 0 ? w : 0)}
161 , height{
static_cast<std::size_t
>(h > 0 ? h : 0)}
165 inline auto FSize::getClassName()
const ->
FString 169 inline auto FSize::getWidth()
const noexcept -> std::size_t
173 inline auto FSize::getHeight()
const noexcept -> std::size_t
177 inline auto FSize::getArea()
const noexcept -> std::size_t
178 {
return width * height; }
181 inline void FSize::setWidth (std::size_t w) noexcept
185 inline void FSize::setHeight (std::size_t h) noexcept
189 inline void FSize::setSize (
const FSize& s) noexcept
196 inline void FSize::setSize (std::size_t w, std::size_t h) noexcept
203 inline auto FSize::isEmpty()
const noexcept ->
bool 204 {
return width == 0 && height == 0; }
207 inline auto FSize::width_ref() & noexcept -> std::size_t&
211 inline auto FSize::height_ref() & noexcept -> std::size_t&
Definition: class_template.cpp:25