@@ -112,57 +112,57 @@ namespace std::experimental::io2d {
112112
113113 // color
114114
115- constexpr rgba_color::rgba_color () noexcept { }
115+ inline constexpr rgba_color::rgba_color () noexcept { }
116116 template <class T , ::std::enable_if_t <::std::is_integral_v<T>, _Color_is_integral>>
117- 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)
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- 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)
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- constexpr void rgba_color::r (float val) noexcept {
130+ inline constexpr void rgba_color::r (float val) noexcept {
131131 _R = val * _A;
132132 }
133- constexpr void rgba_color::g (float val) noexcept {
133+ inline constexpr void rgba_color::g (float val) noexcept {
134134 _G = val * _A;
135135 }
136- constexpr void rgba_color::b (float val) noexcept {
136+ inline constexpr void rgba_color::b (float val) noexcept {
137137 _B = val * _A;
138138 }
139- constexpr void rgba_color::a (float val) noexcept {
139+ inline constexpr void rgba_color::a (float val) noexcept {
140140 _A = val;
141141 }
142142
143- constexpr float rgba_color::r () const noexcept {
143+ inline constexpr float rgba_color::r () const noexcept {
144144 return _R;
145145 }
146- constexpr float rgba_color::g () const noexcept {
146+ inline constexpr float rgba_color::g () const noexcept {
147147 return _G;
148148 }
149- constexpr float rgba_color::b () const noexcept {
149+ inline constexpr float rgba_color::b () const noexcept {
150150 return _B;
151151 }
152- constexpr float rgba_color::a () const noexcept {
152+ inline constexpr float rgba_color::a () const noexcept {
153153 return _A;
154154 }
155155
156156 template <class T , ::std::enable_if_t <::std::is_integral_v<T>, _Color_is_integral>>
157- constexpr rgba_color& rgba_color::operator *=(T rhs) {
157+ inline constexpr rgba_color& rgba_color::operator *=(T rhs) {
158158 r (::std::min (r () * rhs / 255 .0F , 1 .0F ));
159159 g (::std::min (g () * rhs / 255 .0F , 1 .0F ));
160160 b (::std::min (b () * rhs / 255 .0F , 1 .0F ));
161161 a (::std::min (a () * rhs / 255 .0F , 1 .0F ));
162162 return *this ;
163163 }
164164 template <class U , ::std::enable_if_t <::std::is_floating_point_v<U>, _Color_is_floating>>
165- constexpr rgba_color& rgba_color::operator *=(U rhs) {
165+ inline constexpr rgba_color& rgba_color::operator *=(U rhs) {
166166 r (::std::min (r () * rhs, 1 .0F ));
167167 g (::std::min (g () * rhs, 1 .0F ));
168168 b (::std::min (b () * rhs, 1 .0F ));
@@ -248,6 +248,10 @@ namespace std::experimental::io2d {
248248 return v;
249249 }
250250
251+ inline constexpr point_2d point_2d::zero () noexcept {
252+ return { 0 .0f , 0 .0f };
253+ }
254+
251255 inline point_2d point_2d::to_unit () const noexcept {
252256 auto leng = magnitude ();
253257
@@ -338,7 +342,49 @@ namespace std::experimental::io2d {
338342 return point_2d{ lhs.x / rhs.x , lhs.y / rhs.y };
339343 }
340344
341- inline constexpr matrix_2d& matrix_2d::translate (point_2d value) noexcept {
345+ inline constexpr matrix_2d::matrix_2d () noexcept
346+ : matrix_2d (1 .0f , 0 .0f , 0 .0f , 1 .0f , 0 .0f , 0 .0f ) {}
347+
348+ inline constexpr matrix_2d::matrix_2d (float v00, float v01, float v10, float v11, float v20, float v21) noexcept
349+ : m00 (v00)
350+ , m01 (v01)
351+ , m02 (0 .0f )
352+ , m10 (v10)
353+ , m11 (v11)
354+ , m12 (0 .0f )
355+ , m20 (v20)
356+ , m21 (v21)
357+ , m22 (1 .0f ) {
358+ }
359+
360+ inline constexpr matrix_2d matrix_2d::init_translate (const point_2d& value) noexcept {
361+ return { 1 .0F , 0 .0F , 0 .0F , 1 .0F , value.x , value.y };
362+ }
363+ inline constexpr matrix_2d matrix_2d::init_scale (const point_2d& value) noexcept {
364+ return { value.x , 0 .0F , 0 .0F , value.y , 0 .0F , 0 .0F };
365+ }
366+ inline matrix_2d matrix_2d::init_rotate (float radians) noexcept {
367+ auto sine = sin (radians);
368+ auto cosine = cos (radians);
369+ sine = _Round_floating_point_to_zero (sine);
370+ cosine = _Round_floating_point_to_zero (cosine);
371+ return { cosine, -sine, sine, cosine, 0 .0F , 0 .0F };
372+ }
373+ inline matrix_2d matrix_2d::init_reflect (float radians) noexcept {
374+ auto sine = sin (radians * 2 .0F );
375+ auto cosine = cos (radians * 2 .0F );
376+ sine = _Round_floating_point_to_zero (sine);
377+ cosine = _Round_floating_point_to_zero (cosine);
378+ return { cosine, sine, sine, -cosine, 0 .0F , 0 .0F };
379+ }
380+ inline constexpr matrix_2d matrix_2d::init_shear_x (float factor) noexcept {
381+ return { 1 .0F , 0 .0F , factor, 1 .0F , 0 .0F , 0 .0F };
382+ }
383+ inline constexpr matrix_2d matrix_2d::init_shear_y (float factor) noexcept {
384+ return { 1 .0F , factor, 0 .0F , 1 .0F , 0 .0F , 0 .0F };
385+ }
386+
387+ inline constexpr matrix_2d& matrix_2d::translate (point_2d value) noexcept {
342388 *this = *this * init_translate (value);
343389 return *this ;
344390 }
0 commit comments