Fix 3 bugs in filled arc drawing...

1. Certain small angles would fill the inverse angle
2. Certain angles would draw a spurios horizontal line
3. Integer rounding improvements (now also improved for arc drawing)
spinbox_widget
inmarket 2016-10-01 18:15:05 +10:00
parent a5f27d61c6
commit e3a0cff000
1 changed files with 73 additions and 69 deletions

View File

@ -1722,11 +1722,11 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c
sedge = NONFIXED(radius * ((sbit & 0x99) ? ffsin(start) : ffcos(start)) + FIXED0_5); sedge = NONFIXED(radius * ((sbit & 0x99) ? ffsin(start) : ffcos(start)) + FIXED0_5);
eedge = NONFIXED(radius * ((ebit & 0x99) ? ffsin(end) : ffcos(end)) + FIXED0_5); eedge = NONFIXED(radius * ((ebit & 0x99) ? ffsin(end) : ffcos(end)) + FIXED0_5);
#elif GFX_USE_GMISC && GMISC_NEED_FASTTRIG #elif GFX_USE_GMISC && GMISC_NEED_FASTTRIG
sedge = round(radius * ((sbit & 0x99) ? fsin(start) : fcos(start))); sedge = floor(radius * ((sbit & 0x99) ? fsin(start) : fcos(start)) + 0.5);
eedge = round(radius * ((ebit & 0x99) ? fsin(end) : fcos(end))); eedge = floor(radius * ((ebit & 0x99) ? fsin(end) : fcos(end)) + 0.5);
#else #else
sedge = round(radius * ((sbit & 0x99) ? sin(start*GFX_PI/180) : cos(start*GFX_PI/180))); sedge = floor(radius * ((sbit & 0x99) ? sin(start*GFX_PI/180) : cos(start*GFX_PI/180)) + 0.5);
eedge = round(radius * ((ebit & 0x99) ? sin(end*GFX_PI/180) : cos(end*GFX_PI/180))); eedge = floor(radius * ((ebit & 0x99) ? sin(end*GFX_PI/180) : cos(end*GFX_PI/180)) + 0.5);
#endif #endif
if (sbit & 0xB4) sedge = -sedge; if (sbit & 0xB4) sedge = -sedge;
if (ebit & 0xB4) eedge = -eedge; if (ebit & 0xB4) eedge = -eedge;
@ -1843,17 +1843,21 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c
MUTEX_ENTER(g); MUTEX_ENTER(g);
// Do the trig to get the formulas for the start and end lines. // We add a half pixel so that we are drawing from the centre of the pixel
// instead of the left edge of the pixel. This also fixes the implied floor()
// when converting back to a coord_t
sxa = exa = FIXED(x) + FIXED0_5; sxa = exa = FIXED(x) + FIXED0_5;
// Do the trig to get the formulas for the start and end lines.
#if GFX_USE_GMISC && GMISC_NEED_FIXEDTRIG #if GFX_USE_GMISC && GMISC_NEED_FIXEDTRIG
sxb = radius*ffcos(start); sy = -NONFIXED(radius*ffsin(start) + FIXED0_5); sxb = radius*ffcos(start); sy = NONFIXED(FIXED0_5 - radius*ffsin(start));
exb = radius*ffcos(end); ey = -NONFIXED(radius*ffsin(end) + FIXED0_5); exb = radius*ffcos(end); ey = NONFIXED(FIXED0_5 - radius*ffsin(end));
#elif GFX_USE_GMISC && GMISC_NEED_FASTTRIG #elif GFX_USE_GMISC && GMISC_NEED_FASTTRIG
sxb = FP2FIXED(radius*fcos(start)); sy = -round(radius*fsin(start)); sxb = FP2FIXED(radius*fcos(start)); sy = floor(0.5-radius*fsin(start));
exb = FP2FIXED(radius*fcos(end)); ey = -round(radius*fsin(end)); exb = FP2FIXED(radius*fcos(end)); ey = floor(0.5-radius*fsin(end));
#else #else
sxb = FP2FIXED(radius*cos(start*GFX_PI/180)); sy = -round(radius*sin(start*GFX_PI/180)); sxb = FP2FIXED(radius*cos(start*GFX_PI/180)); sy = floor(0.5-radius*sin(start*GFX_PI/180));
exb = FP2FIXED(radius*cos(end*GFX_PI/180)); ey = -round(radius*sin(end*GFX_PI/180)); exb = FP2FIXED(radius*cos(end*GFX_PI/180)); ey = floor(0.5-radius*sin(end*GFX_PI/180));
#endif #endif
sxd = sy ? sxb/sy : sxb; sxd = sy ? sxb/sy : sxb;
exd = ey ? exb/ey : exb; exd = ey ? exb/ey : exb;
@ -1864,7 +1868,7 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c
if (sy > 0) qtr |= 0x02; if (sy > 0) qtr |= 0x02;
if (exb > 0) qtr |= 0x04; // E1=0100(4), E2=0000(0), E3=1000(8), E4=1100(12) if (exb > 0) qtr |= 0x04; // E1=0100(4), E2=0000(0), E3=1000(8), E4=1100(12)
if (ey > 0) qtr |= 0x08; if (ey > 0) qtr |= 0x08;
if (sy > ey) qtr |= 0x10; // order of start and end lines if (sy > ey || (sy == ey && sxb > 0)) qtr |= 0x10; // order of start and end lines
// Calculate intermediates // Calculate intermediates
a = 1; a = 1;
@ -2318,7 +2322,7 @@ void gdispGBlitArea(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, c
} }
} while(a < b); } while(a < b);
if (a <= ey) { if (a <= ey) {
g->p.y = y+a; g->p.x = NONFIXED(sxa); g->p.x1 = x+b; hline_clip(g); // S2C g->p.y = y+a; g->p.x = NONFIXED(sxa); g->p.x1 = NONFIXED(exa); hline_clip(g); // S2E
} else if (a <= sy) { } else if (a <= sy) {
g->p.y = y+a; g->p.x = NONFIXED(sxa); g->p.x1 = x+b; hline_clip(g); // S2C g->p.y = y+a; g->p.x = NONFIXED(sxa); g->p.x1 = x+b; hline_clip(g); // S2C
} else if (!(qtr & 4)) { } else if (!(qtr & 4)) {