Skip to content

Commit b2bdf88

Browse files
committed
Fix adaptive AA vertical edge detection
The previous implementation incorrectly checked `dx == 0` to detect vertical edges, but dx is modified by Bresenham reduction (line 144: dx = dx % dy). This caused diagonal lines with integer slopes to incorrectly use the vertical optimization, resulting in thin diagonal strokes disappearing. Root cause identified by cubic-dev-ai review: - dx is reduced to Bresenham remainder, losing original slope info - Integer-slope diagonals (e.g., 45° lines where dx == dy) would have dx==0 after modulo reduction - These were incorrectly routed to _span_fill_vertical() - Thin diagonal strokes collapsed due to sub-pixel span width Fix: - Use aa_quality flag instead of dx for vertical edge detection - aa_quality is set from ORIGINAL dx value before Bresenham reduction - aa_quality==0 means truly vertical edge (original dx==0) - aa_quality==2 means needs full 4x4 AA Testing: - Build successful with no warnings - mado-perf shows diagonal lines using full 4x4 AA (correct) - Vertical lines still benefit from optimization
1 parent 29e40e5 commit b2bdf88

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/poly.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,10 +383,14 @@ static void _twin_edge_fill(twin_pixmap_t *pixmap,
383383
* Only apply to spans >= 16 pixels to avoid branch overhead.
384384
* Threshold: 16 pixels * 4 samples/pixel = 64 samples
385385
*
386-
* Check if both edges forming this span are vertical (dx=0).
386+
* Check aa_quality (not dx) to detect vertical edges.
387+
* By this point, dx has been reduced by Bresenham, so dx==0
388+
* incorrectly matches diagonal lines with integer slopes, causing
389+
* thin diagonal strokes to disappear. The aa_quality flag was set
390+
* using the ORIGINAL dx value before Bresenham reduction.
387391
*/
388392
twin_sfixed_t span_width = a->x - x0;
389-
if (edge_start && edge_start->dx == 0 && a->dx == 0 &&
393+
if (edge_start && edge_start->aa_quality == 0 && a->aa_quality == 0 &&
390394
span_width >= (16 << TWIN_POLY_FIXED_SHIFT)) {
391395
/* Both edges vertical and span is wide enough: use optimized
392396
* span fill */

0 commit comments

Comments
 (0)