Skip to content

Commit 9596a27

Browse files
committed
fix many clang-tidy warnings
1 parent 438f4c3 commit 9596a27

33 files changed

+121
-115
lines changed

examples/19-gridmap.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ namespace {
9696
, m_grid_map(gf::GridMap::make_orthogonal(MapSize, CellSize))
9797
{
9898
for (auto position : gf::position_range(MapSize)) {
99-
switch (Grid[position.y][position.x]) {
99+
switch (Grid[position.y][position.x]) { // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
100100
case ' ':
101101
m_grid_map.set_properties(position, gf::CellProperty::Walkable | gf::CellProperty::Transparent);
102102
break;
@@ -210,7 +210,7 @@ namespace {
210210
const auto& mouse_motion_event = event.from<gf::EventType::MouseMoved>();
211211
auto mouse_position = mouse_motion_event.position;
212212
auto mouse_location = position_to_world_location(mouse_position);
213-
gf::Vec2I position = m_grid_entity.grid().compute_position(mouse_location);
213+
const gf::Vec2I position = m_grid_entity.grid().compute_position(mouse_location);
214214

215215
if (position != m_state.light) {
216216
m_state.light = position;

include/gf2/core/Activities.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ namespace gf {
307307
template<typename Tuple, std::size_t... Indices>
308308
struct ActivityTupleGetters<Tuple, std::index_sequence<Indices...>> {
309309
using Getter = Activity& (*)(Tuple&);
310-
static inline constexpr Getter Table[std::tuple_size_v<Tuple>] = { &activity_tuple_get<Tuple, Indices>... };
310+
static constexpr Getter Table[std::tuple_size_v<Tuple>] = { &activity_tuple_get<Tuple, Indices>... };
311311
};
312312

313313
template<typename Tuple>

include/gf2/core/Array2D.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ namespace gf {
140140

141141
std::size_t linearize(Vec2I index) const
142142
{
143-
return static_cast<std::size_t>(index.x) + static_cast<std::size_t>(index.y) * static_cast<std::size_t>(m_size.x);
143+
return static_cast<std::size_t>(index.x) + (static_cast<std::size_t>(index.y) * static_cast<std::size_t>(m_size.x));
144144
}
145145

146146
Vec2I m_size;

include/gf2/core/BinaryHeap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ namespace gf {
156156

157157
static constexpr size_type left_child_index(size_type index)
158158
{
159-
return 2 * index + 1;
159+
return (2 * index) + 1;
160160
}
161161

162162
static constexpr size_type right_child_index(size_type index)
163163
{
164-
return 2 * index + 2;
164+
return (2 * index) + 2;
165165
}
166166

167167
bool leaf(size_type index) const

include/gf2/core/GridVisibility.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace gf {
9090

9191
int relative_slope(Vec2I point) const
9292
{
93-
return (far.y - near.y) * (far.x - point.x) - (far.y - point.y) * (far.x - near.x);
93+
return ((far.y - near.y) * (far.x - point.x)) - ((far.y - point.y) * (far.x - near.x));
9494
}
9595
};
9696

include/gf2/core/Mat3.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ namespace gf {
8888
const float sin = std::sin(angle);
8989
// clang-format off
9090
return {{
91-
{ cos,- sin, center.x * (1 - cos) + center.y * sin },
92-
{ sin, cos, center.y * (1 - cos) - center.x * sin },
91+
{ cos,- sin, (center.x * (1 - cos)) + (center.y * sin) },
92+
{ sin, cos, (center.y * (1 - cos)) - (center.x * sin) },
9393
{ 0.0f, 0.0f, 1.0f }
9494
}};
9595
// clang-format on

include/gf2/core/Math.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,15 @@ namespace gf {
5858
template<typename T>
5959
constexpr std::enable_if_t<std::is_arithmetic_v<T>, T> clamp(T val, T min, T max)
6060
{
61-
// clang-format off
62-
return val < min ? min : (max < val ? max : val);
63-
// clang-format on
61+
if (val < min) {
62+
return min;
63+
}
64+
65+
if (max < val) {
66+
return max;
67+
}
68+
69+
return val;
6470
}
6571

6672
} // namespace details
@@ -126,7 +132,7 @@ namespace gf {
126132
template<typename T, typename U>
127133
constexpr T lerp(T lhs, T rhs, U t)
128134
{
129-
return T((U(1) - t) * lhs + t * rhs);
135+
return T(((U(1) - t) * lhs) + (t * rhs));
130136
}
131137

132138
template<typename T>
@@ -168,13 +174,13 @@ namespace gf {
168174
template<typename T>
169175
constexpr std::enable_if_t<std::is_integral_v<T>, T> div_floor(T dividend, T divisor)
170176
{
171-
return dividend / divisor - (dividend % divisor != 0) * ((dividend < 0) ^ (divisor < 0));
177+
return (dividend / divisor) - ((dividend % divisor != 0) * ((dividend < 0) ^ (divisor < 0)));
172178
}
173179

174180
template<typename T>
175181
constexpr std::enable_if_t<std::is_integral_v<T>, T> div_ceil(T dividend, T divisor)
176182
{
177-
return dividend / divisor + (dividend % divisor != 0) * ((dividend > 0) ^ (divisor < 0));
183+
return (dividend / divisor) + ((dividend % divisor != 0) * ((dividend > 0) ^ (divisor < 0)));
178184
}
179185

180186
} // namespace gf

library/core/BinPack.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ namespace gf {
1717
namespace {
1818
int score_best_area(Vec2I size, RectI rectangle)
1919
{
20-
return rectangle.extent.w * rectangle.extent.h - size.w * size.h;
20+
return (rectangle.extent.w * rectangle.extent.h) - (size.w * size.h);
2121
}
2222

2323
int score_best_short_side(Vec2I size, RectI rectangle)

library/core/Bitmap.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ namespace gf {
123123

124124
std::ptrdiff_t Bitmap::offset_from_position(Vec2I position) const
125125
{
126-
return static_cast<std::ptrdiff_t>(position.x) + static_cast<std::ptrdiff_t>(position.y) * static_cast<std::ptrdiff_t>(m_size.w);
126+
return static_cast<std::ptrdiff_t>(position.x) + (static_cast<std::ptrdiff_t>(position.y) * static_cast<std::ptrdiff_t>(m_size.w));
127127
}
128128

129129
}

library/core/Color.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace gf {
2929

3030
if ((max - min) > std::numeric_limits<float>::epsilon()) {
3131
if (max == color.r) {
32-
hue = std::fmod(60.0f * (color.g - color.b) / (max - min) + 360.0f, 360.0f);
32+
hue = std::fmod((60.0f * (color.g - color.b) / (max - min)) + 360.0f, 360.0f);
3333
} else if (max == color.g) {
3434
hue = 60.0f * (color.b - color.r) / (max - min) + 120.0f;
3535
} else if (max == color.b) {
@@ -39,7 +39,7 @@ namespace gf {
3939
}
4040
}
4141

42-
const float sat = (max < std::numeric_limits<float>::epsilon()) ? 0.0f : (1.0f - min / max);
42+
const float sat = (max < std::numeric_limits<float>::epsilon()) ? 0.0f : (1.0f - (min / max));
4343
const float val = max;
4444

4545
return { hue, sat, val, color.a };
@@ -135,7 +135,7 @@ namespace gf {
135135

136136
float linear_to_srgb(float c)
137137
{
138-
return (c < 0.0031308f) ? 12.92f * c : 1.055f * std::pow(c, 1.f / 2.4f) - 0.055f;
138+
return (c < 0.0031308f) ? 12.92f * c : (1.055f * std::pow(c, 1.f / 2.4f)) - 0.055f;
139139
}
140140
}
141141

0 commit comments

Comments
 (0)