Skip to content

Commit 4fc1578

Browse files
committed
Separating the implementation
xlinear_algebra.h -> xio2d_impl.h
1 parent 2738ec9 commit 4fc1578

File tree

2 files changed

+69
-56
lines changed

2 files changed

+69
-56
lines changed

N3888_RefImpl/src/xio2d_impl.h

Lines changed: 60 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

N3888_RefImpl/src/xlinear_algebra.h

Lines changed: 9 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ namespace std::experimental::io2d {
1818
constexpr float magnitude_squared() const noexcept;
1919
float angular_direction() const noexcept;
2020
point_2d to_unit() const noexcept;
21-
constexpr static point_2d zero() noexcept {
22-
return { 0.0f, 0.0f };
23-
}
21+
constexpr static point_2d zero() noexcept;
2422

2523
// \ref{\iotwod.\pointtwod.member.ops}, member operators:
2624
constexpr point_2d& operator+=(const point_2d& rhs) noexcept;
@@ -45,19 +43,8 @@ namespace std::experimental::io2d {
4543

4644
class matrix_2d {
4745
public:
48-
constexpr matrix_2d() noexcept
49-
: matrix_2d(1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f) {}
50-
constexpr matrix_2d(float v00, float v01, float v10, float v11, float v20, float v21) noexcept
51-
: m00(v00)
52-
, m01(v01)
53-
, m02(0.0f)
54-
, m10(v10)
55-
, m11(v11)
56-
, m12(0.0f)
57-
, m20(v20)
58-
, m21(v21)
59-
, m22(1.0f) {
60-
}
46+
constexpr matrix_2d() noexcept;
47+
constexpr matrix_2d(float v00, float v01, float v10, float v11, float v20, float v21) noexcept;
6148

6249
float m00;
6350
float m01;
@@ -70,32 +57,12 @@ namespace std::experimental::io2d {
7057
float m22;
7158

7259
// \ref{\iotwod.\matrixtwod.staticfactories}, static factory functions:
73-
constexpr static matrix_2d init_translate(const point_2d& value) noexcept {
74-
return{ 1.0F, 0.0F, 0.0F, 1.0F, value.x, value.y };
75-
}
76-
constexpr static matrix_2d init_scale(const point_2d& value) noexcept {
77-
return{ value.x, 0.0F, 0.0F, value.y, 0.0F, 0.0F };
78-
}
79-
static matrix_2d init_rotate(float radians) noexcept {
80-
auto sine = sin(radians);
81-
auto cosine = cos(radians);
82-
sine = _Round_floating_point_to_zero(sine);
83-
cosine = _Round_floating_point_to_zero(cosine);
84-
return{ cosine, -sine, sine, cosine, 0.0F, 0.0F };
85-
}
86-
static matrix_2d init_reflect(float radians) noexcept {
87-
auto sine = sin(radians * 2.0F);
88-
auto cosine = cos(radians * 2.0F);
89-
sine = _Round_floating_point_to_zero(sine);
90-
cosine = _Round_floating_point_to_zero(cosine);
91-
return{ cosine, sine, sine, -cosine, 0.0F, 0.0F };
92-
}
93-
constexpr static matrix_2d init_shear_x(float factor) noexcept {
94-
return{ 1.0F, 0.0F, factor, 1.0F, 0.0F, 0.0F };
95-
}
96-
constexpr static matrix_2d init_shear_y(float factor) noexcept {
97-
return{ 1.0F, factor, 0.0F, 1.0F, 0.0F, 0.0F };
98-
}
60+
constexpr static matrix_2d init_translate(const point_2d& value) noexcept;
61+
constexpr static matrix_2d init_scale(const point_2d& value) noexcept;
62+
static matrix_2d init_rotate(float radians) noexcept;
63+
static matrix_2d init_reflect(float radians) noexcept;
64+
constexpr static matrix_2d init_shear_x(float factor) noexcept;
65+
constexpr static matrix_2d init_shear_y(float factor) noexcept;
9966

10067
// \ref{\iotwod.\matrixtwod.modifiers}, modifiers:
10168
constexpr matrix_2d& translate(point_2d v) noexcept;

0 commit comments

Comments
 (0)