Skip to content

Refactor RectI & RectD methods to simplify code and improve readability. #914

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

Merged
merged 1 commit into from
Sep 5, 2023

Conversation

acolwell
Copy link
Collaborator

@acolwell acolwell commented Sep 5, 2023

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?

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.

- 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.
@acolwell acolwell requested a review from devernay September 5, 2023 00:55
Copy link
Member

@devernay devernay left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up!
LGTM

@acolwell acolwell merged commit b134344 into NatronGitHub:RB-2.5 Sep 5, 2023
@acolwell acolwell deleted the refactor_recti_and_rectd branch September 5, 2023 15:07
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