API design suggestion on `zune_imageprocs::composite::Composite::try_new`
Closed this issue · 2 comments
The try_new
API supports two location parameters: geometry and gravity:
pub fn try_new(
image: &'a Image, composite_method: CompositeMethod, geometry: Option<(usize, usize)>,
gravity: Option<Gravity>
) -> Result<Self, &'static str>;
One must supply at least one of the two parameters. Otherwise an Err
will be returned.
Since the Err case is almost always a careless coding issue and could be addressed in compile time, I would suggest to split this method into two APIs: try_new
(with a mandatory geometry
parameter - or should we call it location
?), and try_new_gravity
, with a mandatory gravity
parameter and an optional geometry
(or offset
?) parameter, to make things simpler.
Hi, thanks for the suggestion, that is certainly better preferred.
I'm not sure which is more common, I.e gravity or geometry/position/location so I'd prefer if both have prefixes and we drop the try, something like new_gravity
and new_position
Nice!
The gravity API seems redundant to me though. It's trivial for the caller to calculate the absolute location, or at least a helper function would be sufficient to do that.