Add custom clang-tidy check to improve use of point arithmetic operators #33161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
SUMMARY: Infrastructure "clang-tidy now checks for use of point arithmetic and suggest refactoring to make more use thereof"
Purpose of change
A lot of code is unnecessarily verbose because it performs operations on individual
point
andtripoint
coordinates rather than working with the objects as a whole.Finding and fixing this by hand would be very tiresome, so it would be good to automate the process.
Describe the solution
Implement a new custom
clang-tidy
check which looks for opportunities to use point arithmetic and refactors the code accordingly.To make all the refactored code compile required adding a couple more overloaded operators:
int * point
andpoint + tripoint
.This is by far the most complex clang-tidy check I've written, so there are surely corner cases it doesn't handle, but I've at least glanced through the changes it's made here and they seem reasonable.
Most of the below changes were automated, but when coordinate transforms are involved it merely flags an error; I fixed those manually. That required adding
omt_to_ms_copy
.Describe alternatives you've considered
Some of the changed code is not written in the most natural way (e.g. the order in which things are added up might be unintuitive. I could have worked to improve that, but haven't.
Additional context
In support of #32017.
Next step is a tool to change e.g.
point( 0, -1 )
intopoint_north
.