acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
size.h
1#pragma once
2
3
4#include "acme/prototype/geometry2d/_function.h"
5#include "acme/prototype/geometry/sequence.h"
6
7
8template < prototype_number NUMBER >
9class size_type :
10 public sequence_type < NUMBER, 2 >
11{
12public:
13
14
15// NUMBER cx;
16 // NUMBER cy;
17
18
19 //using SIZE_BASE_TYPE = BASE_TYPE;
20 using UNIT_TYPE = NUMBER;
21 //using POINT_TYPE = point_type < NUMBER >;
22 //using RECTANGLE_TYPE = rectangle_type < NUMBER >;
23
24
25
26
27 constexpr size_type() {}
28 constexpr size_type(no_initialize_t) : sequence_type < NUMBER, 2 >(no_initialize_t{}) {}
29 //size_type(nullptr_t) : sequence_type < NUMBER, 2 >(nullptr) {}
30
31// sequence_type(const sequence_type&) = default;
32
33// template <prototype_number T,
34// std::enable_if_t<T::SIZE == SIZE &&
35// std::is_same_v<typename T::COORDINATE, COORDINATE>, ::i32> = 0>
36// sequence_type(const T & a) {
37// for (size_t i = 0; i < SIZE; ++i)
38// m_coordinatea[i] = (COORDINATE)a[i];
39// }
40
41 template < prototype_number C >
42 constexpr size_type(C c)
43 {
44
45 this->set_all((NUMBER)c);
46
47 }
48
49 template < prototype_number CX, prototype_number CY >
50 constexpr size_type(CX cx, CY cy)
51 {
52 this->m_coordinatea[0] = (UNIT_TYPE) cx;
53 this->m_coordinatea[1] = (UNIT_TYPE) cy;
54 }
55
56 template < prototype_number NUMBER1 >
57 constexpr size_type(const sequence_type < NUMBER1, 2 > & sequence) :
58 sequence_type < UNIT_TYPE, 2 >(sequence)
59 {
60
61 }
62
63
64
65
66
67 //using sequence_type < NUMBER, 2 >::sequence_type;
68
69 //size_type() noexcept { this->cx = UNIT_TYPE{}; this->cy = UNIT_TYPE{}; }
70 //size_type(no_initialize_t) noexcept {}
71 //size_type(nullptr_t) noexcept { this->cx = UNIT_TYPE{}; this->cy = UNIT_TYPE{}; }
72 //size_type(UNIT_TYPE cx, UNIT_TYPE cy) noexcept { this->cx = cx; this->cy = cy; }
73// template < prototype_number NUMBER_TYPE >
74// size_type(NUMBER_TYPE n) noexcept { this->cx = (UNIT_TYPE) n; this->cy = (UNIT_TYPE) n; }
75 //size_type(::u32 u) noexcept { this->cx = (UNIT_TYPE) u; this->cy = (UNIT_TYPE) u; }
76 //size_type(::i64 i) noexcept { this->cx = (UNIT_TYPE) i; this->cy = (UNIT_TYPE) i; }
77 //size_type(::u64 u) noexcept { this->cx = (UNIT_TYPE) u; this->cy = (UNIT_TYPE) u; }
78 //size_type(::f32 f) noexcept { this->cx = (UNIT_TYPE) f; this->cy = (UNIT_TYPE) f; }
79 //size_type(::f64 d) noexcept { this->cx = (UNIT_TYPE) d; this->cy = (UNIT_TYPE) d; }
80// explicit size_type(const lparam & lparam) noexcept : size_type(lparam.x, lparam.y) {}
81 //template < prototype_point POINT >
82// size_type(const sequence_type < UNIT_TYPE, 2 > & sequence) noexcept { this->cx = sequence.x; this->cy = sequence.y; }
83// template < prototype_rectangle RECTANGLE >
84// size_type(const RECTANGLE & rectangle) noexcept { this->cx = (UNIT_TYPE)::width(rectangle); this->cy = (UNIT_TYPE)::height(rectangle); }
85// template < prototype_size SIZE >
86// size_type(const SIZE & size) noexcept : size_type((UNIT_TYPE)size.cx, (UNIT_TYPE)size.cy) {}
87 //size_type(const ::i64_size& size) noexcept : size_type((UNIT_TYPE)size.cx, (UNIT_TYPE)size.cy) {}
88 //size_type(const ::f32_size& size) noexcept : size_type((UNIT_TYPE)size.cx, (UNIT_TYPE)size.cy) {}
89 //size_type(const ::f64_size& size) noexcept : size_type((UNIT_TYPE)size.cx, (UNIT_TYPE)size.cy) {}
90 //size_type(const ::i32_size* psize) noexcept : size_type(*psize) {}
91 //size_type(const ::i64_size* psize) noexcept : size_type(*psize) {}
92 //size_type(const ::f32_size* psize) noexcept : size_type(*psize) {}
93 //size_type(const ::f64_size* psize) noexcept : size_type(*psize) {}
94//#ifdef __APPLE__
97//#endif
98
99
100 //operator ::i32_size* () noexcept { return this; }
101 //operator const ::i32_size* () const noexcept { return this; }
102 //operator bool () const noexcept { return is_set(); }
103
104 // constexpr const NUMBER & cx() const { return this->x; }
105 // constexpr const NUMBER & cy() const { return this->y; }
106 // NUMBER & cx() { return this->x; }
107 // NUMBER & cy() { return this->y; }
108
109 size_type& Null() { this->cx = (UNIT_TYPE)0; this->cy = (UNIT_TYPE)0; return *this; }
110
111 template < prototype_point POINT >
112 POINT operator +(const POINT& point1) const noexcept { POINT point(point1); ::offset(point, this->cx, this->cy); return point; }
113 template < prototype_point POINT >
114 POINT operator-(const POINT & point1) const noexcept { POINT point(this->cx, this->cy); ::offset(point, -point1.x, -point1.y); return point; }
115
116// RECTANGLE_TYPE operator +(const RECTANGLE_TYPE& rect1) const noexcept { RECTANGLE_TYPE rectangle(rect1); ::offset(rectangle, this->cx, this->cy); return rectangle; }
117// RECTANGLE_TYPE operator-(const RECTANGLE_TYPE& rect1) const noexcept { RECTANGLE_TYPE rectangle(rect1); ::offset(rectangle, -this->cx, -this->cy); return rectangle; }
118
119 UNIT_TYPE area() const noexcept { return ::area(this->cx, this->cy); }
120 inline bool is_empty() const noexcept { return this->cx <= 0 || this->cy <= 0; }
121 inline bool is_set() const noexcept { return !is_empty(); }
122 inline bool has_area() const noexcept { return is_set(); }
123
124
125 consteval size2_t semantic_t() const { return {}; }
126
127 ::u32 as_u32() const noexcept { return as_u32(this->cx, this->cy); }
128 ::u64 as_u64() const noexcept { return as_u64(this->cx, this->cy); }
129 class lparam lparam() const noexcept { return make_u32(this->cx, this->cy); }
130
131 inline UNIT_TYPE width() const noexcept { return this->cx; }
132 inline UNIT_TYPE height() const noexcept { return this->cy; }
133
134// inline UNIT_TYPE get_minimum_dimension() const noexcept { return ::minimum(this->cx, this->cy); }
135// inline UNIT_TYPE get_maximum_dimension() const noexcept { return ::maximum(this->cx, this->cy); }
136
137// inline UNIT_TYPE get_dimension(enum_orientation eorientation) const noexcept { return ::get_dimension(eorientation, this->cx, this->cy); }
138// inline UNIT_TYPE get_orthogonal_dimension(enum_orientation eorientation) const noexcept { return ::get_normal_dimension(eorientation, this->cx, this->cy); }
139// inline UNIT_TYPE get_orthogonal(enum_orientation eorientation)const noexcept { return get_orthogonal_dimension(eorientation); }
140// inline UNIT_TYPE get_normal_dimension(enum_orientation eorientation) const noexcept { return get_orthogonal_dimension(eorientation); }
141// inline UNIT_TYPE get_normal(enum_orientation eorientation) const noexcept { return get_orthogonal_dimension(eorientation); }
142//
143// inline UNIT_TYPE set_dimension(enum_orientation eorientation, UNIT_TYPE l) noexcept { if (eorientation == e_orientation_horizontal) this->cx = l; else if (eorientation == e_orientation_vertical) this->cy = l; return l; }
144// inline UNIT_TYPE set_orthogonal_dimension(enum_orientation eorientation, UNIT_TYPE l) noexcept { if(eorientation == e_orientation_horizontal) this->cy = l; else if (eorientation == e_orientation_vertical) this->cx = l; return l;}
145// inline UNIT_TYPE set_orthogonal(enum_orientation eorientation, UNIT_TYPE l) noexcept { return set_orthogonal_dimension(eorientation, l); }
146// inline UNIT_TYPE set_normal_dimension(enum_orientation eorientation, UNIT_TYPE l) noexcept { return set_orthogonal_dimension(eorientation, l); }
147// inline UNIT_TYPE set_normal(enum_orientation eorientation, UNIT_TYPE l) noexcept { return set_orthogonal_dimension(eorientation, l); }
148
149 inline void set(UNIT_TYPE c) noexcept { this->cx = this->cy = c; }
150 inline void set(UNIT_TYPE cx, UNIT_TYPE cy) noexcept { this->cx = cx; this->cy = cy; }
151
152 inline UNIT_TYPE minimum() const {return sequence_type <UNIT_TYPE, 2>::minimum();}
153 inline UNIT_TYPE maximum() const {return sequence_type <UNIT_TYPE, 2>::maximum();}
154 inline size_type minimum(const size_type & s)const noexcept { return size_type(::minimum(this->cx, s.cx), ::minimum(this->cy, s.cy)); }
155 inline size_type maximum(const size_type& s)const noexcept { return size_type(::maximum(this->cx, s.cx), ::maximum(this->cy, s.cy)); }
156
157 inline size_type & ensure_at_most(const size_type & s) noexcept { this->cx = ::minimum(this->cx, s.cx); this->cy = ::minimum(this->cy, s.cy); return *this; }
158 inline size_type & ensure_at_least(const size_type & s) noexcept { this->cx = ::maximum(this->cx, s.cx); this->cy = ::maximum(this->cy, s.cy); return *this; }
159
160 inline static size_type unit_size() { return size_type(1, 1); }
161
162 inline size_type transposed() const { return size_type(this->cy, this->cx); }
163
164 inline size_type aspect_width(UNIT_TYPE w) { return size_type(w, w * this->cy / this->cx); }
165 inline size_type aspect_height(UNIT_TYPE h) { return size_type(h * this->cx / this->cy, h); }
166 inline ::design::enum_fit get_fit(size_type s) { return (::design::enum_fit) ::numeric::sign(s.cx *this->cy - s.cy * this->cx); }
167 inline size_type fit(size_type s)
168 {
169 if (get_fit(s) == ::design::e_fit_height) return aspect_height(s.cy); else return aspect_width(s.cx);
170 }
171 inline ::design::enum_match get_expand(size_type s) { return (::design::enum_match)(-(::i32)get_fit(s)); }
172 inline size_type expand(size_type s)
173 {
174 if (get_expand(s) == ::design::e_match_height) return aspect_height(s.cy); else return aspect_width(s.cx);
175 }
176
177 inline size_type & operator =(const size_type & size) noexcept { this->cx = size.cx; this->cy = size.cy; return *this; }
178
179 template < prototype_size SIZE >
180 inline size_type & operator +=(const SIZE & size) noexcept { this->cx += size.cx; this->cy += size.cy; return *this; }
181
182 template < prototype_size SIZE >
183 inline size_type & operator-=(const SIZE & size) noexcept { this->cx -= size.cx; this->cy -= size.cy; return *this; }
184
185// template < prototype_point POINT >
186// inline size_type & operator +=(const POINT & point) noexcept { this->cx += point.x; this->cy += point.y; return *this; }
187
188 template < prototype_number NUMBER1 >
189 inline size_type & operator +=(const sequence_type < NUMBER1, 2 > & sequence) noexcept { this->cx = (UNIT_TYPE) (this->cx + sequence.x); this->cy = (UNIT_TYPE) (this->cy + sequence.y); return *this; }
190
191 template < prototype_number NUMBER1 >
192 inline size_type & operator -=(const sequence_type < NUMBER1, 2 > & sequence) noexcept { this->cx = (UNIT_TYPE) (this->cx - sequence.x); this->cy = (UNIT_TYPE) (this->cy - sequence.y); return *this; }
193
194// template < prototype_point POINT >
195// inline size_type & operator-=(const POINT & point) noexcept { this->cx -= point.x; this->cy -= point.y; return *this; }
196
197 template < prototype_number NUMBER1 >
198 inline size_type & operator +=(NUMBER1 n) noexcept { this->cx = UNIT_TYPE(this->cx + n); this->cy = UNIT_TYPE(this->cy + n); return *this; }
199
200 template < prototype_number NUMBER1 >
201 inline size_type & operator -=(NUMBER1 n) noexcept { this->cx = UNIT_TYPE(this->cx - n); this->cy = UNIT_TYPE(this->cy - n); return *this; }
202
203 template < prototype_number NUMBER1 >
204 inline size_type & operator *=(NUMBER1 n) noexcept { this->cx = UNIT_TYPE(this->cx * n); this->cy = UNIT_TYPE(this->cy * n); return *this; }
205
206 template < prototype_number NUMBER1 >
207 inline size_type & operator /=(NUMBER1 n) noexcept { this->cx = UNIT_TYPE(this->cx / n); this->cy = UNIT_TYPE(this->cy / n); return *this; }
208
209 inline void set_size(UNIT_TYPE cx, UNIT_TYPE cy) noexcept {this->cx = cx; this->cy = cy; }
210 inline void set_size(const size_type & size_type) noexcept { set_size(size_type.cx, size_type.cy); }
211
212 template < prototype_number NUMBER1 >
213 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator +(const sequence_type < NUMBER1, 2 > & sequence) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > > ((largest_number < UNIT_TYPE, NUMBER1 >) (this->cx + sequence.x), (largest_number < UNIT_TYPE, NUMBER1 >) (this->cy + sequence.y)); }
214
215 template < prototype_number NUMBER1 >
216 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator -(const sequence_type < NUMBER1, 2 > & sequence) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > > ((largest_number < UNIT_TYPE, NUMBER1 >) (this->cx - sequence.x), (largest_number < UNIT_TYPE, NUMBER1 >) (this->cy - sequence.y)); }
217
218 inline size_type operator-() const noexcept { return size_type(-this->cx, -this->cy); }
219
220//#ifdef WINDOWS
221// inline size_type operator /(::i32 i) const noexcept { return size_type((UNIT_TYPE)(this->cx / i), (UNIT_TYPE)(this->cy / i)); }
222//#endif
223
224 template < prototype_number NUMBER1 >
225 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator /(NUMBER1 l) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((largest_number < UNIT_TYPE, NUMBER1 >)(this->cx / l), (largest_number < UNIT_TYPE, NUMBER1 >)(this->cy / l)); }
226// inline size_type operator /(::i64 i) const noexcept { return size_type((UNIT_TYPE)(this->cx / i), (UNIT_TYPE)(this->cy / i)); }
227// inline size_type operator /(::f32 f) const noexcept { return size_type((UNIT_TYPE)(this->cx / f), (UNIT_TYPE)(this->cy / f)); }
228// inline size_type operator /(::f64 d) const noexcept { return size_type((UNIT_TYPE)(this->cx / d), (UNIT_TYPE)(this->cy / d)); }
229 template < prototype_number NUMBER1 >
230 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator /(const sequence_type <NUMBER1, 2> & sequence) const { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((largest_number < UNIT_TYPE, NUMBER1 >)(this->cx / sequence.x), (largest_number < UNIT_TYPE, NUMBER1 >)(this->cy / sequence.y)); }
231
232 template < prototype_number NUMBER1 >
233 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator *(NUMBER1 d) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((largest_number < UNIT_TYPE, NUMBER1 >)(this->cx * d), (largest_number < UNIT_TYPE, NUMBER1 >)(this->cy * d)); }
234
235 //inline size_type operator +(::i32 i) const noexcept { return size_type(this->cx + i, this->cy + i); }
236 template < prototype_number NUMBER1 >
237 inline size_type<largest_number < UNIT_TYPE, NUMBER1 >> operator +(NUMBER1 d) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((largest_number < UNIT_TYPE, NUMBER1 >)(this->cx + d), (largest_number < UNIT_TYPE, NUMBER1 >)(this->cy + d)); }
238
239// inline size_type operator -(::i32 i) const noexcept { return size_type(this->cx - i, this->cy - i); }
240 template < prototype_number NUMBER1 >
241 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > operator -(NUMBER1 d) const noexcept { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((largest_number < UNIT_TYPE, NUMBER1 >)(this->cx - d), (largest_number < UNIT_TYPE, NUMBER1 >)(this->cy - d)); }
242
243
244 template < prototype_number NUMBER1 >
245 inline size_type < largest_number < UNIT_TYPE, NUMBER1 > > half_away(const size_type < NUMBER1 >& size) { return size_type < largest_number < UNIT_TYPE, NUMBER1 > >((this->cx - size.cx) / (largest_number < UNIT_TYPE, NUMBER1 >) 2, (this->cy - size.cy) / (largest_number < UNIT_TYPE, NUMBER1 >) 2); }
246
247// inline bool operator ==(nullptr_t) const noexcept { return ::is_null(this); }
248// inline bool operator !=(nullptr_t) const noexcept { return !operator==(nullptr); }
249
250 inline bool operator == (const size_type & size) const noexcept { return this->cx == size.cx && this->cy == size.cy; }
251// inline bool operator != (const size_type & size) const noexcept { return !operator ==(size); }
252
253// inline bool operator == (const RECTANGLE_TYPE & rectangle) const noexcept { return this->cx == rectangle.width() && this->cy == rectangle.height(); }
254 //inline bool operator != (const RECTANGLE_TYPE & rectangle) const noexcept { return !operator ==(rectangle); }
255
256 inline bool operator >= (const size_type & size) const noexcept
257 {
258
259 return this->cx >= size.cx && this->cy >= size.cy;
260
261 }
262
263
264 inline bool operator > (const size_type & size) const noexcept
265 {
266
267 return *this >= size && *this != size;
268
269 }
270
271
272 inline bool operator <= (const size_type & size) const noexcept
273 {
274
275 return this->cx <= size.cx && this->cy <= size.cy;
276
277 }
278
279
280 inline bool operator < (const size_type & size) const noexcept
281 {
282
283 return *this <= size && *this != size;
284
285 }
286// inline ::std::strong_ordering operator <=> (const RECTANGLE_TYPE & rectangle) const noexcept { return this->operator <=> (rectangle.size()); }
287 //inline bool operator >= (const RECTANGLE_TYPE & rectangle) const noexcept { return this->operator >= (rectangle.size()); }
288 //inline bool operator < (const RECTANGLE_TYPE & rectangle) const noexcept { return this->operator < (rectangle.size()); }
289 //inline bool operator <= (const RECTANGLE_TYPE & rectangle) const noexcept { return this->operator <= (rectangle.size()); }
290
291 inline bool any_gt (const size_type & size) const noexcept { return this->cx > size.cx || this->cy > size.cy; }
292 inline bool any_ge (const size_type & size) const noexcept { return this->cx >= size.cx || this->cy >= size.cy; }
293 inline bool any_lt (const size_type & size) const noexcept { return this->cx < size.cx || this->cy < size.cy; }
294 inline bool any_le (const size_type & size) const noexcept { return this->cx <= size.cx || this->cy <= size.cy; }
295
296// inline bool any_gt (const RECTANGLE_TYPE & rectangle) const noexcept { return this->any_gt(rectangle.size()); }
297// inline bool any_ge (const RECTANGLE_TYPE & rectangle) const noexcept { return this->any_ge(rectangle.size()); }
298// inline bool any_lt (const RECTANGLE_TYPE & rectangle) const noexcept { return this->any_lt(rectangle.size()); }
299// inline bool any_le (const RECTANGLE_TYPE & rectangle) const noexcept { return this->any_le(rectangle.size()); }
300
301
302 constexpr operator hash32() const
303 {
304
305 return ::hash32(this->cx) + ::hash32(this->cy);
306
307 }
308
309};
310
311
312template < prototype_size SIZE >
313inline auto abs(const SIZE & size) noexcept { return SIZE(abs(size.cx), abs(size.cy)); }
314//inline auto abs(const ::i64_size& size) noexcept { return ::i64_size(abs(size.cx), abs(size.cy)); }
315//inline auto abs(const ::f32_size& size) noexcept { return ::f32_size(abs(size.cx), abs(size.cy)); }
316//inline auto abs(const ::f64_size& size) noexcept { return ::f64_size(abs(size.cx), abs(size.cy)); }
317
318
319
320
321
322constexpr ::i32_size lparam::size() const
323{
324
325 return {this->loword(), this->hiword()};
326
327}
328
329
330
331
Definition hash32.h:14
Definition _tags.h:5
Definition _initial_concepts.h:13