Use faster check for line whether it's inside drawing rect #4269
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.
This obviously does not consider slope that's outside,
But these cases will be clipping by CoreGraphics anyway.
Doing a full line collision test here is an overkill.
Issue Link 🔗
Fixes a performance degradation introduced here: #4100
It was a big chunk of code that was introduced to fix a subtle bug, but most of the fix was actually the code calling it - figuring out the first/last line coordinate for stepped lined.
Goals ⚽
Revert to almost-the-previous-implementation, keeping the actual fix in place.
Implementation Details 🚧
When testing simply that
lastCoordinate.x > left && firstCoordinate.x < right
, it's enough to ensure the line is horizontally somewhere in the content rect.The equivalent vertical check was inverted, causing rare issues.
But the main issue was actually with stepped lines, where a line was more than 2 coordinates, and only the first 2 were validated.
Testing Details 🔍
Zooming in manually in all scenarios until all coordinates are off screen - horizontally and vertically.