-
-
Notifications
You must be signed in to change notification settings - Fork 162
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
Fix aalines overlap #2912
Fix aalines overlap #2912
Conversation
Pixel was missing between steep and not-steep line, when line is inverted
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is asking for something that won't be fun, but I'd like to see some regression test(s) put in place that demonstrate this change, and will flag if the change gets broken by a future commit
- test_aalines__overlap and - test_aalines__steep_missing_pixel - Added missing pixel when first line in list is steep and second is not (earlier, it was working only when it is not first line in list)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One small nitpick (that applies to both tests), but otherwise this looks good to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This still looks good to me
In some cases when adding extra pixel between steep and non-steep aaline, one extra pixel is not enough, causing gaps to appear between aalines Instead both endpoint pixels are needed This allowed to merge extra pixel handling with endpoint handling
So I tried to understand how the algorithm works, but even after a lot of doliprane, I couldn't understand the algorithm because of lack of graphical explanations. I believe it would be better if @mzivic7 or anyone who understood the algorithm, make a video that explains step by step the algorithm for the sake of others mental health. Like that we can push this PR faster to its merge. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, LGTM 👍
Output looks a lot better (Once I zoomed in, my old eyes couldn't see shit at normal resolution) and the changes make sense to me to reduce the overlapping in the original algorithm.
As seen on the picture bellow, there is a problem with draw.aalines.
This is happening because draw.aalines require each aaline to be drawn 1px shorter (in some cases 2px - see bellow), so two connected draw_aaline are not overlapping.
What is changed and how it works:
draw_aaline has 2 endpoints that needs to be disabled for draw.aalines only:
First endpoint is disabled when it is first line when aalines is open.
And when
from_x
value is not decimal (if it is, then line is 2px shorter).Second endpoint is disabled when it is last line when aalines is open.
As a result of disabling first endpoint, now there is special case where 1px is missing between two lines, where one is steep and other line is not.
This is detected in draw.aalines.
And resolved in draw_aaline by drawing one px at place where end point should be.
At what end point will be drawn pixel: first point when line is not inverted, second point when line is inverted.
Here are some results (might need to zoom to see the difference better):
Top line is modified.
Middle line is original.
Bottom line is difference.
Code used to draw this:
Results were merged for comparison in gimp.