Openframeworks: ofPath::arc adding radial line

Created on 26 Aug 2016  路  6Comments  路  Source: openframeworks/openFrameworks

From the forums:
https://forum.openframeworks.cc/t/arc-without-drawing-radius-lines/24343

Note this issue appears with current master.

The following code produces an unexpected straight line:

    ofPath path;

    //draw an arc with a center starting at 300, 300, radius of 150 over 180 degrees
    //should appear like a semi-circle
    path.arc(300, 300, 150, 150, -180, 0);
    path.setFilled(false);
    path.setStrokeWidth(1);

    path.draw();

screen shot 2016-08-26 at 4 38 55 pm

But ofPolyline::arc looks correct.

    ofPolyline poly;

    //draw an arc with a center starting at 300, 300, radius of 150 over 180 degrees
    //should appear like a semi-circle
    poly.arc(300, 300, 150, 150, -180, 0);

   poly.draw();

screen shot 2016-08-26 at 4 40 25 pm

bug core

Most helpful comment

So the issue seems to be that ofPath::addCommand adds a moveTo command if a command list hasn't started with one.

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/graphics/ofPath.cpp#L864

Normally this is fine, but with ofPath::arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd) the Command.To is not the drawing position but the center of the arc. So a moveTo set the path position at the center and then a line is drawn to the start of the arc.

A working solution is to preempt the automatic adding of the moveTo in ofPath::addCommand by doing one within ofPath::arc that sets the moveTo to the correct position.

//----------------------------------------------------------
void ofPath::arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd){
    if(mode==COMMANDS){
        //NEW----
        //addCommand adds a moveTo if one hasn't been set, but in this case it is adding a moveTo to the center of the arc and not the beginning of the arc
        if(commands.empty() || commands.back().type==Command::close){
            glm::vec3 start = centre + glm::vec3( glm::cos( glm::radians(angleBegin) ) * radiusX, glm::sin( glm::radians(angleBegin) ) * radiusY, 0.0f );
            commands.push_back(Command(Command::moveTo,start));
        }
        //END NEW----       
        addCommand(Command(Command::arc,centre,radiusX,radiusY,angleBegin,angleEnd));

screen shot 2016-08-26 at 5 00 46 pm

Can't see any downsides to this approach, but would appreciate others double checking :)

All 6 comments

So the issue seems to be that ofPath::addCommand adds a moveTo command if a command list hasn't started with one.

https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/graphics/ofPath.cpp#L864

Normally this is fine, but with ofPath::arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd) the Command.To is not the drawing position but the center of the arc. So a moveTo set the path position at the center and then a line is drawn to the start of the arc.

A working solution is to preempt the automatic adding of the moveTo in ofPath::addCommand by doing one within ofPath::arc that sets the moveTo to the correct position.

//----------------------------------------------------------
void ofPath::arc(const glm::vec3 & centre, float radiusX, float radiusY, float angleBegin, float angleEnd){
    if(mode==COMMANDS){
        //NEW----
        //addCommand adds a moveTo if one hasn't been set, but in this case it is adding a moveTo to the center of the arc and not the beginning of the arc
        if(commands.empty() || commands.back().type==Command::close){
            glm::vec3 start = centre + glm::vec3( glm::cos( glm::radians(angleBegin) ) * radiusX, glm::sin( glm::radians(angleBegin) ) * radiusY, 0.0f );
            commands.push_back(Command(Command::moveTo,start));
        }
        //END NEW----       
        addCommand(Command(Command::arc,centre,radiusX,radiusY,angleBegin,angleEnd));

screen shot 2016-08-26 at 5 00 46 pm

Can't see any downsides to this approach, but would appreciate others double checking :)

related?

ofPath p;
p.circle(300, 300, 100);
ofPolyline outline = p.getOutline()[0];
outline.draw();

produces:

screen shot 2016-12-14 at 4 41 20 am

https://github.com/openframeworks/openFrameworks/issues/2928

this seems to be related too. trying to think of how to solve this. working with circles and ofPath at the moment.

I also had to add tthe fix from @ofTheo to arcNegative. But then it works.

Any news on this issue?

can you send a PR with the fixes?

This ellipse will give the same issue - The PR does not fix that.

I'm not sure that should be considered a bug, since you could just moveTo 450, 150 and then center the ellipse att 400, 150.

ofPath path;
path.moveTo(450, 150);
path.ellipse(450, 150, 100, 100);
Was this page helpful?
0 / 5 - 0 ratings

Related issues

gaborpapp picture gaborpapp  路  10Comments

dimitre picture dimitre  路  4Comments

dimitre picture dimitre  路  4Comments

hellokitty-glitch picture hellokitty-glitch  路  7Comments

lewislepton picture lewislepton  路  7Comments