Skip to content

Example Usage on nanosvg home page run with example file drawing.svg creates excess path->pts due to 'z' cmd at end. My fix below. #279

@KariGordon

Description

@KariGordon

Example: Creates three extra points at end due to the 'z' cmd (which tries to draw a straight bezier back to start point).
for (NSVGshape* shape = image->shapes; shape != NULL; shape = shape->next) {
for (NSVGpath path = shape->paths; path != NULL; path = path->next) {
for (int i = 0; i < path->npts - 1; i += 3) {
float
p = &path->pts[i * 2];
drawCubicBez(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);

The FIX I use is:
static void nsvg__lineTo(NSVGparser* p, float x, float y)
{
float px,py, dx,dy;
if (p->npts > 0) {
const float tol = 1.0e-5;//magic number
px = p->pts[(p->npts-1)*2+0];
py = p->pts[(p->npts-1)*2+1];
dx = x - px;
dy = y - py;
if (fabs(dx) > tol || fabs(dy) > tol) {
nsvg__addPoint(p, px + dx / 3.0f, py + dy / 3.0f);
nsvg__addPoint(p, x - dx / 3.0f, y - dy / 3.0f);
nsvg__addPoint(p, x, y);
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions