[rtextures] Review ImageDrawCircle() asymmetry - #6118
Conversation
ImageDrawCircle filled 2*radius pixels wide but 2*radius + 1 tall. Each horizontal span started at centerX - x with width 2*x, which covers centerX - x through centerX + x - 1, leaving the column at centerX + x unwritten. The result was one column short on the right, off-centre, and inconsistent with ImageDrawCircleLines, which is 2*radius + 1 in both directions. Widen the four spans by one pixel so the fill is (2r+1) x (2r+1), centred on (centerX, centerY) and aligned with ImageDrawCircleLines. Fixes raysan5#6117
1943a90 to
45bab0c
Compare
|
@Risu-swift please, could you provide comparison screenshots and also comparison with EDIT: Sorry, just saw the open issue. Still, how does it compare to |
ImageDrawCircle() asymmetry
Radius 5, left to right:
Measured on master (9f3cadf), centre (20,20) on a 40x40 target, alpha > 127 counted as covered:
It stays one pixel larger than One thing this PR does not change, visible in the figure above: the shapes differ as well as the sizes. The left panel is round, the right is a diamond with clipped corners. Changing that would mean replacing the span walk with a distance test, which is a much bigger behaviour change than this PR, so I have left it alone. Happy to open a separate issue if it is worth tracking. |
|
@Risu-swift thanks for the review. Meging this change for now but definitely behaviour should be the same as |

Fixes #6117
ImageDrawCirclefilled2*radiuspixels wide but2*radius + 1tall. Each horizontal span started atcenterX - xwith width2*x, which coverscenterX - xthroughcenterX + x - 1, so the column atcenterX + xwas never written. The fill came out one column short on the right, half a pixel off-centre, and out of line withImageDrawCircleLines, which is2*radius + 1in both directions.This widens the four spans by one pixel. The fill becomes
(2r+1) x (2r+1), centred on(centerX, centerY), and matchesImageDrawCircleLinesexactly.Verified on master (9f3cadf) with radii 1-6: before the change, 1, 5, 7, 9, 11 and 13 outline pixels fell outside the fill respectively. After it, zero for every radius.
Note this makes every filled circle one pixel wider than before, so existing output shifts. The alternative would be narrowing
ImageDrawCircleLinesinstead, but the outline is the one that is currently correct and centred.