Skip to content

Commit

Permalink
Merge branch 'clang_tidyv2' into 'master'
Browse files Browse the repository at this point in the history
[Clang-tidy] Apply a new round of clang-tidy fix

See merge request sfcgal/SFCGAL!296
  • Loading branch information
lbartoletti committed Dec 19, 2023
2 parents d60dc13 + bcce5ec commit 9730132
Show file tree
Hide file tree
Showing 175 changed files with 8,314 additions and 7,945 deletions.
41 changes: 41 additions & 0 deletions script/apply_clang_tidy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash

# This script generates a commit for each clang-tidy check using various clang utilities.
#
# By default, it uses Linux paths.
# You can execute it by defining the variables CLANG_TIDY_BIN, RUN_CLANG_TIDY_BIN,
# and APPLY_CLANG_TIDY_BIN when running the script:
#
# > env CLANG_TIDY_BIN=/usr/local/bin/clang-tidy15 \
# RUN_CLANG_TIDY_BIN=/usr/local/bin/run-clang-tidy15 \
# APPLY_CLANG_TIDY_BIN=/usr/local/bin/clang-apply-replacements15 \
# ./apply_clang_tidy.sh
#
# There isn't a clang-tidy CI in this project as of now.
# This script is useful for potential changes in .clang-tidy.
# We encourage developers to apply the fixes suggested by clang-tidy.


CLANG_TIDY_BIN=${CLANG_TIDY_BIN:-/usr/bin/clang-tidy}
RUN_CLANG_TIDY_BIN=${RUN_CLANG_TIDY_BIN:-/usr/bin/run-clang-tidy}
APPLY_CLANG_TIDY_BIN=${APPLY_CLANG_TIDY_BIN:-/usr/bin/clang-apply-replacements}

run_clang_tidy() {
checks=$(${CLANG_TIDY_BIN} --list-checks | awk '/ /{print $1}')

# Iterate over each check and run clang-tidy with fixes
while IFS= read -r check; do
${RUN_CLANG_TIDY_BIN} -p build -clang-tidy-binary=${CLANG_TIDY_BIN} -clang-apply-replacements-binary=${APPLY_CLANG_TIDY_BIN} -checks="-=*,$check" -fix

# Check if changes were made
if [ -n "$(git status -s)" ]; then
# Commit the changes with a relevant message
git add .
git commit -m "Fix clang-tidy check: $check"
else
echo "No changes for clang-tidy check: $check"
fi
done <<< "$checks"
}

run_clang_tidy
32 changes: 18 additions & 14 deletions src/Coordinate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@ Coordinate::~Coordinate() = default;
class CoordinateDimensionVisitor : public boost::static_visitor<int> {
public:
auto
operator()(const Coordinate::Empty &) const -> int
operator()(const Coordinate::Empty & /*unused*/) const -> int
{
return 0;
}
auto
operator()(const Kernel::Point_2 &) const -> int
operator()(const Kernel::Point_2 & /*unused*/) const -> int
{
return 2;
}
auto
operator()(const Kernel::Point_3 &) const -> int
operator()(const Kernel::Point_3 & /*unused*/) const -> int
{
return 3;
}
Expand Down Expand Up @@ -134,7 +134,7 @@ Coordinate::is3D() const -> bool
class GetXVisitor : public boost::static_visitor<Kernel::FT> {
public:
auto
operator()(const Coordinate::Empty &) const -> Kernel::FT
operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT
{
BOOST_THROW_EXCEPTION(
Exception("trying to get an empty coordinate x value"));
Expand Down Expand Up @@ -165,7 +165,7 @@ Coordinate::x() const -> Kernel::FT
class GetYVisitor : public boost::static_visitor<Kernel::FT> {
public:
auto
operator()(const Coordinate::Empty &) const -> Kernel::FT
operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT
{
BOOST_THROW_EXCEPTION(
Exception("trying to get an empty coordinate y value"));
Expand Down Expand Up @@ -196,14 +196,14 @@ Coordinate::y() const -> Kernel::FT
class GetZVisitor : public boost::static_visitor<Kernel::FT> {
public:
auto
operator()(const Coordinate::Empty &) const -> Kernel::FT
operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::FT
{
BOOST_THROW_EXCEPTION(
Exception("trying to get an empty coordinate z value"));
return 0;
}
auto
operator()(const Kernel::Point_2 &) const -> Kernel::FT
operator()(const Kernel::Point_2 & /*unused*/) const -> Kernel::FT
{
return 0;
}
Expand Down Expand Up @@ -231,7 +231,7 @@ class RoundVisitor : public boost::static_visitor<> {
RoundVisitor(const long &scaleFactor) : _scaleFactor(scaleFactor) {}

void
operator()(Coordinate::Empty &) const
operator()(Coordinate::Empty & /*unused*/) const
{
}
void
Expand All @@ -249,10 +249,11 @@ class RoundVisitor : public boost::static_visitor<> {
private:
long _scaleFactor;

auto
[[nodiscard]] auto
_roundFT(const Kernel::FT &v) const -> Kernel::FT
{
#ifdef CGAL_USE_GMPXX

#if defined(CGAL_USE_GMPXX)
::mpq_class q(SFCGAL::round(v.exact() * _scaleFactor), _scaleFactor);
q.canonicalize();
return Kernel::FT(q);
Expand All @@ -276,7 +277,7 @@ Coordinate::round(const long &scaleFactor) -> Coordinate &
class ToPoint2Visitor : public boost::static_visitor<Kernel::Point_2> {
public:
auto
operator()(const Coordinate::Empty &) const -> Kernel::Point_2
operator()(const Coordinate::Empty & /*unused*/) const -> Kernel::Point_2
{
return Kernel::Point_2(CGAL::ORIGIN);
}
Expand Down Expand Up @@ -353,22 +354,25 @@ Coordinate::operator<(const Coordinate &other) const -> bool
// comparison along x
if (x() < other.x()) {
return true;
} else if (other.x() < x()) {
}
if (other.x() < x()) {
return false;
}

// comparison along y
if (y() < other.y()) {
return true;
} else if (other.y() < y()) {
}
if (other.y() < y()) {
return false;
}

// comparison along z if possible
if (is3D()) {
if (z() < other.z()) {
return true;
} else if (other.z() < z()) {
}
if (other.z() < z()) {
return false;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Coordinate.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SFCGAL_API Coordinate {
* Empty Coordinate constructor
*/
Coordinate();

/**
* XY Constructor with exact coordinates
*/
Expand All @@ -36,6 +37,7 @@ class SFCGAL_API Coordinate {
* XYZ Constructor with exact coordinates
*/
Coordinate(const Kernel::FT &x, const Kernel::FT &y, const Kernel::FT &z);

/**
* XYZ constructor
* @warning x,y,z must not be not be NaN nor inf
Expand Down
24 changes: 12 additions & 12 deletions src/Envelope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,13 +143,13 @@ auto
Envelope::overlaps(const Envelope &a, const Envelope &b) -> bool
{
if (a.is3D()) {
CGAL::Bbox_3 abox = a.toBbox_3();
CGAL::Bbox_3 bbox = b.toBbox_3();
CGAL::Bbox_3 const abox = a.toBbox_3();
CGAL::Bbox_3 const bbox = b.toBbox_3();
return CGAL::do_overlap(abox, bbox);
}

CGAL::Bbox_2 abox = a.toBbox_2();
CGAL::Bbox_2 bbox = b.toBbox_2();
CGAL::Bbox_2 const abox = a.toBbox_2();
CGAL::Bbox_2 const bbox = b.toBbox_2();
return CGAL::do_overlap(abox, bbox);
}

Expand Down Expand Up @@ -195,15 +195,15 @@ Envelope::toShell() const -> std::unique_ptr<PolyhedralSurface>
return shell;
}

Point a(xMin(), yMin(), zMin());
Point b(xMax(), yMin(), zMin());
Point c(xMax(), yMax(), zMin());
Point d(xMin(), yMax(), zMin());
Point const a(xMin(), yMin(), zMin());
Point const b(xMax(), yMin(), zMin());
Point const c(xMax(), yMax(), zMin());
Point const d(xMin(), yMax(), zMin());

Point e(xMin(), yMin(), zMax());
Point f(xMax(), yMin(), zMax());
Point g(xMax(), yMax(), zMax());
Point h(xMin(), yMax(), zMax());
Point const e(xMin(), yMin(), zMax());
Point const f(xMax(), yMin(), zMax());
Point const g(xMax(), yMax(), zMax());
Point const h(xMin(), yMax(), zMax());

// bottom : a,d,c,b
{
Expand Down
7 changes: 3 additions & 4 deletions src/GeometryCollection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SFCGAL {
///
///
///
GeometryCollection::GeometryCollection() : _geometries() {}
GeometryCollection::GeometryCollection() = default;

///
///
Expand Down Expand Up @@ -90,9 +90,8 @@ GeometryCollection::coordinateDimension() const -> int
{
if (isEmpty()) {
return 0;
} else {
return _geometries.front().coordinateDimension();
}
return _geometries.front().coordinateDimension();
}

///
Expand Down Expand Up @@ -181,7 +180,7 @@ GeometryCollection::addGeometry(Geometry const &geometry)
///
///
auto
GeometryCollection::isAllowed(Geometry const &) -> bool
GeometryCollection::isAllowed(Geometry const & /*unused*/) -> bool
{
// GeometryCollection accepts all subtypes
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/Kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ namespace SFCGAL {
/**
* default Kernel
*/
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel;

using Kernel = CGAL::Exact_predicates_exact_constructions_kernel;

/**
* Quotient type
Expand Down
9 changes: 4 additions & 5 deletions src/LineString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ namespace SFCGAL {
///
///
///
LineString::LineString() : Geometry(), _points() {}
LineString::LineString() = default;

///
///
///
LineString::LineString(const std::vector<Point> &points) : Geometry(), _points()
LineString::LineString(const std::vector<Point> &points)
{
for (const auto &point : points) {
_points.push_back(point.clone());
Expand All @@ -26,7 +26,7 @@ LineString::LineString(const std::vector<Point> &points) : Geometry(), _points()
///
///
LineString::LineString(const Point &startPoint, const Point &endPoint)
: Geometry(), _points()

{
_points.push_back(startPoint.clone());
_points.push_back(endPoint.clone());
Expand Down Expand Up @@ -154,9 +154,8 @@ LineString::numSegments() const -> size_t
{
if (_points.empty()) {
return 0;
} else {
return _points.size() - 1;
}
return _points.size() - 1;
}

///
Expand Down
2 changes: 1 addition & 1 deletion src/MultiLineString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SFCGAL {
///
///
///
MultiLineString::MultiLineString() : GeometryCollection() {}
MultiLineString::MultiLineString() = default;

///
///
Expand Down
2 changes: 1 addition & 1 deletion src/MultiPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SFCGAL {
///
///
///
MultiPoint::MultiPoint() : GeometryCollection() {}
MultiPoint::MultiPoint() = default;

///
///
Expand Down
2 changes: 1 addition & 1 deletion src/MultiPolygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SFCGAL {
///
///
///
MultiPolygon::MultiPolygon() : GeometryCollection() {}
MultiPolygon::MultiPolygon() = default;

///
///
Expand Down
2 changes: 1 addition & 1 deletion src/MultiSolid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace SFCGAL {
///
///
///
MultiSolid::MultiSolid() : GeometryCollection() {}
MultiSolid::MultiSolid() = default;

///
///
Expand Down
16 changes: 7 additions & 9 deletions src/Polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ namespace SFCGAL {
///
///
///
Polygon::Polygon() : Surface() { _rings.push_back(new LineString()); }
Polygon::Polygon() { _rings.push_back(new LineString()); }

///
///
///
Polygon::Polygon(const std::vector<LineString> &rings) : Surface()
Polygon::Polygon(const std::vector<LineString> &rings)
{
if (rings.empty()) {
_rings.resize(1, new LineString());
Expand All @@ -32,23 +32,20 @@ Polygon::Polygon(const std::vector<LineString> &rings) : Surface()
///
///
///
Polygon::Polygon(const LineString &exteriorRing) : Surface()
Polygon::Polygon(const LineString &exteriorRing)
{
_rings.push_back(exteriorRing.clone());
}

///
///
///
Polygon::Polygon(LineString *exteriorRing) : Surface()
{
_rings.push_back(exteriorRing);
}
Polygon::Polygon(LineString *exteriorRing) { _rings.push_back(exteriorRing); }

///
///
///
Polygon::Polygon(const Triangle &triangle) : Surface()
Polygon::Polygon(const Triangle &triangle)
{
_rings.push_back(new LineString());

Expand Down Expand Up @@ -255,7 +252,8 @@ Polygon::toPolygon_with_holes_2(bool fixOrientation) const
holes.push_back(inner);
}

CGAL::Polygon_2<Kernel> outer = exteriorRing().toPolygon_2(fixOrientation);
CGAL::Polygon_2<Kernel> const outer =
exteriorRing().toPolygon_2(fixOrientation);
return CGAL::Polygon_with_holes_2<Kernel>(outer, holes.begin(), holes.end());
}

Expand Down
Loading

0 comments on commit 9730132

Please sign in to comment.