ofPath getVertices, possible with an open path like a line?

I’ve already understood I have to use line width > 0 to be able to use getVertices command
but I can’t convert a simple line (two points) to ofPolyline. Is there some way to do that? if not, is this the intended usage of getVertices? only for closed polygons or 3 or more points?
Anyway I’ll try to make some rectangles and use the first two points for now.

Thank you

This code inside draw() works for me:

    ofPolyline line;
    line.addVertex(20, 20);
    line.addVertex(200, 50);

    for(auto & v : line.getVertices()) {
        std::cout << v << std::endl;

How does your code look like?

Not sure what you mean by getVertices since ofPath doens’t have such method but this also prints 2:

ofPath path;
path.moveTo({0., 0., 0.});
path.lineTo({0., 10., 0.});
ofPolyline line = path.getOutline()[0];
std::cout << line.getVertices().size() << std::endl;

I’m on 0.10 though in case this was an issue with 0.9 that’s been fixed meanwhile but i don’t think this wouldn’t have worked

Oops I was confused about the title. Since ofPath doesn’t have getVertices I thought it was ofPolyline.

Just for fun I tried with stroke width 0 and it also seems to work:

    ofPath path;
    path.moveTo(20, 20);
    path.lineTo(200, 50);
    auto & line = path.getOutline()[0];
    for(auto & v : line.getVertices()) {
        std::cout << v << std::endl;

thank you indeed this code is running fine here.
sorry about the incomplete case
I’m trying to get some two points simple lines from svg file (attached here in this post)
Maybe I’m doing something wrong or it is something related to ofxSvg

for (auto a=0; a<svg.getNumPath(); a++) {
	ofPath p = svg.getPathAt(a);
	vector <ofPolyline> linhas = p.getOutline();
	cout << linhas.size() << endl;
	if (linhas.size()) {
		cout << linhas[0].getVertices().size() << endl;


just tried that on 0.10 and it’s working fine as well so it might be a bug in 0.9.8

1 Like