ref: 4dc7878a215151dfd021b4444c7850fa8412387c
parent: 64511aba1433ac89569f57542bde44e02c1a45e5
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Jul 16 14:49:35 EDT 2024
cut off quadratic curves better; don't call fabs
--- a/rast.c
+++ b/rast.c
@@ -58,7 +58,8 @@
#define QBZR_PIX_SCALE 4.0
#define MAXCOMPONENTS 16
-#define ε 1.0e-6
+#define ε 1.0e-9
+#define ₀(v) ((v) > -ε && (v) < ε)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
@@ -80,7 +81,6 @@
Sval p, q, d;
int n;
-#define ₀(x) (x > -ε && x < ε)
if(₀(a)){
if(₀(b))
return 0;
@@ -96,7 +96,6 @@
qs[0] = -p;
return qs[0] > 0 && qs[0] < 1;
}
-#undef ₀
if(d < 0.0)
return 0;
@@ -132,10 +131,10 @@
}
/* FIXME would it make things faster to do proper convex hull test here? */
- if(s.p0.x < 0 && s.p1.x < 0 && s.p2.x < 0 ||
- s.p0.x > 1 && s.p1.x > 1 && s.p2.x > 1 ||
- s.p0.y < 0 && s.p1.y < 0 && s.p2.y < 0 ||
- s.p0.y > 1 && s.p1.y > 1 && s.p2.y > 1)
+ if(s.p0.x <= 0 && s.p1.x <= 0 && s.p2.x <= 0 ||
+ s.p0.x >= 1 && s.p1.x >= 1 && s.p2.x >= 1 ||
+ s.p0.y <= 0 && s.p1.y <= 0 && s.p2.y <= 0 ||
+ s.p0.y >= 1 && s.p1.y >= 1 && s.p2.y >= 1)
return 0;
#define e(t,a) (s.p0.a*(1-t)*(1-t) + 2*s.p1.a*(1-t)*t + s.p2.a*t*t)
@@ -179,11 +178,11 @@
z.p0.y = e(a, y);
z.p2.y = e(b, y);
- if(fabs(z.p0.y-1) < ε && fabs(z.p2.y-1) < ε)
+ if(₀(z.p0.y) && ₀(z.p2.y))
continue;
z.p0.x = e(a, x);
z.p2.x = e(b, x);
- if(fabs(z.p0.x-1) < ε && fabs(z.p2.x-1) < ε)
+ if(₀(z.p0.x) && ₀(z.p2.x))
continue;
#undef e