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

Cleanup #5233

Merged
merged 11 commits into from
Jun 7, 2021
Merged

Cleanup #5233

merged 11 commits into from
Jun 7, 2021

Conversation

yueh
Copy link
Member

@yueh yueh commented May 18, 2021

No description provided.

@yueh yueh added this to the 8.4.0-alpha - 1.16.5 milestone May 18, 2021
@yueh yueh marked this pull request as draft May 18, 2021 20:11
@yueh yueh marked this pull request as ready for review May 27, 2021 07:16
return (((((light >> 16) & 0xff) + ((dark >> 16) & 0xff)) / 2) << 16)
| (((((light >> 8) & 0xff) + ((dark >> 8) & 0xff)) / 2) << 8)
| ((((light) & 0xff) + ((dark) & 0xff)) / 2);
return ((light >> 16 & 0xff) + (dark >> 16 & 0xff)) / 2 << 16
Copy link
Member

Choose a reason for hiding this comment

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

i don't really see this as an improvement

Copy link
Member Author

Choose a reason for hiding this comment

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

5 parenthesis really doesn't help here either, I would even say there are too many to really keep track when reading it, so it causes more confusion than it helps
The pattern of value >> offset & MASK is in my opinion common enough to extract certain bits from a variable to not need additional ().

Copy link
Member

Choose a reason for hiding this comment

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

Yes it helps, because no, i do have to look up bit shifting operator precedence regularly.

Copy link
Member

Choose a reason for hiding this comment

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

Same for me, I have no clue about the operator precedence of bitwise operations.

Copy link
Member Author

Choose a reason for hiding this comment

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

Neither solution is ideal. Personally I understand the clean one better, even when taking into account that I have to lookup the operator precendence. Mostly because I only have to look it up once and then apply it everywhere. While keeping track of the shitton of parenthesis is actually more challenging for me and is pretty much guaranteed to move one randomly by accident without noticing it.

Otherwise there might be a helper somewhere to calculate the average of two rgb ints?

Copy link
Member

Choose a reason for hiding this comment

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

I guess int rAverage = (((light >> 16) & 0xff) + ((dark >> 16) & 0xff)) / 2; and so on would work better if we want to clean up that statement.

@yueh yueh merged commit b098fc3 into master Jun 7, 2021
@yueh yueh deleted the cleanup branch June 7, 2021 11:31
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants