Changes this path to one in which all curved components are replaced by
sequences of line segments that approximate the curves.
The accuracy of the approximation is controlled by an internal number
(currently set to
0.5)
that can be changed by the optional
flatness
argument, which should be a number between
0.2
and
100.
Decreasing the
flatness
improves approximations, but it can be expensive.
Explicit path flattening is rarely needed, because built-ins that
manipulate paths automatically flatten them when necessary.
| |
| Example: |
The program,
import yoix.stdio.*;
Path p;
moveto(x, y) = printf(" moveto(%.1f, %.1f);\n", x, y);
lineto(x, y) = printf(" lineto(%.1f, %.1f);\n", x, y);
curveto(x1, y1, x2, y2, x3, y3) {
printf(" curveto(");
printf("%.1f, %.1f, ", x1, y1);
printf("%.1f, %.1f, ", x2, y2);
printf("%.1f, %.1f", x3, y3);
printf(");\n");
}
p.moveto(100, 100);
p.curveto(200, 200, 400, 300, 500, 300);
printf("Output before flattenpath:\n");
p.pathforall(moveto, lineto, NULL, curveto, NULL);
p.flattenpath(2);
printf("\nOutput after flattenpath:\n");
p.pathforall(moveto, lineto, NULL, curveto, NULL);
prints something like
Output before flattenpath:
moveto(100.0, 100.0);
curveto(200.0, 200.0, 400.0, 300.0, 500.0, 300.0);
Output after flattenpath:
moveto(100.0, 100.0);
lineto(141.8, 137.3);
lineto(190.6, 173.4);
lineto(244.1, 207.2);
lineto(300.0, 237.5);
lineto(355.9, 263.1);
lineto(409.4, 282.8);
lineto(458.2, 295.5);
lineto(500.0, 300.0);
on standard output.
| | |
| Return: |
Path
| | |
| See Also: |
arc,
arcn,
closepath,
currentpath,
currentpoint,
curveto,
Graphics,
lineto,
moveto,
newpath,
pathbbox,
pathforall,
quadto,
rcurveto,
rlineto,
rmoveto,
rquadto
|
|