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

shift_index functions added into Grid class #278

Merged
merged 6 commits into from
Nov 15, 2024

Conversation

blenk13
Copy link
Contributor

@blenk13 blenk13 commented Nov 15, 2024

I've written three functions into Grid.

  1. A function that takes an index and horizontal step size (in terms of a number of pixels) as arguments, and outputs the COLUMN index of the new location after the step has been taken.
  2. A function that takes an index and vertical step size (in terms of a number of pixels) as arguments, and outputs the ROW index of the new location after the step has been taken.
  3. A function that takes a start index and a 2D step (as a morph::vec<int, 2>, in terms of numbers of pixels) as arguments and outputs the index after the move has been made.

The functions work with all GridOrders and all GridWraps.
Comprehensive unit tests are included and are passing.

I wondered whether it would be best if only (3) were a public function and have (1) and (2) as private ones? But I'll leave that up to you.

Copy link
Collaborator

@sebjameswml sebjameswml left a comment

Choose a reason for hiding this comment

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

This looks great. Agree about the 2 private functions. Minor changes requested to keep me super code-neat-happy.

morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated Show resolved Hide resolved
morph/Grid.h Outdated
* \param dx The horizontal displacement (in units of number of pixels).
* \return The column index of the moved pixel
*/
I col_after_x_shift (I ind, I dx)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you're probably right about making these two functions private, so let's do that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to do this without breaking the unit tests.
Is there some preferred way giving the test file permission to access private functions?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll have a play - I see that I can actually make changes to this PR myself. I'll sort it. And thanks for the other changes, it looks impeccable now :)

morph/Grid.h Outdated Show resolved Hide resolved
blenk13 and others added 4 commits November 15, 2024 18:44
If the function is to be unit tested, then it's simplest to keep it part of the public interface of the Grid class. 

If you want to unit test private parts of a class, you probably need to write a new class specifically for that purpose, which would provide access to the private members (using the friend keyword). But we're not going to do that. There's no great harm in making these two functions public, so I hereby reverse our previous decision.
@sebjameswml
Copy link
Collaborator

Right, sorted. I'll wait for the CI to finish and merge it after that

@sebjameswml sebjameswml merged commit eb79e4c into ABRG-Models:main Nov 15, 2024
6 checks passed
@blenk13 blenk13 deleted the AlexB_grid_shift_index branch November 17, 2024 16:20
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