Skip to content

Commit

Permalink
fix protection against min/max macros
Browse files Browse the repository at this point in the history
The regular expression I used was:

```
((?!(?:^.*(\/\/|\/\*).*|^ *\* .*|^[^"]*"(?:"[^"]*"|[^"])*))^(?:.*[ ,\(]|))(\b(?:(?:[A-Za-z]+::)*)(?:max|min))\b *\(
```
  • Loading branch information
lrineau committed Jan 14, 2025
1 parent 1f70e59 commit d4e6ffd
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ double mean_min_angle(const Mesh& mesh)
const Triangle_3 tr = surface_mesh_face_to_triangle(f, mesh);
std::array<FT, 3> angles = triangle_angles(tr);

FT min_angle = std::min({angles[0], angles[1], angles[2]});
FT min_angle = (std::min)({angles[0], angles[1], angles[2]});

min_angle = min_angle * (180.0 / CGAL_PI);
mean_min_angle += min_angle;
Expand All @@ -93,7 +93,7 @@ double mean_max_angle(const Mesh& mesh)
const Triangle_3 tr = surface_mesh_face_to_triangle(f, mesh);
std::array<FT, 3> angles = triangle_angles(tr);

FT max_angle = std::max({angles[0], angles[1], angles[2]});
FT max_angle = (std::max)({angles[0], angles[1], angles[2]});

max_angle = max_angle * (180.0 / CGAL_PI);
mean_max_angle += max_angle;
Expand Down Expand Up @@ -151,8 +151,8 @@ double mean_edge_ratio(const Mesh& mesh,
FT a = std::sqrt(CGAL::squared_distance(tr[0], tr[1]));
FT b = std::sqrt(CGAL::squared_distance(tr[1], tr[2]));
FT c = std::sqrt(CGAL::squared_distance(tr[2], tr[0]));
FT min_edge = std::min({a, b, c});
FT max_edge = std::max({a, b, c});
FT min_edge = (std::min)({a, b, c});
FT max_edge = (std::max)({a, b, c});
FT edge_ratio = max_edge / min_edge;

mean_edge_ratio += edge_ratio;
Expand Down Expand Up @@ -181,7 +181,7 @@ double mean_aspect_ratio(const Mesh& mesh,
FT c = std::sqrt(CGAL::squared_distance(tr[2], tr[0]));
FT s = 0.5 * (a + b + c);
FT inscribed_radius = std::sqrt((s * (s - a) * (s - b) * (s - c)) / s);
FT max_edge = std::max({a, b, c});
FT max_edge = (std::max)({a, b, c});
FT aspect_ratio = max_edge / inscribed_radius;
aspect_ratio /= (2. * std::sqrt(3.)); // normalized
mean_aspect_ratio += aspect_ratio;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void GUI_country_pick_handler::mouse_press_event(QMouseEvent* e) {
auto sd = sqrt(d);
auto t1 = (-b - sd) / (2 * a);
auto t2 = (-b + sd) / (2 * a);
if (t1 > 0 && t2 > 0) ti = std::min(t1, t2);
if (t1 > 0 && t2 > 0) ti = (std::min)(t1, t2);
else if (t1 > 0) ti = t1;
else ti = t2;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void Main_widget::initializeGL() {
for (auto& [country_name, triangle_points] : country_triangles_map) {
auto country_triangles = std::make_unique<Triangles>(triangle_points);
auto color = QVector4D(rndm(), rndm(), rndm(), 1);
auto m = std::max(color.x(), std::max(color.y(), color.z()));
auto m = (std::max)(color.x(), (std::max)(color.y(), color.z()));
color /= m;
color *= m_dimming_factor;
color.setW(1);
Expand Down
2 changes: 1 addition & 1 deletion CGAL_Core/include/CGAL/CORE/poly/Curves.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ template <class NT>
int BiPoly<NT>::getXdegree(){
int deg=-1;
for(int i=0; i <=ydeg; i++)
deg = max(deg, coeffX[i].getTrueDegree());
deg = (max)(deg, coeffX[i].getTrueDegree());
return deg;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1565,7 +1565,7 @@ advanced_make_xy_monotone( const typename CK::Circular_arc_2 &a,
double ymax = (is_on_upper) ?
to_interval
( CircularFunctors::y_extremal_point<CK>(a.supporting_circle(),false).y() ).second :
CGAL::max(left_bb.ymax(),right_bb.ymax());
(CGAL::max)(left_bb.ymax(),right_bb.ymax());
*/
return Bbox_2(left_bb.xmin(),ymin,right_bb.xmax(),ymax);
}
Expand Down
2 changes: 1 addition & 1 deletion Distance_3/include/CGAL/Distance_3/Triangle_3_Triangle_3.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ squared_distance(const typename K::Triangle_3& tr1,
FT sqd_q2 = CGAL::squared_distance(vertex(tr2, 1), tr1);
FT sqd_r2 = CGAL::squared_distance(vertex(tr2, 2), tr1);
const FT m = std::min({sqd_p1, sqd_q1, sqd_r1, sqd_p2, sqd_q2, sqd_r2});
const FT m = (std::min)({sqd_p1, sqd_q1, sqd_r1, sqd_p2, sqd_q2, sqd_r2});
return m;
#endif
Expand Down
8 changes: 6 additions & 2 deletions Lab/demo/Lab/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,8 +2396,12 @@ void MainWindow::viewerShowObject()
}
if(item) {
const Scene::Bbox bbox = item->bbox();
CGAL::qglviewer::Vec min(static_cast<float>(bbox.xmin())+viewer->offset().x, static_cast<float>(bbox.ymin())+viewer->offset().y, static_cast<float>(bbox.zmin())+viewer->offset().z),
max(static_cast<float>(bbox.xmax())+viewer->offset().x, static_cast<float>(bbox.ymax())+viewer->offset().y, static_cast<float>(bbox.zmax())+viewer->offset().z);
CGAL::qglviewer::Vec min{static_cast<float>(bbox.xmin()) + viewer->offset().x,
static_cast<float>(bbox.ymin()) + viewer->offset().y,
static_cast<float>(bbox.zmin()) + viewer->offset().z};
CGAL::qglviewer::Vec max{static_cast<float>(bbox.xmax()) + viewer->offset().x,
static_cast<float>(bbox.ymax()) + viewer->offset().y,
static_cast<float>(bbox.zmax()) + viewer->offset().z};
viewer->setSceneBoundingBox(min, max);
viewerShow(static_cast<float>(min.x), static_cast<float>(min.y), static_cast<float>(min.z),
static_cast<float>(max.x), static_cast<float>(max.y), static_cast<float>(max.z));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void compute(SMesh* sMesh,
for (Vertex_descriptor v : vertices(*sMesh))
{
const PMP::Principal_curvatures_and_directions<Epic_kernel> pc = principal_curvatures_and_directions_map[v];
max_curvature_magnitude_on_mesh = std::max(max_curvature_magnitude_on_mesh, std::max(abs(pc.min_curvature), abs(pc.max_curvature)));
max_curvature_magnitude_on_mesh =
(std::max)(max_curvature_magnitude_on_mesh, (std::max)(abs(pc.min_curvature), abs(pc.max_curvature)));
}

for(Vertex_descriptor v : vertices(*sMesh))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ main( int argc, char* argv[])
*/

// evt. update max_entry:
max_entry = max( a[dim - 1] + b[dim - 1], max_entry);
max_entry = (max)( a[dim - 1] + b[dim - 1], max_entry);

// keep both vectors:
vectors.push_back( a);
Expand Down
4 changes: 2 additions & 2 deletions Number_types/include/CGAL/leda_bigfloat_interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ template <> class Real_embeddable_traits< leda_bigfloat_interval >
std::pair<double, double> lower_I(CGAL::to_interval(x.lower()));
std::pair<double, double> upper_I(CGAL::to_interval(x.upper()));
return std::pair< double, double >(
CGAL::min(lower_I.first , upper_I.first ),
CGAL::max(lower_I.second, upper_I.second));
(CGAL::min)(lower_I.first , upper_I.first ),
(CGAL::max)(lower_I.second, upper_I.second));
}
};
};
Expand Down
4 changes: 2 additions & 2 deletions STL_Extension/include/CGAL/Random_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ Random_allocator<T, Upstream_allocator>::allocate(size_type n, const void* hint)
#endif // CGAL_DEBUG_RANDOM_ALLOCATOR
return block->data + index;
}
size_type block_size = std::max(n * random_size, minimal_block_size);
size_type block_size = (std::max)(n * random_size, minimal_block_size);
ptr_->allocate_new_block(block_size);
return allocate(n, hint);
}
Expand Down Expand Up @@ -183,7 +183,7 @@ template <typename T, typename Upstream_allocator>
typename Random_allocator<T, Upstream_allocator>::size_type
Random_allocator<T, Upstream_allocator>::max_size() const noexcept
{
return std::numeric_limits<size_type>::max() / sizeof(T);
return (std::numeric_limits<size_type>::max)() / sizeof(T);
}

} // namespace CGAL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1002,7 +1002,7 @@ namespace nanoflann
if(node->child1 == NULL && node->child2 == NULL)
return 1;
else{
return std::max(depth(node->child1)+1,depth(node->child2)+1);
return (std::max)(depth(node->child1)+1,depth(node->child2)+1);
}
}

Expand Down Expand Up @@ -1130,8 +1130,8 @@ namespace nanoflann
node->sub.divhigh = right_bbox[cutfeat].low;

for (int i=0; i<(DIM>0 ? DIM : dim); ++i) {
bbox[i].low = std::min(left_bbox[i].low, right_bbox[i].low);
bbox[i].high = std::max(left_bbox[i].high, right_bbox[i].high);
bbox[i].low = (std::min)(left_bbox[i].low, right_bbox[i].low);
bbox[i].high = (std::max)(left_bbox[i].high, right_bbox[i].high);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ int main(int argc, char** argv)

if (!withE)
{ E=static_cast<unsigned int>(random.get_int
(10, std::max(std::size_t(11),
cm.number_of_darts()/10))); }
(10, (std::max)(std::size_t(11),
cm.number_of_darts()/10))); }

if (!withD)
{ D=static_cast<unsigned int>(random.get_int
(10, std::max(std::size_t(11),
cm.number_of_darts()/10))); }
(10, (std::max)(std::size_t(11),
cm.number_of_darts()/10))); }



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Polyline_constraint_hierarchy_2
struct Constraint_id
{
Vertex_list_ptr vl = nullptr;
size_type id = std::numeric_limits<size_type>::max();
size_type id = (std::numeric_limits<size_type>::max)();

Constraint_id(std::nullptr_t = nullptr) {}
Constraint_id(Vertex_list_ptr vl, size_type id) : vl(vl), id(id) {}
Expand All @@ -131,7 +131,7 @@ class Polyline_constraint_hierarchy_2

Constraint_id& operator=(std::nullptr_t) {
vl = nullptr;
id = std::numeric_limits<size_type>::max();
id = (std::numeric_limits<size_type>::max)();
return *this;
}
bool operator==(std::nullptr_t n) const { return vl == n; }
Expand Down

0 comments on commit d4e6ffd

Please sign in to comment.