openframeworks / openframeworks/openFrameworks
ofPath adds an initial straight line segment when creating curves in COMMAND mode
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
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:

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):


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.)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in libs/openFrameworks/graphics/ofPath.cpp at addCommand(...) and the moveTo/addVertex logic linked in the issue. Reproduce the provided curveTo example in COMMAND mode, then verify the behavior of straight-line paths as well. Done means curve paths no longer gain an unintended initial straight segment while straight-line paths continue to work.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100