Skip to content

Commit deda638

Browse files
committed
Ensure R6 compliance
Chapter 6. Colors
1 parent e36d3ea commit deda638

File tree

3 files changed

+89
-124
lines changed

3 files changed

+89
-124
lines changed

N3888_RefImpl/src/io2d.h

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -36,92 +36,6 @@
3636
#define _IO2D_API
3737
#endif
3838

39-
/*
40-
namespace std::experimental::io2d {
41-
inline namespace v1 {
42-
43-
using dashes = tuple<vector<float>, float>;
44-
45-
template <class T>
46-
constexpr T pi = T(3.14159265358979323846264338327950288L);
47-
template <class T>
48-
constexpr T two_pi = T(6.28318530717958647692528676655900577L);
49-
template <class T>
50-
constexpr T half_pi = T(1.57079632679489661923132169163975144L);
51-
template <class T>
52-
constexpr T three_pi_over_two = T(4.71238898038468985769396507491925432L);
53-
54-
template <class T>
55-
constexpr T tau = T(6.28318530717958647692528676655900577L);
56-
template <class T>
57-
constexpr T three_quarters_tau = T(4.71238898038468985769396507491925432L);
58-
template <class T>
59-
constexpr T half_tau = T(3.14159265358979323846264338327950288L);
60-
template <class T>
61-
constexpr T quarter_tau = T(1.57079632679489661923132169163975144L);
62-
63-
class image_surface;
64-
class display_surface;
65-
66-
enum class format {
67-
invalid,
68-
argb32,
69-
xrgb32,
70-
a8,
71-
rgb16_565,
72-
rgb30
73-
};
74-
75-
enum class scaling {
76-
letterbox, // Same as uniform except that the display_surface is cleared using the letterbox brush first
77-
uniform, // Maintain aspect ratio and center as needed, ignoring side areas that are not drawn to
78-
fill_uniform, // Maintain aspect ratio but fill entire display (some content may not be shown)
79-
fill_exact, // Ignore aspect ratio and use (possibly non-uniform) scale to fill exactly
80-
none // Do not scale.
81-
};
82-
83-
enum class refresh_rate {
84-
as_needed,
85-
as_fast_as_possible,
86-
fixed
87-
};
88-
89-
_IO2D_API int format_stride_for_width(format format, int width) noexcept;
90-
_IO2D_API display_surface make_display_surface(int preferredWidth,
91-
int preferredHeight, format preferredFormat,
92-
scaling scl = scaling::letterbox,
93-
refresh_rate rr = refresh_rate::as_fast_as_possible, float fps = 30.0f);
94-
display_surface make_display_surface(int preferredWidth,
95-
int preferredHeight, format preferredFormat, error_code& ec,
96-
scaling scl = scaling::letterbox,
97-
refresh_rate rr = refresh_rate::as_fast_as_possible, float fps = 30.0f) noexcept;
98-
_IO2D_API display_surface make_display_surface(int preferredWidth,
99-
int preferredHeight, format preferredFormat, int preferredDisplayWidth,
100-
int preferredDisplayHeight, scaling scl = scaling::letterbox,
101-
refresh_rate rr = refresh_rate::as_fast_as_possible, float fps = 30.0f);
102-
display_surface make_display_surface(int preferredWidth,
103-
int preferredHeight, format preferredFormat, int preferredDisplayWidth,
104-
int preferredDisplayHeight, error_code& ec,
105-
scaling scl = scaling::letterbox,
106-
refresh_rate rr = refresh_rate::as_fast_as_possible, float fps = 30.0f) noexcept;
107-
_IO2D_API image_surface make_image_surface(format format, int width, int height);
108-
_IO2D_API image_surface make_image_surface(format format, int width, int height,
109-
error_code& ec) noexcept;
110-
image_surface copy_image_surface(image_surface& sfc) noexcept;
111-
float angle_for_point(point_2d ctr, point_2d pt,
112-
point_2d scl = point_2d{ 1.0f, 1.0f }) noexcept;
113-
point_2d point_for_angle(float ang, float rad = 1.0f) noexcept;
114-
point_2d point_for_angle(float ang, point_2d rad) noexcept;
115-
point_2d arc_start(point_2d ctr, float sang, point_2d rad,
116-
const matrix_2d& m = matrix_2d{}) noexcept;
117-
point_2d arc_center(point_2d cpt, float sang, point_2d rad,
118-
const matrix_2d& m = matrix_2d{}) noexcept;
119-
point_2d arc_end(point_2d cpt, float eang, point_2d rad,
120-
const matrix_2d& m = matrix_2d{}) noexcept;
121-
}
122-
}
123-
*/
124-
12539
namespace std {
12640
namespace experimental {
12741
namespace io2d {

N3888_RefImpl/src/xcolor.h

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,39 @@ namespace std::experimental::io2d {
1313
float _G = 0.0F;
1414
float _B = 0.0F;
1515
float _A = 1.0F;
16+
1617
public:
1718
constexpr rgba_color() noexcept;
19+
1820
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
19-
constexpr rgba_color(T r, T g, T b, T a = static_cast<T>(0xFF));
20-
template <class T, ::std::enable_if_t<::std::is_floating_point_v<T>, _Color_is_floating> = _Color_is_floating_val>
21-
constexpr rgba_color(T r, T g, T b, T a = 1.0F);
21+
constexpr rgba_color(T r, T g, T b, T a = static_cast<T>(0xFF)) noexcept;
22+
23+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
24+
constexpr rgba_color(U r, U g, U b, U a = 1.0F) noexcept;
2225

23-
constexpr void r(float val) noexcept;
24-
constexpr void g(float val) noexcept;
25-
constexpr void b(float val) noexcept;
26-
constexpr void a(float val) noexcept;
26+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
27+
constexpr void r(T val) noexcept;
28+
29+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
30+
constexpr void r(U val) noexcept;
31+
32+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
33+
constexpr void g(T val) noexcept;
34+
35+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
36+
constexpr void g(U val) noexcept;
37+
38+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
39+
constexpr void b(T val) noexcept;
40+
41+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
42+
constexpr void b(U val) noexcept;
43+
44+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
45+
constexpr void a(T val) noexcept;
46+
47+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
48+
constexpr void a(U val) noexcept;
2749

2850
constexpr float r() const noexcept;
2951
constexpr float g() const noexcept;
@@ -180,24 +202,26 @@ namespace std::experimental::io2d {
180202
_IO2D_API static const rgba_color yellow_green;
181203

182204
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
183-
constexpr rgba_color& operator*=(T rhs);
205+
constexpr rgba_color& operator*=(T rhs) noexcept;
184206

185207
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
186-
constexpr rgba_color& operator*=(U rhs);
208+
constexpr rgba_color& operator*=(U rhs) noexcept;
187209
};
188210

189-
constexpr bool operator==(const rgba_color& lhs, const rgba_color& rhs)
190-
noexcept;
191-
constexpr bool operator!=(const rgba_color& lhs, const rgba_color& rhs)
192-
noexcept;
193-
template <class T>
211+
constexpr bool operator==(const rgba_color& lhs, const rgba_color& rhs) noexcept;
212+
213+
constexpr bool operator!=(const rgba_color& lhs, const rgba_color& rhs) noexcept;
214+
215+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
194216
constexpr rgba_color operator*(const rgba_color& lhs, T rhs) noexcept;
195-
template <class U>
217+
218+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
196219
constexpr rgba_color operator*(const rgba_color& lhs, U rhs) noexcept;
197-
template <class T>
220+
221+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
198222
constexpr rgba_color operator*(T lhs, const rgba_color& rhs) noexcept;
199-
template <class U>
200-
constexpr rgba_color operator*(U lhs, const rgba_color& rhs) noexcept;
201223

224+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
225+
constexpr rgba_color operator*(U lhs, const rgba_color& rhs) noexcept;
202226
}
203227
}

N3888_RefImpl/src/xio2d_impl.h

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,59 @@ namespace std::experimental::io2d {
114114

115115
inline constexpr rgba_color::rgba_color() noexcept { }
116116
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral>>
117-
inline constexpr rgba_color::rgba_color(T r, T g, T b, T a)
117+
inline constexpr rgba_color::rgba_color(T r, T g, T b, T a) noexcept
118118
: _R(static_cast<float>(::std::min<float>(::std::max<float>((r / 255.0F), 0.0F), 1.0F)))
119119
, _G(static_cast<float>(::std::min<float>(::std::max<float>((g / 255.0F), 0.0F), 1.0F)))
120120
, _B(static_cast<float>(::std::min<float>(::std::max<float>((b / 255.0F), 0.0F), 1.0F)))
121121
, _A(static_cast<float>(::std::min<float>(::std::max<float>((a / 255.0F), 0.0F), 1.0F))) { }
122122
template <class T, ::std::enable_if_t<::std::is_floating_point_v<T>, _Color_is_floating>>
123-
inline constexpr rgba_color::rgba_color(T r, T g, T b, T a)
123+
inline constexpr rgba_color::rgba_color(T r, T g, T b, T a) noexcept
124124
: _R(static_cast<float>(::std::min<T>(::std::max<T>(static_cast<float>(r), 0.0F), 1.0F)))
125125
, _G(static_cast<float>(::std::min<T>(::std::max<T>(static_cast<float>(g), 0.0F), 1.0F)))
126126
, _B(static_cast<float>(::std::min<T>(::std::max<T>(static_cast<float>(b), 0.0F), 1.0F)))
127127
, _A(static_cast<float>(::std::min<T>(::std::max<T>(static_cast<float>(a), 0.0F), 1.0F))) {
128128
}
129129

130-
inline constexpr void rgba_color::r(float val) noexcept {
131-
_R = val * _A;
132-
}
133-
inline constexpr void rgba_color::g(float val) noexcept {
134-
_G = val * _A;
135-
}
136-
inline constexpr void rgba_color::b(float val) noexcept {
137-
_B = val * _A;
138-
}
139-
inline constexpr void rgba_color::a(float val) noexcept {
140-
_A = val;
141-
}
130+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
131+
inline constexpr void r(T val) noexcept {
132+
_R = val * _A;
133+
}
134+
135+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
136+
inline constexpr void r(U val) noexcept {
137+
_R = val * _A;
138+
}
139+
140+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
141+
inline constexpr void g(T val) noexcept {
142+
_G = val * _A;
143+
}
142144

145+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
146+
inline constexpr void g(U val) noexcept {
147+
_G = val * _A;
148+
}
149+
150+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
151+
inline constexpr void b(T val) noexcept {
152+
_B = val * _A;
153+
}
154+
155+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
156+
inline constexpr void b(U val) noexcept {
157+
_B = val * _A;
158+
}
159+
160+
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral> = _Color_is_integral_val>
161+
inline constexpr void a(T val) noexcept {
162+
_A = val;
163+
}
164+
165+
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating> = _Color_is_floating_val>
166+
inline constexpr void a(U val) noexcept {
167+
_A = val;
168+
}
169+
143170
inline constexpr float rgba_color::r() const noexcept {
144171
return _R;
145172
}
@@ -154,15 +181,15 @@ namespace std::experimental::io2d {
154181
}
155182

156183
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral>>
157-
inline constexpr rgba_color& rgba_color::operator*=(T rhs) {
184+
inline constexpr rgba_color& rgba_color::operator*=(T rhs) noexcept {
158185
r(::std::min(r() * rhs / 255.0F, 1.0F));
159186
g(::std::min(g() * rhs / 255.0F, 1.0F));
160187
b(::std::min(b() * rhs / 255.0F, 1.0F));
161188
a(::std::min(a() * rhs / 255.0F, 1.0F));
162189
return *this;
163190
}
164191
template <class U, ::std::enable_if_t<::std::is_floating_point_v<U>, _Color_is_floating>>
165-
inline constexpr rgba_color& rgba_color::operator*=(U rhs) {
192+
inline constexpr rgba_color& rgba_color::operator*=(U rhs) noexcept {
166193
r(::std::min(r() * rhs, 1.0F));
167194
g(::std::min(g() * rhs, 1.0F));
168195
b(::std::min(b() * rhs, 1.0F));
@@ -178,7 +205,7 @@ namespace std::experimental::io2d {
178205
}
179206

180207
template <class T, ::std::enable_if_t<::std::is_floating_point_v<T>, _Color_is_floating>>
181-
inline constexpr rgba_color operator*(const rgba_color& lhs, T rhs) {
208+
inline constexpr rgba_color operator*(const rgba_color& lhs, T rhs) noexcept {
182209
rhs = ::std::max(::std::min(rhs, 1.0F), 0.0F);
183210
return{
184211
::std::min(lhs.r() * rhs, 1.0F),
@@ -189,7 +216,7 @@ namespace std::experimental::io2d {
189216
}
190217

191218
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral>>
192-
inline constexpr rgba_color operator*(const rgba_color& lhs, T rhs) {
219+
inline constexpr rgba_color operator*(const rgba_color& lhs, T rhs) noexcept {
193220
rhs = ::std::max(::std::min(rhs, 1.0F), 0.0F);
194221
return{
195222
::std::min(lhs.r() * rhs / 255.0F, 1.0F),
@@ -200,7 +227,7 @@ namespace std::experimental::io2d {
200227
}
201228

202229
template <class T, ::std::enable_if_t<::std::is_floating_point_v<T>, _Color_is_floating>>
203-
inline constexpr rgba_color operator*(T lhs, const rgba_color& rhs) {
230+
inline constexpr rgba_color operator*(T lhs, const rgba_color& rhs) noexcept {
204231
lhs = ::std::max(::std::min(lhs, 1.0F), 0.0F);
205232
return{
206233
::std::min(lhs * rhs.r(), 1.0F),
@@ -211,7 +238,7 @@ namespace std::experimental::io2d {
211238
}
212239

213240
template <class T, ::std::enable_if_t<::std::is_integral_v<T>, _Color_is_integral>>
214-
inline constexpr rgba_color operator*(T lhs, const rgba_color& rhs) {
241+
inline constexpr rgba_color operator*(T lhs, const rgba_color& rhs) noexcept {
215242
lhs = ::std::max(::std::min(lhs, 1.0F), 0.0F);
216243
return{
217244
::std::min(lhs / 255.0F * rhs.r(), 1.0F),

0 commit comments

Comments
 (0)