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 PHP bug #64641: imagefilledpolygon doesn't draw horizontal line #236
Conversation
for autotools, i think you want to:
|
Thanks, Mike. I've committed the respective changes, but please don't merge this PR yet – I'm hoping to actually fix the bug ASAP. |
A quick note :) Polygon drawing uses scanot lines algorithm. We could loop over the points and draw a single line if the points are aligned (vertically or horizontallly). Changing the main algorithm for this special case is not necessary nor desired (add complexity). |
See https://www.cs.rit.edu/~icss571/filling/index.html For a detailed explanation |
Thanks, Pierre. I'll still have to digest the algorithm, but it seems I've found the culprit, namely the special case handling of horizontal edges. Obviously, that can't work for a 1-dimensional polygon (i.e. consisting of horizontal edges only), because the edge table ( So, yes, we need some special handling for 1-dimensional polygons as you've suggested. I'll work on a patch. |
Btw document it could do it as well :) |
abb7ae1
to
0d63302
Compare
I have committed the fix now, and removed the XFAIL provisions.
I've thought about that as well, but IMHO it seems to be an arbitrary restriction (Why can I draw a vertical filled polygon, but not a horizontal one? Why can I draw an unfilled horizontal polygon, but not a filled one?) Furthermore, during testing the patch against PHP I've noticed several other test failures. It turned out the gdImageFilledPolygon() is used in gdImageFilledArc(), so this is also affected by the fix. An example (expected, actual, diff): As one can see, the actual arc is more symmetric than the expected arc (we have a single pixel at the top and bottom, as well as at the left and right hand side). IMO a good reason to apply the fix. We would have to assess the effect of this BC break, though. Just seen that all Travis checks are failing; I'll have a look at this right away. |
Hm. I thought I rewrote this function using the same algorithm I use for ellipse, except for antialised operations. Have to check that. |
gdImageArc() just forwards to gdImageFilledArc(), and this is using gdImageFilledPolygon(). |
I don't understand, why the checks are failing. Apparently, that is caused by failing to fopen() the expected image, but I don't see why this can happen. Locally, the tests are running fine (after |
Hm doesn't it have to use the absolute path to the expected image? |
See https://github.com/libgd/libgd/blob/master/tests/gdimagerotate/bug00067.c for an example |
According to @vapier sprintf() shouldn't be used anymore for constructing gdAssertImageEqualsToFile() paths. And according to the code relative paths are looked up in tests/. |
yes, you shouldn't attempt to construct your own paths anymore. the gdtest helpers should cover all your needs. this deals with all the edge cases with build/test envs. that said, the issue here is that you need to add all new images to |
As reported in <https://bugs.php.net/64641> 1-dimensional horizontal filled polygons are not drawn at all. That is caused by the scanline algorithm used for drawing filled polygons which skips the drawing of horizontal edges, because that is normally not necessary. If, however, the polygon consists of horizontal edges only, that obviously doesn't work, so we add a special case handling.
0d63302
to
f9f10fa
Compare
Thanks! I could have noticed that myself, though… I've pushed the fix. If the Travis checks succeed, I'll merge later (and also commit the fix to PHP 5.6+). |
As reported in https://bugs.php.net/64641 1-dimensional horizontal
filled polygons are not drawn at all.
This commit does not yet fix the bug, but rather adds a failing test case
to show the behavior. This test should be marked as XFAIL, but I don't
know how to do that yet.
The patch suggested in the PHP bug report was used to create
php_bug_64641.png which is the expected image, but this patch would break
tests/imagefilledpolygon/gdimagefilledpolygon1. From a quick glance at the
resulting image diff, it seems the patch is plain wrong.