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
Aaline blend test #585
Aaline blend test #585
Conversation
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.
Hmm, casting to int is fine, I think. Source for that algorithm: https://web.archive.org/web/20160512070449/http://freespace.virgin.net/hugo.elias/graphics/x_wuline.htm
function trunc(x)
return integer part of x
end of function
Should be okay for negative numbers: (int)(-2.6) = -2. The only difference is that trunc() returns a float, as far as I can tell.
The reason I think it could have trouble with negative numbers is that trunc will cause the number to go to either the left, or right depending on if it is negative. So for diagonal negative lines, the results could be 1 pixel off what they were before? |
They seem to give the same results: #include <math.h>
#include <stdio.h>
#define TRUNC(d) (((d) >= 0.0) ? (floor(d)) : (ceil(d)))
int main() {
for (float i=0; i<3.0f; i += 0.4f) {
printf("%f %d %f %f\n", i, (int)i, trunc(i), TRUNC(i));
}
for (float i=0; i>-3.0f; i -= 0.4f) {
printf("%f %d %f %f\n", i, (int)i, trunc(i), TRUNC(i));
}
return 0;
}
I'd guess that the builtin trunc() is faster than floor() and ceil(), though Edit: I realized that the sign might matter, but does it? |
trunc is used in a few spots, and perhaps some(or all) of them would be fine with casting-to-int trunc?
|
draw.aaline(surface, pygame.Color(255, 255, 255), (2, 18), (18, 2), 1) | ||
|
||
# white should be blended with the background green. | ||
self.assertEqual(surface.get_at((10, 10)), (191, 255, 191, 255)) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Continuing on from the PR #582 so we can all change things in a branch on pygame repo if needed.
For the issue #575