Refactor RectI & RectD methods to simplify code and improve readability. #914
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.
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)
What does this pull request do?
The main goal of this change is to simplify the code and improve readability for some RectI and RectD usage. It does not
change any existing functionality, but it changes some key function signatures and adds a few helpers to make the code
simpler and a little easier to follow. The new signatures also make it easier to declare various variables const now, which
makes it a lot easier to reason about behavior in some of the large functions in the rendering path.
Here is a summary of the changes made:
Changed RectI::toCanonical(), RectI::toCanonical_noClip() and RectD::toPixelEnclosing() to return their value instead if using an out pointer param. This simplifies a lot of callers, avoids default construction in a lot of cases, and allows many variables to be marked const which makes it easier to ensure values don't change unexpectedly in large functions.
Added RectI::toNewMipMapLevel() helper function to reduce duplicate code and make the code a little more readable.
Added RectI::intersect() and RectD::intersect() methods that return the intersection or a null rect. Updated a few places where this form simplifies or makes the code more clear.
Added RectI::clipIfOverlaps() and RectD::clipIfOverlaps() helper functions to replace a common usage of the existing intersect() method. The intent is to make it a little more clear that the intersection only happens if there is an overlap and it avoids having to specify a variable name twice.
Renamed the original intersect() to intersectInternal() and made it private. The intersect() and clipIfOverlaps() changes above made it so there were no callers outside of RectI and RectD that needed this.
Removed some comment out code and a few variables/computations that weren't actually used for anything.
Added documentation for a few methods to make their behavior a little more clear.
Updated python wrapper type definitions to reflect the changes above. The intersect modifications could be removed because the new intersect() signature and semantics match the desired python signature and semantics.
Have you tested your changes (if applicable)? If so, how?
Yes. I've build this locally, verified the tests still run and Natron appears to work as expected. No change in behavior has been observed.