PolyLine should accept closed at initialization #1412

Merged
merged 1 commit into from Oct 21, 2016

Projects

None yet

4 participants

@drewish
Contributor
drewish commented Apr 2, 2016

This let's me simplify some code like:

ci::PolyLine2f BuildingPlan::triangle()
{
    ci::PolyLine2f result( { ci::vec2(10, -10), ci::vec2(10, 10), ci::vec2(-10, 10), ci::vec2(10, -10)  } );
    result.setClosed();
    return result;
}

Down to a one liner.

ci::PolyLine2f BuildingPlan::triangle()
{
    return ci::PolyLine2f( { ci::vec2(10, -10), ci::vec2(10, 10), ci::vec2(-10, 10), ci::vec2(10, -10)  }, true );
}
@mottosso
mottosso commented Apr 3, 2016

I personally really like the named parameter idiom spread across Cinder. Could that work here?

ci::PolyLine2f BuildingPlan::triangle()
{
    return ci::PolyLine2f( { ci::vec2(10, -10), ci::vec2(10, 10), ci::vec2(-10, 10), ci::vec2(10, -10)  } ).closed(true);
}

Though it should probably apply to the other arguments too.

@drewish
Contributor
drewish commented Apr 3, 2016

@mottosso yeah that's actually a nice pattern to follow, and it'd be backwards compatible if we left the other methods in place.

Edit: I think it's make sense to define closed with a default param of true so you could just do closed() or closed(false)

@richardeakin
Collaborator

I also prefer a named method rather than additional bool as argument, because it is clearer at the call site. That said, I don't believe the classes like Polyline, Shape2d, are currently using the named parameter idiom, not that they shouldn't but need to weigh whether we want to start introducing methods in that fashion there.

@andrewfb
Collaborator

I'm inclined to accept this as written. I'm not opposed to NPI in instances like this, but it does feel like a policy that needs to revisited on a larger scale at some future date.

@andrewfb andrewfb merged commit e5a28a6 into cinder:master Oct 21, 2016
@drewish drewish deleted the drewish:polyline-closed branch Oct 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment