Skip to content
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

Add custom clang-tidy check to improve use of point arithmetic operators #33161

Merged
merged 5 commits into from
Aug 12, 2019

Conversation

jbytheway
Copy link
Contributor

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 and tripoint 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 and point + 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 ) into point_north.

Previously the point operand had to be on the LHS.
Previously you could only do tripoint + point.
This is a clang-tidy check intended to automatically refactor arithmetic
using point and tripoint coordinates to be higher-level point
arithmetic.
These were highlighted by the new cata-use-point-arithmetic check.
@jbytheway jbytheway force-pushed the use_point_arithmetic_check branch from 6738501 to 8221c15 Compare August 12, 2019 14:40
@ZhilkinSerg ZhilkinSerg added [C++] Changes (can be) made in C++. Previously named `Code` Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style Code: Build Issues regarding different builds and build environments labels Aug 12, 2019
@ZhilkinSerg ZhilkinSerg merged commit 6c8f543 into CleverRaven:master Aug 12, 2019
@jbytheway jbytheway deleted the use_point_arithmetic_check branch August 12, 2019 18:04
misterprimus pushed a commit to misterprimus/Cataclysm-DDA that referenced this pull request Sep 21, 2019
…ors (CleverRaven#33161)

* Support int * point multiplication

Previously the point operand had to be on the LHS.

* Add point + tripoint operator

Previously you could only do tripoint + point.

* Initial version of UsePoingArithmetic check

This is a clang-tidy check intended to automatically refactor arithmetic
using point and tripoint coordinates to be higher-level point
arithmetic.

* Perform a refactoring pass

* Manually fix some coordinate transformations

These were highlighted by the new cata-use-point-arithmetic check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[C++] Changes (can be) made in C++. Previously named `Code` Code: Build Issues regarding different builds and build environments Code: Infrastructure / Style / Static Analysis Code internal infrastructure and style
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants