Skip to content

ofPath adds an initial straight line segment when creating curves in COMMAND mode #2928

@mikewesthad

Description

@mikewesthad

ofPath defaults to adding a straight line vertex when creating curves in COMMAND mode.

The addCommand(...) method of ofPath defaults to adding a moveTo command if the commands std::vector is empty. moveTo creates a new polyline in the path and adds a straight line vertex via addVertex(...). Here's a link to the relevant line of code.

This has caused problems for a few people (forum post) who are using ofPath's curveTo(...) method. Users could switch to creating paths in POLYLINE mode, but that undercuts some of the power of using paths.

For example, if you run this code:

ofPath path;
std::vector<ofVec2f> points;

void ofApp::setup(){
    points.push_back(ofVec2f(100, 50));
    points.push_back(ofVec2f(200, 250));
    points.push_back(ofVec2f(300, 50));
    points.push_back(ofVec2f(400, 250));
    points.push_back(ofVec2f(500, 50));
    points.push_back(ofVec2f(600, 250));
    points.push_back(ofVec2f(700, 50));
    for(int i=0; i<points.size(); i++) {
        path.curveTo(points[i].x, points[i].y, 0.0);
    }
    path.setFilled(false);
}

void ofApp::draw(){
    ofBackground(0);
    ofSetColor(255);
    path.draw();
}

You get:

image

I'm a bit confused as to why ofPath is set up to default to using moveTo to add a straight line vertex. If I comment out this line from ofPath, the above code works as expected (and it also works as expected for straight line paths):

image

image

Is removing that line of code an appropriate fix, or is there some more hidden reason why that addVertex(...) command exists?

(I'm running Windows 7 (64) with oF 0.8.0 in Code::Blocks 12.11, but this bug is not IDE/OS specific and not fixed in the master branch.)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions