Skip to content

Commit

Permalink
nanosvg: Fix drawing artefacts due to rounding errors: memononen/nano…
Browse files Browse the repository at this point in the history
  • Loading branch information
oehhar committed Oct 23, 2023
1 parent 22b0521 commit d8c34d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions generic/nanosvgrast.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,11 +886,17 @@ static NSVGactiveEdge* nsvg__addActive(NSVGrasterizer* r, NSVGedge* e, float sta
dxdy = (e->x1 - e->x0) / (e->y1 - e->y0);
/* STBTT_assert(e->y0 <= start_point); */
/* round dx down to avoid going too far */
/*
* HaO 2023-10-23
* pull request
* https://github.com/memononen/nanosvg/pull/247
* replaces floorf by roundf in the following 3 lines
*/
if (dxdy < 0)
z->dx = (int)(-floorf(NSVG__FIX * -dxdy));
z->dx = (int)(-roundf(NSVG__FIX * -dxdy));
else
z->dx = (int)floorf(NSVG__FIX * dxdy);
z->x = (int)floorf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
z->dx = (int)roundf(NSVG__FIX * dxdy);
z->x = (int)roundf(NSVG__FIX * (e->x0 + dxdy * (startPoint - e->y0)));
/* z->x -= off_x * FIX; */
z->ey = e->y1;
z->next = 0;
Expand Down

0 comments on commit d8c34d6

Please sign in to comment.