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

Refactor clipIfOverlaps() so it does not have a return value. #947

Merged

Conversation

acolwell
Copy link
Collaborator

Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. Additionally, make sure you've done all of these things:

PR Description

What type of PR is this? (Check one of the boxes below)

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change which does not add functionality nor fixes a bug but improves Natron in some way)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • My change requires a change to the documentation
    • I have updated the documentation accordingly

What does this pull request do?

This change removes the return value for clipIfOverlaps() and updates all callers. This was done to address a comment made in #930 (comment)

  • Removed return value from RectI::clipIfOverlaps() and RectD::clipIfOverlaps()
  • Introduced clip() that updates a RectI or RectD with the intersection of itself and another rectangle.
  • Reworked several clipIfOverlaps() callers to use clip() or intersect() instead of clipIfOverlaps().

Have you tested your changes (if applicable)? If so, how?

Yes. I verified all the tests still pass on Windows and Linux (https://github.com/acolwell/Natron/actions/runs/7944427820). I also did some testing on Windows using an installer build including these changes (https://github.com/acolwell/Natron/actions/runs/7944419132). I did not notice any issues associated with these changes.

Futher details of this pull request

The vast majority of the changes do not change the existing behavior. The only case where there is technically a behavior change is in Image::halveRoIForDepth() where a clipIfOverlaps() is changed to an intersect(). I've determined that this is safe though because it appears that the roi is verified to be contained within the bounds of the image by the downscaleMipmap() call that eventually invokes halveRoIForDepth(). This guarantees that roi and srcBounds, in halveRoIForDepth(), should always overlap which means clipIfOverlaps() is equivalent to an intersect(). This was not immediately obvious when looking at the code, so I added assert(bounds_.contains(roi)) calls to the function levels between downscaleMipmap() and halveRoIForDepth() to help make it clear this precondition is expected to be maintained at each of these levels.

I suspect many/all of the remaining clipIfOverlap() calls that remain can likely be replaced with clip() or intersect(), but I have not sufficiently proved the safety of those transformations to myself. What I have in this PR I believe are perfectly safe and fulfill my previous commitment to remove the clipIfOverlaps() return value. I'll look into replacing the other calls to clipIfOverlap() as time permits and I have figured out how to prove they are safe.

This change removes the return value for clipIfOverlaps() and
updates all callers. This was done to address a comment made in
NatronGitHub#930 (comment)

- Removed return value from RectI::clipIfOverlaps() and RectD::clipIfOverlaps()

- Introduced clip() that updates a RectI or RectD with the intersection of
  itself and another rectangle.

- Reworked several clipIfOverlaps() callers to use clip() or intersect()
  instead of clipIfOverlaps().
Engine/Lut.cpp Outdated Show resolved Hide resolved
@acolwell acolwell force-pushed the remove-clipifoverlaps-returnvalue branch from 79a8fec to 7b0404e Compare February 20, 2024 18:50
@acolwell acolwell merged commit 95fd6d5 into NatronGitHub:RB-2.5 Feb 20, 2024
3 checks passed
@acolwell acolwell deleted the remove-clipifoverlaps-returnvalue branch February 20, 2024 21:40
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