ImageSharp.Drawing icon indicating copy to clipboard operation
ImageSharp.Drawing copied to clipboard

Convenience constructors for shapes

Open antonfirsov opened this issue 5 years ago • 3 comments

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 avatar Nov 11 '20 22:11 antonfirsov

@antonfirsov I'm assuming we'd accept a Span<PointF> for each parameter?

JimBobSquarePants avatar Jul 07 '21 12:07 JimBobSquarePants

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?

antonfirsov avatar Jul 08 '21 00:07 antonfirsov

Old school it is then!

JimBobSquarePants avatar Jul 08 '21 01:07 JimBobSquarePants

It looks like we've covered this now. Closing

JimBobSquarePants avatar Aug 13 '23 10:08 JimBobSquarePants

I didn't mean this just for ComplexPolygon. Path and Polygon could use a similar constructors.

antonfirsov avatar Aug 14 '23 08:08 antonfirsov

I had a look at those but couldn’t see a way to improve them. Happy to hear suggestions though! 🙂

JimBobSquarePants avatar Aug 14 '23 08:08 JimBobSquarePants

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.

antonfirsov avatar Aug 14 '23 08:08 antonfirsov