Skip to content

Commit fcf1ddd

Browse files
committed
Use std::min/max instead of hand-rolling the check
clang-tidy check readability-use-std-min-max Apparently C++ compilers are good enough to optimize this properly https://stackoverflow.com/questions/15540250/in-c-is-it-better-to-cap-a-value-using-stdmin-or-an-if-branch
1 parent 734f2ad commit fcf1ddd

File tree

3 files changed

+12
-34
lines changed

3 files changed

+12
-34
lines changed

src/gen/gen-discrete-isolation.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,7 @@ FROM {src} WHERE {importance_column} > 0
113113
double const dx = coords[m].first - coords[n].first;
114114
double const dy = coords[m].second - coords[n].second;
115115
double const dist = dx * dx + dy * dy;
116-
if (dist < min) {
117-
min = dist;
118-
}
116+
min = std::min(dist, min);
119117
}
120118
data[n].di = std::sqrt(min);
121119
}

src/geom-box.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,17 @@
99

1010
#include "geom-box.hpp"
1111

12+
#include <algorithm>
1213
#include <variant>
1314

1415
namespace geom {
1516

1617
box_t &box_t::extend(point_t const &point) noexcept
1718
{
18-
if (point.x() < m_min_x) {
19-
m_min_x = point.x();
20-
}
21-
if (point.y() < m_min_y) {
22-
m_min_y = point.y();
23-
}
24-
if (point.x() > m_max_x) {
25-
m_max_x = point.x();
26-
}
27-
if (point.y() > m_max_y) {
28-
m_max_y = point.y();
29-
}
30-
19+
m_min_x = std::min(point.x(), m_min_x);
20+
m_min_y = std::min(point.y(), m_min_y);
21+
m_max_x = std::max(point.x(), m_max_x);
22+
m_max_y = std::max(point.y(), m_max_y);
3123
return *this;
3224
}
3325

@@ -40,18 +32,10 @@ void box_t::extend(point_list_t const &list) noexcept
4032

4133
void box_t::extend(box_t const &box) noexcept
4234
{
43-
if (box.min_x() < m_min_x) {
44-
m_min_x = box.min_x();
45-
}
46-
if (box.min_y() < m_min_y) {
47-
m_min_y = box.min_y();
48-
}
49-
if (box.max_x() > m_max_x) {
50-
m_max_x = box.max_x();
51-
}
52-
if (box.max_y() > m_max_y) {
53-
m_max_y = box.max_y();
54-
}
35+
m_min_x = std::min(box.min_x(), m_min_x);
36+
m_min_y = std::min(box.min_y(), m_min_y);
37+
m_max_x = std::max(box.max_x(), m_max_x);
38+
m_max_y = std::max(box.max_y(), m_max_y);
5539
}
5640

5741
box_t envelope(geom::nullgeom_t const & /*geom*/) { return box_t{}; }

src/geom-pole-of-inaccessibility.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ bool point_to_ring_distance_squared(point_t point, ring_t const &ring,
9090

9191
double const d =
9292
point_to_segment_distance_squared(point, a, b, stretch);
93-
if (d < *min_dist_squared) {
94-
*min_dist_squared = d;
95-
}
93+
*min_dist_squared = std::min(d, *min_dist_squared);
9694
}
9795

9896
return inside;
@@ -158,9 +156,7 @@ point_t pole_of_inaccessibility(const polygon_t &polygon, double precision,
158156

159157
double const min_precision =
160158
std::max(envelope.width(), envelope.height()) / 1000.0;
161-
if (min_precision > precision) {
162-
precision = min_precision;
163-
}
159+
precision = std::max(min_precision, precision);
164160

165161
box_t const stretched_envelope{envelope.min_x(), envelope.min_y() * stretch,
166162
envelope.max_x(),

0 commit comments

Comments
 (0)