Skip to content

Commit 90bec2a

Browse files
committed
constexpr fixes
1 parent 713a584 commit 90bec2a

File tree

3 files changed

+76
-76
lines changed

3 files changed

+76
-76
lines changed

include/math/color.hpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,13 @@ struct [[nodiscard]] Color
7171
* @param a alpha channel color value (transparency)
7272
*/
7373
constexpr Color(Color rgb, float a) noexcept : r(rgb.r), g(rgb.g), b(rgb.b),
74-
a(saturate(a) * 255.0f + 0.5f) { }
74+
a(uint8(saturate(a) * 255.0f + 0.5f)) { }
7575

7676
/**
7777
* @brief Creates a new sRGB color structure from the binary data.
7878
* @param data target binary color data
7979
*/
80-
constexpr explicit Color(uint32 data) noexcept { *(uint32*)this = data; }
80+
explicit Color(uint32 data) noexcept { *(uint32*)this = data; }
8181
/**
8282
* @brief Creates a new sRGB color structure from the hexadecimal string.
8383
* @param hex target hexadecimal color string (eg. #FFFFFFFF)
@@ -183,41 +183,41 @@ struct [[nodiscard]] Color
183183
/**
184184
* @brief Returns color binary data.
185185
*/
186-
constexpr explicit operator uint32() const noexcept { return *(const uint32*)this; }
186+
explicit operator uint32() const noexcept { return *(const uint32*)this; }
187187

188188
/*******************************************************************************************************************
189189
* @brief Returns sRGB color normalizer R channel. (Red)
190190
*/
191-
constexpr float getNormR() const noexcept { return r * (1.0f / 255.0f); }
191+
constexpr float getNormR() const noexcept { return (float)r * (1.0f / 255.0f); }
192192
/**
193193
* @brief Returns sRGB color normalizer G channel. (Green)
194194
*/
195-
constexpr float getNormG() const noexcept { return g * (1.0f / 255.0f); }
195+
constexpr float getNormG() const noexcept { return (float)g * (1.0f / 255.0f); }
196196
/**
197197
* @brief Returns sRGB color normalizer B channel. (Blue)
198198
*/
199-
constexpr float getNormB() const noexcept { return b * (1.0f / 255.0f); }
199+
constexpr float getNormB() const noexcept { return (float)b * (1.0f / 255.0f); }
200200
/**
201201
* @brief Returns sRGB color normalizer A channel. (Alpha)
202202
*/
203-
constexpr float getNormA() const noexcept { return a * (1.0f / 255.0f); }
203+
constexpr float getNormA() const noexcept { return (float)a * (1.0f / 255.0f); }
204204

205205
/**
206206
* @brief Sets sRGB color normalizer R channel. (Red)
207207
*/
208-
constexpr void setNormR(float r) noexcept { this->r = saturate(r) * 255.0f + 0.5f; }
208+
constexpr void setNormR(float r) noexcept { this->r = uint8(saturate(r) * 255.0f + 0.5f); }
209209
/**
210210
* @brief Sets sRGB color normalizer G channel. (Green)
211211
*/
212-
constexpr void setNormG(float g) noexcept { this->g = saturate(g) * 255.0f + 0.5f; }
212+
constexpr void setNormG(float g) noexcept { this->g = uint8(saturate(g) * 255.0f + 0.5f); }
213213
/**
214214
* @brief Sets sRGB color normalizer B channel. (Blue)
215215
*/
216-
constexpr void setNormB(float b) noexcept { this->b = saturate(b) * 255.0f + 0.5f; }
216+
constexpr void setNormB(float b) noexcept { this->b = uint8(saturate(b) * 255.0f + 0.5f); }
217217
/**
218218
* @brief Sets sRGB color normalizer A channel. (Alpha)
219219
*/
220-
constexpr void setNormA(float a) noexcept { this->a = saturate(a) * 255.0f + 0.5f; }
220+
constexpr void setNormA(float a) noexcept { this->a = uint8(saturate(a) * 255.0f + 0.5f); }
221221

222222
/*******************************************************************************************************************
223223
* @brief Converts sRGB color to the string. (Space separated)
@@ -242,11 +242,11 @@ struct [[nodiscard]] Color
242242
/**
243243
* @brief Converts sRGB color to the RGB hexadecimal string.
244244
*/
245-
string toHex4() const noexcept { return math::toHex8((const uint8*)this, 4); }
245+
string toHex4() const noexcept { return toHex8((const uint8*)this, 4); }
246246
/**
247247
* @brief Converts sRGB color to the RGBA hexadecimal string.
248248
*/
249-
string toHex3() const noexcept { return math::toHex8((const uint8*)this, 3); }
249+
string toHex3() const noexcept { return toHex8((const uint8*)this, 3); }
250250

251251
/**
252252
* @brief Converts sRGB color to the normalized linear RGB color space.

include/math/matrix/float.hpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,12 @@ struct [[nodiscard]] float2x2
128128
static const float2x2 zero, one, minusOne, identity;
129129
};
130130

131-
inline const float2x2 float2x2::identity = float2x2(
131+
inline constexpr float2x2 float2x2::identity = float2x2(
132132
1.0f, 0.0f,
133133
0.0f, 1.0f);
134-
inline const float2x2 float2x2::zero = float2x2(0.0f);
135-
inline const float2x2 float2x2::one = float2x2(1.0f);
136-
inline const float2x2 float2x2::minusOne = float2x2(-1.0f);
134+
inline constexpr float2x2 float2x2::zero = float2x2(0.0f);
135+
inline constexpr float2x2 float2x2::one = float2x2(1.0f);
136+
inline constexpr float2x2 float2x2::minusOne = float2x2(-1.0f);
137137

138138
/***********************************************************************************************************************
139139
* @brief Floating point 3x3 matrix structure.
@@ -245,13 +245,13 @@ struct [[nodiscard]] float3x3
245245
static const float3x3 zero, one, minusOne, identity;
246246
};
247247

248-
inline const float3x3 float3x3::identity = float3x3(
248+
inline constexpr float3x3 float3x3::identity = float3x3(
249249
1.0f, 0.0f, 0.0f,
250250
0.0f, 1.0f, 0.0f,
251251
0.0f, 0.0f, 1.0f);
252-
inline const float3x3 float3x3::zero = float3x3(0.0f);
253-
inline const float3x3 float3x3::one = float3x3(1.0f);
254-
inline const float3x3 float3x3::minusOne = float3x3(-1.0f);
252+
inline constexpr float3x3 float3x3::zero = float3x3(0.0f);
253+
inline constexpr float3x3 float3x3::one = float3x3(1.0f);
254+
inline constexpr float3x3 float3x3::minusOne = float3x3(-1.0f);
255255

256256
/***********************************************************************************************************************
257257
* @brief Floating point 4x3 matrix structure.
@@ -354,13 +354,13 @@ struct [[nodiscard]] float4x3
354354
static const float4x3 zero, one, minusOne, identity;
355355
};
356356

357-
inline const float4x3 float4x3::identity = float4x3(
357+
inline constexpr float4x3 float4x3::identity = float4x3(
358358
1.0f, 0.0f, 0.0f, 0.0f,
359359
0.0f, 1.0f, 0.0f, 0.0f,
360360
0.0f, 0.0f, 1.0f, 0.0f);
361-
inline const float4x3 float4x3::zero = float4x3(0.0f);
362-
inline const float4x3 float4x3::one = float4x3(1.0f);
363-
inline const float4x3 float4x3::minusOne = float4x3(-1.0f);
361+
inline constexpr float4x3 float4x3::zero = float4x3(0.0f);
362+
inline constexpr float4x3 float4x3::one = float4x3(1.0f);
363+
inline constexpr float4x3 float4x3::minusOne = float4x3(-1.0f);
364364

365365
/***********************************************************************************************************************
366366
* @brief Floating point 3x4 matrix structure.
@@ -462,14 +462,14 @@ struct [[nodiscard]] float3x4
462462
static const float3x4 zero, one, minusOne, identity;
463463
};
464464

465-
inline const float3x4 float3x4::identity = float3x4(
465+
inline constexpr float3x4 float3x4::identity = float3x4(
466466
1.0f, 0.0f, 0.0f,
467467
0.0f, 1.0f, 0.0f,
468468
0.0f, 0.0f, 1.0f,
469469
0.0f, 0.0f, 0.0f);
470-
inline const float3x4 float3x4::zero = float3x4(0.0f);
471-
inline const float3x4 float3x4::one = float3x4(1.0f);
472-
inline const float3x4 float3x4::minusOne = float3x4(-1.0f);
470+
inline constexpr float3x4 float3x4::zero = float3x4(0.0f);
471+
inline constexpr float3x4 float3x4::one = float3x4(1.0f);
472+
inline constexpr float3x4 float3x4::minusOne = float3x4(-1.0f);
473473

474474
/***********************************************************************************************************************
475475
* @brief Floating point 4x4 matrix structure.
@@ -621,14 +621,14 @@ struct [[nodiscard]] float4x4
621621
static const float4x4 zero, one, minusOne;
622622
};
623623

624-
inline const float4x4 float4x4::identity = float4x4(
624+
inline constexpr float4x4 float4x4::identity = float4x4(
625625
1.0f, 0.0f, 0.0f, 0.0f,
626626
0.0f, 1.0f, 0.0f, 0.0f,
627627
0.0f, 0.0f, 1.0f, 0.0f,
628628
0.0f, 0.0f, 0.0f, 1.0f);
629-
inline const float4x4 float4x4::zero = float4x4(0.0f);
630-
inline const float4x4 float4x4::one = float4x4(1.0f);
631-
inline const float4x4 float4x4::minusOne = float4x4(-1.0f);
629+
inline constexpr float4x4 float4x4::zero = float4x4(0.0f);
630+
inline constexpr float4x4 float4x4::one = float4x4(1.0f);
631+
inline constexpr float4x4 float4x4::minusOne = float4x4(-1.0f);
632632

633633
//**********************************************************************************************************************
634634
static constexpr float4x4 operator+(float n, const float4x4& m) noexcept

include/math/vector/float.hpp

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -146,21 +146,21 @@ struct [[nodiscard]] float2
146146
epsilon, inf, minusInf, nan, left, right, bottom, top;
147147
};
148148

149-
inline const float2 float2::zero = float2(0.0f);
150-
inline const float2 float2::one = float2(1.0f);
151-
inline const float2 float2::minusOne = float2(-1.0f);
152-
inline const float2 float2::min = float2(FLT_MIN);
153-
inline const float2 float2::minusMin = float2(-FLT_MIN);
154-
inline const float2 float2::max = float2(FLT_MAX);
155-
inline const float2 float2::minusMax = float2(-FLT_MAX);
156-
inline const float2 float2::epsilon = float2(FLT_EPSILON);
157-
inline const float2 float2::inf = float2(INFINITY);
158-
inline const float2 float2::minusInf = float2(-INFINITY);
159-
inline const float2 float2::nan = float2(NAN);
160-
inline const float2 float2::left = float2(-1.0f, 0.0f);
161-
inline const float2 float2::right = float2(1.0f, 0.0f);
162-
inline const float2 float2::bottom = float2(0.0f, -1.0f);
163-
inline const float2 float2::top = float2(0.0f, 1.0f);
149+
inline constexpr float2 float2::zero = float2(0.0f);
150+
inline constexpr float2 float2::one = float2(1.0f);
151+
inline constexpr float2 float2::minusOne = float2(-1.0f);
152+
inline constexpr float2 float2::min = float2(FLT_MIN);
153+
inline constexpr float2 float2::minusMin = float2(-FLT_MIN);
154+
inline constexpr float2 float2::max = float2(FLT_MAX);
155+
inline constexpr float2 float2::minusMax = float2(-FLT_MAX);
156+
inline constexpr float2 float2::epsilon = float2(FLT_EPSILON);
157+
inline constexpr float2 float2::inf = float2(INFINITY);
158+
inline constexpr float2 float2::minusInf = float2(-INFINITY);
159+
inline constexpr float2 float2::nan = float2(NAN);
160+
inline constexpr float2 float2::left = float2(-1.0f, 0.0f);
161+
inline constexpr float2 float2::right = float2(1.0f, 0.0f);
162+
inline constexpr float2 float2::bottom = float2(0.0f, -1.0f);
163+
inline constexpr float2 float2::top = float2(0.0f, 1.0f);
164164

165165
/***********************************************************************************************************************
166166
* @brief Floating point 3 component vector structure.
@@ -310,23 +310,23 @@ struct [[nodiscard]] float3
310310
epsilon, inf, minusInf, nan, left, right, bottom, top, back, front;
311311
};
312312

313-
inline const float3 float3::zero = float3(0.0f);
314-
inline const float3 float3::one = float3(1.0f);
315-
inline const float3 float3::minusOne = float3(-1.0f);
316-
inline const float3 float3::min = float3(FLT_MIN);
317-
inline const float3 float3::minusMin = float3(-FLT_MIN);
318-
inline const float3 float3::max = float3(FLT_MAX);
319-
inline const float3 float3::minusMax = float3(-FLT_MAX);
320-
inline const float3 float3::epsilon = float3(FLT_EPSILON);
321-
inline const float3 float3::inf = float3(INFINITY);
322-
inline const float3 float3::minusInf = float3(-INFINITY);
323-
inline const float3 float3::nan = float3(NAN);
324-
inline const float3 float3::left = float3(-1.0f, 0.0f, 0.0f);
325-
inline const float3 float3::right = float3(1.0f, 0.0f, 0.0f);
326-
inline const float3 float3::bottom = float3(0.0f, -1.0f, 0.0f);
327-
inline const float3 float3::top = float3(0.0f, 1.0f, 0.0f);
328-
inline const float3 float3::back = float3(0.0f, 0.0f, -1.0f);
329-
inline const float3 float3::front = float3(0.0f, 0.0f, 1.0f);
313+
inline constexpr float3 float3::zero = float3(0.0f);
314+
inline constexpr float3 float3::one = float3(1.0f);
315+
inline constexpr float3 float3::minusOne = float3(-1.0f);
316+
inline constexpr float3 float3::min = float3(FLT_MIN);
317+
inline constexpr float3 float3::minusMin = float3(-FLT_MIN);
318+
inline constexpr float3 float3::max = float3(FLT_MAX);
319+
inline constexpr float3 float3::minusMax = float3(-FLT_MAX);
320+
inline constexpr float3 float3::epsilon = float3(FLT_EPSILON);
321+
inline constexpr float3 float3::inf = float3(INFINITY);
322+
inline constexpr float3 float3::minusInf = float3(-INFINITY);
323+
inline constexpr float3 float3::nan = float3(NAN);
324+
inline constexpr float3 float3::left = float3(-1.0f, 0.0f, 0.0f);
325+
inline constexpr float3 float3::right = float3(1.0f, 0.0f, 0.0f);
326+
inline constexpr float3 float3::bottom = float3(0.0f, -1.0f, 0.0f);
327+
inline constexpr float3 float3::top = float3(0.0f, 1.0f, 0.0f);
328+
inline constexpr float3 float3::back = float3(0.0f, 0.0f, -1.0f);
329+
inline constexpr float3 float3::front = float3(0.0f, 0.0f, 1.0f);
330330

331331
/***********************************************************************************************************************
332332
* @brief Floating point 4 component vector structure.
@@ -526,17 +526,17 @@ struct [[nodiscard]] float4
526526
static const float4 zero, one, minusOne, min, minusMin, max, minusMax, epsilon, inf, minusInf, nan;
527527
};
528528

529-
inline const float4 float4::zero = float4(0.0f);
530-
inline const float4 float4::one = float4(1.0f);
531-
inline const float4 float4::minusOne = float4(-1.0f);
532-
inline const float4 float4::min = float4(FLT_MIN);
533-
inline const float4 float4::minusMin = float4(-FLT_MIN);
534-
inline const float4 float4::max = float4(FLT_MAX);
535-
inline const float4 float4::minusMax = float4(-FLT_MAX);
536-
inline const float4 float4::epsilon = float4(FLT_EPSILON);
537-
inline const float4 float4::inf = float4(INFINITY);
538-
inline const float4 float4::minusInf = float4(-INFINITY);
539-
inline const float4 float4::nan = float4(NAN);
529+
inline constexpr float4 float4::zero = float4(0.0f);
530+
inline constexpr float4 float4::one = float4(1.0f);
531+
inline constexpr float4 float4::minusOne = float4(-1.0f);
532+
inline constexpr float4 float4::min = float4(FLT_MIN);
533+
inline constexpr float4 float4::minusMin = float4(-FLT_MIN);
534+
inline constexpr float4 float4::max = float4(FLT_MAX);
535+
inline constexpr float4 float4::minusMax = float4(-FLT_MAX);
536+
inline constexpr float4 float4::epsilon = float4(FLT_EPSILON);
537+
inline constexpr float4 float4::inf = float4(INFINITY);
538+
inline constexpr float4 float4::minusInf = float4(-INFINITY);
539+
inline constexpr float4 float4::nan = float4(NAN);
540540

541541
//**********************************************************************************************************************
542542
static constexpr float2 operator+(float n, float2 v) noexcept { return float2(n) + v; }

0 commit comments

Comments
 (0)