ref: f60c543e823dcf95352fd0fe37a0a851a556be81
parent: 493d6287c76fdc7237804b08c4099ee82ab8c6cf
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Jul 31 00:41:08 EDT 2024
rasterizer: more precise area calculation Avoid division on every segment in the loop. Instead do it only once. (Un)surprisingly, the rendered glyph maps are different after the change.
--- a/rast.c
+++ b/rast.c
@@ -336,7 +336,7 @@
qbzr(SegQ *seg, int ns, int dw, int dh, int pitch, u8int *p)
{
int ju², j², w, h, i, j, ju, px, py, v;
- Sval rju², s₀, s, *c, *c₀x, *c₀y, *cs, zx, zy;
+ Sval rju², s₀, s, sl, sq, *c, *c₀x, *c₀y, *cs, zx, zy;
u64int *ma, *mb, all, nall;
ju² = closest²(dh);
@@ -352,20 +352,20 @@
}
/* calculate area */
- s₀ = 0;
+ sl = sq = 0;
for(i = 0; i < ns; i++){
#define det(a,b) (a.x*b.y - a.y*b.x)
-#define cL(s) det(s.p0, s.p2)/2.0
-#define cQ(s) (2*det(s.p0, s.p1) + 2*det(s.p1, s.p2) + det(s.p0, s.p2))/6.0
+#define cL(s) det(s.p0, s.p2)
+#define cQ(s) (2*det(s.p0, s.p1) + 2*det(s.p1, s.p2) + det(s.p0, s.p2))
if(seg[i].p1.x == seg[i].p2.x && seg[i].p1.y == seg[i].p2.y)
- s₀ -= cL(seg[i]);
+ sl -= cL(seg[i]);
else
- s₀ -= cQ(seg[i]);
+ sq -= cQ(seg[i]);
#undef det
#undef cL
#undef cQ
}
- s₀ *= QBZR_PIX_SCALE;
+ s₀ = (sl + sq/3)*QBZR_PIX_SCALE/2;
/* working space:
* quick is-segment-in-the-cell tests (two 64-bit nums per segment)