Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ofPath::arc adding radial line #5236

Open
ofTheo opened this issue Aug 26, 2016 · 6 comments · Fixed by #6224
Open

ofPath::arc adding radial line #5236

ofTheo opened this issue Aug 26, 2016 · 6 comments · Fixed by #6224
Assignees
Milestone

Comments

@ofTheo
Copy link
Member

ofTheo commented Aug 26, 2016

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

@ofTheo ofTheo self-assigned this Aug 26, 2016
@ofTheo ofTheo added this to the 0.10.0 milestone Aug 26, 2016
@ofTheo
Copy link
Member Author

ofTheo commented Aug 26, 2016

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

@ofZach
Copy link
Contributor

ofZach commented Dec 14, 2016

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

@unjust
Copy link

unjust commented Jun 14, 2018

#2928

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

@CarstenHoyer
Copy link
Contributor

CarstenHoyer commented Feb 1, 2019

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

Any news on this issue?

@arturoc
Copy link
Member

arturoc commented Feb 1, 2019

can you send a PR with the fixes?

CarstenHoyer pushed a commit to CarstenHoyer/openFrameworks that referenced this issue Feb 1, 2019
Remove the first command from ofPath, when the path command is arc.

fixes openframeworks#5236
@CarstenHoyer
Copy link
Contributor

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

arturoc pushed a commit that referenced this issue Feb 3, 2019
Remove the first command from ofPath, when the path command is arc.

fixes #5236 

#changelog #graphics
gumilastik pushed a commit to gumilastik/openFrameworks that referenced this issue Feb 27, 2019
…eworks#6224)

Remove the first command from ofPath, when the path command is arc.

fixes openframeworks#5236 

#changelog #graphics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants