ImageSharp.Drawing
ImageSharp.Drawing copied to clipboard
Convenience constructors for shapes
Given a PointF arrays contour and hole, this is how a ComplexPolygon could be constructed today:
ComplexPolygon polygon = new ComplexPolygon(
new Path(new LinearLineSegment(contour)),
new Path(new LinearLineSegment(hole)));
It should be as easy as:
ComplexPolygon polygon = new ComplexPolygon(contour, hole);
We need to review the shape types and add convenience constructors based on the principle of "good defaults".
@antonfirsov I'm assuming we'd accept a Span<PointF> for each parameter?
Hah, this seems to be an easy question but it isn't.
Currently the LinearLineSegment(PointF[]) constructor takes ownership of the array without copying, this makes sense since it avoids an allocation and a copy for the user, but note that with Span (or rather ReadOnlySpan) the constructor is forced to do a copy. Do we want the Span and the ROS constructor to behave differently? If most users will fill these things from arrays anyways, maybe we just want to keep these API-s oldschool, and array-only?
Old school it is then!
It looks like we've covered this now. Closing
I didn't mean this just for ComplexPolygon. Path and Polygon could use a similar constructors.
I had a look at those but couldn’t see a way to improve them. Happy to hear suggestions though! 🙂
I expect most real-life paths and polygons to be created given a list of points, yet there is no way for feeding those points directly to Path and Polygon constructors. A user needs to create LinearLineSegment around them first. We need Path(PointF[]) and Polygon(PointF[]) constructors.