Skip to content

Commit 1392129

Browse files
committed
clang-tidy:
- fix many errors
1 parent ec64b9f commit 1392129

File tree

5 files changed

+82
-67
lines changed

5 files changed

+82
-67
lines changed

.clang-tidy

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ CheckOptions:
153153

154154
## special things, that have special values
155155
- key: readability-identifier-length.IgnoredVariableNames
156-
value: "(os)" # ostream
156+
value: ""
157157
- key: readability-identifier-length.IgnoredParameterNames
158-
value: "^[n]$"
158+
value: "^(os)$" ## std::ostream
159+
- key: readability-identifier-length.IgnoredExceptionVariableNames
160+
value: ""
159161
- key: readability-identifier-length.MinimumLoopCounterNameLength
160162
value: 1
161163
- key: readability-identifier-length.MinimumExceptionNameLength

src/game/game.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void Game::render(const ServiceProvider& service_provider) const {
6262
}
6363

6464
[[nodiscard]] helper::BoolWrapper<std::pair<ui::EventHandleType, ui::Widget*>>
65-
Game::handle_event(const std::shared_ptr<input::InputManager>&, const SDL_Event&) {
65+
Game::handle_event(const std::shared_ptr<input::InputManager>& /*input_manager*/, const SDL_Event& /*event*/) {
6666
return false;
6767
}
6868

src/game/grid.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void Grid::render(const ServiceProvider& service_provider) const {
4242
}
4343

4444
[[nodiscard]] helper::BoolWrapper<std::pair<ui::EventHandleType, ui::Widget*>>
45-
Grid::handle_event(const std::shared_ptr<input::InputManager>&, const SDL_Event&) {
45+
Grid::handle_event(const std::shared_ptr<input::InputManager>& /*input_manager*/, const SDL_Event& /*event*/) {
4646
return false;
4747
}
4848

src/helper/color.hpp

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,16 @@ struct HSVColor {
2525
u8 a;
2626

2727

28-
constexpr HSVColor(double h, double s, double v, u8 a) // NOLINT(bugprone-easily-swappable-parameters)
29-
: h{ h },
30-
s{ s },
31-
v{ v },
32-
a{ a } {
28+
constexpr HSVColor(
29+
double hue, // NOLINT(bugprone-easily-swappable-parameters)
30+
double saturation,
31+
double value,
32+
u8 alpha
33+
)
34+
: h{ hue },
35+
s{ saturation },
36+
v{ value },
37+
a{ alpha } {
3338

3439
if (utils::is_constant_evaluated()) {
3540

@@ -52,7 +57,7 @@ struct HSVColor {
5257
}
5358
}
5459

55-
constexpr HSVColor(double h, double s, double v) : HSVColor{ h, s, v, 0xFF } { }
60+
constexpr HSVColor(double hue, double saturation, double value) : HSVColor{ hue, saturation, value, 0xFF } { }
5661

5762
constexpr HSVColor() : HSVColor{ 0.0, 0.0, 0.0, 0 } { }
5863

@@ -69,7 +74,7 @@ struct HSVColor {
6974
std::ostream& operator<<(std::ostream& os) const;
7075
};
7176

72-
namespace {
77+
namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
7378
//TODO(Totto): if everything (also libc++ ) supports c++23 , the std functions are constexpr, so we can use them
7479
template<typename T>
7580
constexpr T fmod_constexpr(T value, T divisor) {
@@ -120,15 +125,15 @@ struct Color {
120125
u8 a;
121126

122127

123-
constexpr Color(u8 r, u8 g, u8 b, u8 a) // NOLINT(bugprone-easily-swappable-parameters)
124-
: r{ r },
125-
g{ g },
126-
b{ b },
127-
a{ a } { }
128+
constexpr Color(u8 red, u8 green, u8 blue, u8 alpha) // NOLINT(bugprone-easily-swappable-parameters)
129+
: r{ red },
130+
g{ green },
131+
b{ blue },
132+
a{ alpha } { }
128133

129134
constexpr Color() : Color{ 0, 0, 0, 0 } { }
130135

131-
constexpr Color(u8 r, u8 g, u8 b) : Color{ r, g, b, 0xFF } { }
136+
constexpr Color(u8 red, u8 green, u8 blue) : Color{ red, green, blue, 0xFF } { }
132137

133138
[[nodiscard]] static helper::expected<Color, std::string> from_string(const std::string& value);
134139

@@ -139,30 +144,31 @@ struct Color {
139144

140145
[[nodiscard]] HSVColor to_hsv_color() const;
141146

142-
constexpr Color(const HSVColor& color) {
147+
explicit constexpr Color(const HSVColor& color) {
143148

144149
using FloatType = double; //for more precision use "long double" here
145150

146151
// taken from https://scratch.mit.edu/discuss/topic/694772/
147152

148-
const auto h = static_cast<FloatType>(color.h);
149-
const auto s = static_cast<FloatType>(color.s);
150-
const auto v = static_cast<FloatType>(color.v);
153+
auto hue = static_cast<FloatType>(color.h);
154+
const auto saturation = static_cast<FloatType>(color.s);
155+
const auto value = static_cast<FloatType>(color.v);
156+
157+
const FloatType chroma = value * saturation;
151158

152-
const FloatType chroma = v * s;
153159

154-
FloatType hue = h;
155160
if (hue >= static_cast<FloatType>(360.0)) {
156161
hue = static_cast<FloatType>(0.0);
157162
}
158163

159164

160-
const FloatType x = chroma
161-
* (static_cast<FloatType>(1.0)
162-
- fabs_constexpr(
163-
fmod_constexpr(hue / static_cast<FloatType>(60.0), static_cast<FloatType>(2.0))
164-
- static_cast<FloatType>(1.0)
165-
));
165+
const FloatType x_offset =
166+
chroma
167+
* (static_cast<FloatType>(1.0)
168+
- fabs_constexpr(
169+
fmod_constexpr(hue / static_cast<FloatType>(60.0), static_cast<FloatType>(2.0))
170+
- static_cast<FloatType>(1.0)
171+
));
166172

167173
const u64 index = static_cast<u64>(hue / static_cast<FloatType>(60.0));
168174

@@ -173,44 +179,44 @@ struct Color {
173179
switch (index) {
174180
case 0:
175181
d_r = chroma;
176-
d_g = x;
182+
d_g = x_offset;
177183
d_b = static_cast<FloatType>(0.0);
178184
break;
179185
case 1:
180-
d_r = x;
186+
d_r = x_offset;
181187
d_g = chroma;
182188
d_b = static_cast<FloatType>(0.0);
183189
break;
184190
case 2:
185191
d_r = static_cast<FloatType>(0.0);
186192
d_g = chroma;
187-
d_b = x;
193+
d_b = x_offset;
188194
break;
189195
case 3:
190196
d_r = static_cast<FloatType>(0.0);
191-
d_g = x;
197+
d_g = x_offset;
192198
d_b = chroma;
193199
break;
194200
case 4:
195-
d_r = x;
201+
d_r = x_offset;
196202
d_g = static_cast<FloatType>(0.0);
197203
d_b = chroma;
198204
break;
199205
case 5:
200206
d_r = chroma;
201207
d_g = static_cast<FloatType>(0.0);
202-
d_b = x;
208+
d_b = x_offset;
203209
break;
204210
default:
205211
utils::unreachable();
206212
}
207213

208214

209-
const FloatType m = v - chroma;
215+
const FloatType offset = value - chroma;
210216

211-
const auto finish_value = [m](FloatType value) -> u8 {
217+
const auto finish_value = [offset](FloatType value) -> u8 {
212218
const auto result =
213-
std::clamp<FloatType>(value + m, static_cast<FloatType>(0.0), static_cast<FloatType>(1.0))
219+
std::clamp<FloatType>(value + offset, static_cast<FloatType>(0.0), static_cast<FloatType>(1.0))
214220
* static_cast<FloatType>(0xFF);
215221

216222
return static_cast<u8>(round_constexpr(result));

src/helper/color_literals.hpp

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
#include <string>
99

1010

11-
namespace {
11+
namespace { //NOLINT(cert-dcl59-cpp,google-build-namespaces)
12+
1213
namespace const_constants {
1314

1415
// offsets in C strings for hex rgb and rgba
@@ -22,26 +23,26 @@ namespace {
2223
} // namespace const_constants
2324

2425
// decode a decimal number
25-
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_decimal_number(char n) {
26-
if (n >= '0' && n <= '9') {
27-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(n - '0'));
26+
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_decimal_number(char input) {
27+
if (input >= '0' && input <= '9') {
28+
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - '0'));
2829
}
2930

3031
return const_utils::expected<u8, std::string>::error_result("the input must be a valid decimal character");
3132
}
3233

3334
// decode a single_hex_number
34-
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_number(char n) {
35-
if (n >= '0' && n <= '9') {
36-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(n - '0'));
35+
[[nodiscard]] constexpr const_utils::expected<u8, std::string> single_hex_number(char input) {
36+
if (input >= '0' && input <= '9') {
37+
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - '0'));
3738
}
3839

39-
if (n >= 'A' && n <= 'F') {
40-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(n - 'A' + 10));
40+
if (input >= 'A' && input <= 'F') {
41+
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - 'A' + 10));
4142
}
4243

43-
if (n >= 'a' && n <= 'f') {
44-
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(n - 'a' + 10));
44+
if (input >= 'a' && input <= 'f') {
45+
return const_utils::expected<u8, std::string>::good_result(static_cast<u8>(input - 'a' + 10));
4546
}
4647

4748
return const_utils::expected<u8, std::string>::error_result("the input must be a valid hex character");
@@ -204,37 +205,37 @@ namespace {
204205

205206
if (size == const_constants::hex_rgb_size) {
206207

207-
const auto r = single_hex_color_value(input + const_constants::red_offset);
208-
PROPAGATE(r, ColorFromHexStringReturnType, std::string);
208+
const auto red = single_hex_color_value(input + const_constants::red_offset);
209+
PROPAGATE(red, ColorFromHexStringReturnType, std::string);
209210

210-
const auto g = single_hex_color_value(input + const_constants::green_offset);
211-
PROPAGATE(g, ColorFromHexStringReturnType, std::string);
211+
const auto green = single_hex_color_value(input + const_constants::green_offset);
212+
PROPAGATE(green, ColorFromHexStringReturnType, std::string);
212213

213-
const auto b = single_hex_color_value(input + const_constants::blue_offset);
214-
PROPAGATE(b, ColorFromHexStringReturnType, std::string);
214+
const auto blue = single_hex_color_value(input + const_constants::blue_offset);
215+
PROPAGATE(blue, ColorFromHexStringReturnType, std::string);
215216

216217
return const_utils::expected<ColorFromHexStringReturnType, std::string>::good_result({
217-
Color{ r.value(), g.value(), b.value() },
218+
Color{ red.value(), green.value(), blue.value() },
218219
false
219220
});
220221
}
221222

222223
if (size == const_constants::hex_rgba_size) {
223224

224-
const auto r = single_hex_color_value(input + const_constants::red_offset);
225-
PROPAGATE(r, ColorFromHexStringReturnType, std::string);
225+
const auto red = single_hex_color_value(input + const_constants::red_offset);
226+
PROPAGATE(red, ColorFromHexStringReturnType, std::string);
226227

227-
const auto g = single_hex_color_value(input + const_constants::green_offset);
228-
PROPAGATE(g, ColorFromHexStringReturnType, std::string);
228+
const auto green = single_hex_color_value(input + const_constants::green_offset);
229+
PROPAGATE(green, ColorFromHexStringReturnType, std::string);
229230

230-
const auto b = single_hex_color_value(input + const_constants::blue_offset);
231-
PROPAGATE(b, ColorFromHexStringReturnType, std::string);
231+
const auto blue = single_hex_color_value(input + const_constants::blue_offset);
232+
PROPAGATE(blue, ColorFromHexStringReturnType, std::string);
232233

233-
const auto a = single_hex_color_value(input + const_constants::alpha_offset);
234-
PROPAGATE(a, ColorFromHexStringReturnType, std::string);
234+
const auto alpha = single_hex_color_value(input + const_constants::alpha_offset);
235+
PROPAGATE(alpha, ColorFromHexStringReturnType, std::string);
235236

236237
return const_utils::expected<ColorFromHexStringReturnType, std::string>::good_result({
237-
Color{ r.value(), g.value(), b.value(), a.value() },
238+
Color{ red.value(), green.value(), blue.value(), alpha.value() },
238239
true
239240
});
240241
}
@@ -247,7 +248,10 @@ namespace {
247248
using ColorFromRGBStringReturnType = std::pair<Color, bool>;
248249

249250
[[nodiscard]] constexpr const_utils::expected<ColorFromRGBStringReturnType, std::string>
250-
get_color_from_rgb_string(const char* input, std::size_t) {
251+
get_color_from_rgb_string( //NOLINT(readability-function-cognitive-complexity)
252+
const char* input,
253+
std::size_t /*unused*/
254+
) {
251255

252256
if (input[0] == 'r' && input[1] == 'g' && input[2] == 'b') {
253257
if (input[3] == '(') {
@@ -415,7 +419,10 @@ namespace {
415419
using ColorFromHSVStringReturnType = std::pair<HSVColor, bool>;
416420

417421
[[nodiscard]] constexpr const_utils::expected<ColorFromHSVStringReturnType, std::string>
418-
get_color_from_hsv_string(const char* input, std::size_t) {
422+
get_color_from_hsv_string( //NOLINT(readability-function-cognitive-complexity)
423+
const char* input,
424+
std::size_t /*unused*/
425+
) {
419426

420427
if (input[0] == 'h' && input[1] == 's' && input[2] == 'v') {
421428
if (input[3] == '(') {

0 commit comments

Comments
 (0)