|
|
@ -123,18 +123,6 @@ art_vpath_render_bez (ArtVpath **p_vpath, int *pn, int *pn_max,
|
|
|
|
double x3, double y3,
|
|
|
|
double x3, double y3,
|
|
|
|
double flatness)
|
|
|
|
double flatness)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
double x3_0, y3_0;
|
|
|
|
|
|
|
|
double z3_0_dot;
|
|
|
|
|
|
|
|
double z1_dot, z2_dot;
|
|
|
|
|
|
|
|
double z1_perp, z2_perp;
|
|
|
|
|
|
|
|
double max_perp_sq;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double x_m, y_m;
|
|
|
|
|
|
|
|
double xa1, ya1;
|
|
|
|
|
|
|
|
double xa2, ya2;
|
|
|
|
|
|
|
|
double xb1, yb1;
|
|
|
|
|
|
|
|
double xb2, yb2;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* It's possible to optimize this routine a fair amount.
|
|
|
|
/* It's possible to optimize this routine a fair amount.
|
|
|
|
|
|
|
|
|
|
|
|
First, once the _dot conditions are met, they will also be met in
|
|
|
|
First, once the _dot conditions are met, they will also be met in
|
|
|
@ -157,6 +145,14 @@ art_vpath_render_bez (ArtVpath **p_vpath, int *pn, int *pn_max,
|
|
|
|
just that I have this undying quest for more speed...
|
|
|
|
just that I have this undying quest for more speed...
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* don't subdivide inside this */
|
|
|
|
|
|
|
|
double x3_0, y3_0;
|
|
|
|
|
|
|
|
double z3_0_dot;
|
|
|
|
|
|
|
|
double z1_dot, z2_dot;
|
|
|
|
|
|
|
|
double z1_perp, z2_perp;
|
|
|
|
|
|
|
|
double max_perp_sq;
|
|
|
|
|
|
|
|
|
|
|
|
x3_0 = x3 - x0;
|
|
|
|
x3_0 = x3 - x0;
|
|
|
|
y3_0 = y3 - y0;
|
|
|
|
y3_0 = y3 - y0;
|
|
|
@ -164,20 +160,8 @@ art_vpath_render_bez (ArtVpath **p_vpath, int *pn, int *pn_max,
|
|
|
|
/* z3_0_dot is dist z0-z3 squared */
|
|
|
|
/* z3_0_dot is dist z0-z3 squared */
|
|
|
|
z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0;
|
|
|
|
z3_0_dot = x3_0 * x3_0 + y3_0 * y3_0;
|
|
|
|
|
|
|
|
|
|
|
|
if (z3_0_dot < 0.001)
|
|
|
|
if (z3_0_dot > 0.001)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
/* if start and end point are almost identical, the flatness tests
|
|
|
|
|
|
|
|
* don't work properly, so fall back on testing whether both of
|
|
|
|
|
|
|
|
* the other two control points are the same as the start point,
|
|
|
|
|
|
|
|
* too.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (hypot(x1 - x0, y1 - y0) < 0.001
|
|
|
|
|
|
|
|
&& hypot(x2 - x0, y2 - y0) < 0.001)
|
|
|
|
|
|
|
|
goto nosubdivide;
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
goto subdivide;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* we can avoid subdivision if:
|
|
|
|
/* we can avoid subdivision if:
|
|
|
|
|
|
|
|
|
|
|
|
z1 has distance no more than flatness from the z0-z3 line
|
|
|
|
z1 has distance no more than flatness from the z0-z3 line
|
|
|
@ -193,34 +177,47 @@ art_vpath_render_bez (ArtVpath **p_vpath, int *pn, int *pn_max,
|
|
|
|
|
|
|
|
|
|
|
|
z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0;
|
|
|
|
z1_perp = (y1 - y0) * x3_0 - (x1 - x0) * y3_0;
|
|
|
|
if (z1_perp * z1_perp > max_perp_sq)
|
|
|
|
if (z1_perp * z1_perp > max_perp_sq)
|
|
|
|
goto subdivide;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0;
|
|
|
|
z2_perp = (y3 - y2) * x3_0 - (x3 - x2) * y3_0;
|
|
|
|
if (z2_perp * z2_perp > max_perp_sq)
|
|
|
|
if (z2_perp * z2_perp > max_perp_sq)
|
|
|
|
goto subdivide;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0;
|
|
|
|
z1_dot = (x1 - x0) * x3_0 + (y1 - y0) * y3_0;
|
|
|
|
if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq)
|
|
|
|
if (z1_dot < 0 && z1_dot * z1_dot > max_perp_sq)
|
|
|
|
goto subdivide;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (z1_dot + z1_dot > z3_0_dot)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0;
|
|
|
|
z2_dot = (x3 - x2) * x3_0 + (y3 - y2) * y3_0;
|
|
|
|
if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq)
|
|
|
|
if (z2_dot < 0 && z2_dot * z2_dot > max_perp_sq)
|
|
|
|
goto subdivide;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
if (z1_dot + z1_dot > z3_0_dot)
|
|
|
|
|
|
|
|
goto subdivide;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (z2_dot + z2_dot > z3_0_dot)
|
|
|
|
if (z2_dot + z2_dot > z3_0_dot)
|
|
|
|
goto subdivide;
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
/* if start and end point are almost identical, the flatness tests
|
|
|
|
|
|
|
|
* don't work properly, so fall back on testing whether both of
|
|
|
|
|
|
|
|
* the other two control points are the same as the start point,
|
|
|
|
|
|
|
|
* too.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (hypot(x1 - x0, y1 - y0) > 0.001
|
|
|
|
|
|
|
|
|| hypot(x2 - x0, y2 - y0) > 0.001)
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nosubdivide:
|
|
|
|
|
|
|
|
/* don't subdivide */
|
|
|
|
|
|
|
|
art_vpath_add_point (p_vpath, pn, pn_max,
|
|
|
|
art_vpath_add_point (p_vpath, pn, pn_max,
|
|
|
|
ART_LINETO, x3, y3);
|
|
|
|
ART_LINETO, x3, y3);
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
} while (0);
|
|
|
|
subdivide:
|
|
|
|
double x_m, y_m;
|
|
|
|
|
|
|
|
double xa1, ya1;
|
|
|
|
|
|
|
|
double xa2, ya2;
|
|
|
|
|
|
|
|
double xb1, yb1;
|
|
|
|
|
|
|
|
double xb2, yb2;
|
|
|
|
|
|
|
|
|
|
|
|
xa1 = (x0 + x1) * 0.5;
|
|
|
|
xa1 = (x0 + x1) * 0.5;
|
|
|
|
ya1 = (y0 + y1) * 0.5;
|
|
|
|
ya1 = (y0 + y1) * 0.5;
|
|
|
|