Skip to content

How to get curved paths from NSVGpath #270

@Sum80

Description

@Sum80

when iterating over NSVGpath and reading path->pts, I only get linear points approximating the curves. How can I access the actual Bezier curves or get curved path data instead of just linearized points?"

// Iterate over shapes
for (NSVGshape* shape = image->shapes; shape; shape = shape->next) {
    // Separate tessellator for each shape to avoid connecting them
    TESStesselator* tessellator = tessNewTess(nullptr);
    if (!tessellator) {
        qWarning() << "Failed to create tessellator";
        return;
    }

    std::vector <std::vector<float>> tempVector;

    // Iterate over paths in the shape
    for (NSVGpath* path = shape->paths; path; path = path->next) {
        std::vector<float> vecPoints;
        for (int i = 0; i < path->npts; ++i) {
            // Push x and y coordinates into outlinePoints
            vecPoints.push_back(path->pts[i * 2]); // x-coordinate
            vecPoints.push_back(path->pts[i * 2 + 1]); // y-coordinate
            vecPoints.push_back(0.0);
  
        }
        
        tempVector.push_back(vecPoints);
        tessellatePath(tessellator, path);
    }

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