Skip to content

experimental: use clang-format for buffer and graph #1400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

barendgehrels
Copy link
Collaborator

@barendgehrels barendgehrels commented Apr 26, 2025

Applied on two folders only!

This is experimental and verifies how clang-format could be used for our code base,
using a style that is most close to what we (in general) use.

I used clang-format-15.

Other Boost libraries

clang-format is used by a few other boost libraries. I tried some of these configurations, but it was not satisfactory to my taste.
Here an indication (on a branch of somewhere last year), with sizes in bytes:

  414  ./graph/.clang-format
  706  ./multiprecision/.clang-format
 1721  ./outcome/.clang-format
 2561  ./histogram/.clang-format
 3111  ./yap/.clang-format
 4108  ./nowide/.clang-format
 5697  ./locale/.clang-format

  685 ./geometry/.clang-format

namespace boost { namespace geometry
namespace boost
{
namespace geometry
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find a rule which doesn't affect this style for namespace.
Maybe we can live with this change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the more detailled Brace rules as in #1400 (comment) , I can get namespace boost { namespace geometry {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, better for sure! Thanks! Applied!


using turn_vector_type = std::vector<buffer_turn_info_type>;

using piece_border_type = piece_border<Ring, point_type> ;
using piece_border_type = piece_border<Ring, point_type>;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It nicely catches these kind of small errors.

typename Turns,
typename Pieces,
typename DistanceStrategy,
typename UmbrellaStrategy
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also different than what we had. But it is (as far as I can see) the variant closest possible.

auto const source_turn_indices
= get_turn_indices_by_node_id(turns, clusters, source_node_id, allow_closed);
auto const target_turn_indices
= get_turn_indices_by_node_id(turns, clusters, target_node_id, allow_closed);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catches of wrong const placements, from me recently...

<< std::endl;
std::cout << "quadratic: " << source_node_id << " -> " << target_node_id << " sizes "
<< source_turn_indices.size() << " x " << target_turn_indices.size() << " = "
<< result.size() << std::endl;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal IMO but I don't think we can get this completely satisfactory

struct is_better_collinear_target {};
struct is_better_collinear_target
{
};
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somehow split (though I have AllowShortBlocksOnASingleLine)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the more detailled Brace rules as in #1400 (comment) , I can get

template <operation_type Operation>
struct is_better_collinear_target
{};

bool const better = is_better_collinear_for_union(
op0, op1, edges.front().toi, edges.back().toi);
bool const better
= is_better_collinear_for_union(op0, op1, edges.front().toi, edges.back().toi);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nicer IMO

return side == -1 ? geometry::strategy::buffer::join_convex
: side == 1 ? geometry::strategy::buffer::join_concave
: same_direction(p0, p1, p2) ? geometry::strategy::buffer::join_continue
: geometry::strategy::buffer::join_spike;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not too bad, actually better than I've ever seen from clang-format

first_p1,
first_p2,
last_p1,
last_p2);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really nice... but still acceptable probably

@barendgehrels barendgehrels self-assigned this Apr 26, 2025
@tinko92
Copy link
Collaborator

tinko92 commented Apr 27, 2025

This looks very convenient and I think having a style that can be programmatically enforced but is slightly different from before is better than having a style that is more difficult to ensure consistency for, I'm definitely in favour of this change.

The behaviour for namespaces and empty structs can maybe be made closer to the original by breaking up the Allman style into custom rules to partially address #1400 (comment) and #1400 (comment) like this:

-BreakBeforeBraces: Allman
+BreakBeforeBraces: Custom
+BraceWrapping:
+  AfterClass: true
+  AfterControlStatement: true
+  AfterEnum: true
+  AfterFunction: true
+  AfterNamespace: false
+  AfterStruct: true
+  AfterUnion: true
+  AfterExternBlock: true
+  BeforeCatch: true
+  BeforeElse: true
+  BeforeLambdaBody: true
+  SplitEmptyFunction: false
+  SplitEmptyRecord: false
+  SplitEmptyNamespace: false
+  IndentBraces: false

The following may also be of interest, if this is to be mass-applied, to somewhat preserve the ability to use git blame to understand why some particular line was changed, it requires logging the commit in a file called .git-blame-ignore-revs at root.
https://docs.github.com/en/repositories/working-with-files/using-files/viewing-and-understanding-files#ignore-commits-in-the-blame-view

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants