SelbaWard icon indicating copy to clipboard operation
SelbaWard copied to clipboard

Suggestion. sw::Spline -> sw::Polygon.

Open degski opened this issue 6 years ago • 2 comments

You asked for suggestions, so here's one.

The sw::Spline class is great, I love it, but we are talking about a line (of some thickness). What I would like (and have a use for) is to have a sw::Polygon, with which I mean to say, a sw::Spline that is filled. The Spline (the outline) is closed, in this case, of course.

Maybe you can have a think about it, if it's not clear, just post here.

degski avatar Oct 10 '18 08:10 degski

You're suggesting a concave polygon triangulated from the Spline, I presume. With the freedom of the Spline, this would allow overlapping areas which, I think, would be expected to be non-filled. When you also factor in the interpolated Splines, you get many points that would be used, resulting in very many triangles.

It seems that you mean to create a separate drawable object called Polygon that would store triangles but can be created from a Spline's current points. I'm not sure which approach would be better: separating the Polygon from the Spline or just adding "fill" flag to Spline and switching its calculation over to triangulation.

I will, either way, look into triangulation to make sure I can implement this in a relatively simple way.

Hapaxia avatar Oct 16 '18 23:10 Hapaxia

You're suggesting a concave polygon triangulated from the Spline, I presume.

Yes.

With the freedom of the Spline, this would allow overlapping areas which, I think, would be expected to be non-filled.

Do you mean that the [larger] Polygon could have holes? that would be great of course.

It seems that you mean to create a separate drawable object called Polygon that would store triangles but can be created from a Spline's current points.

Yes to the latter, if that requires triangles, yes.

I'm not sure which approach would be better: separating the Polygon from the Spline or just adding "fill" flag to Spline and switching its calculation over to triangulation.

In a way the sw::Spline is (just) a special kind of (sw::)Polygon, one with transparent fill. There will obviously be much overlap (all the stuff related to the outline), so my vote would be to "marry" the two. Then sw::Spline could become just a [specialized] typedef of sw::Polygon, as not to break existing code or require people to change their code-base.

I will, either way, look into triangulation to make sure I can implement this in a relatively simple way.

Great, I think this can be very useful and eventually should be put up for inclusion in SFML, as this class will be just another square, circle etc. From the whole SW collection, this one stands out as being close to existing functionality. Thanks for looking into this.

degski avatar Oct 19 '18 08:10 degski

Hi again.

I would like to just mention that Polygon has now been added to Selba Ward.

It is still in its early phase (currently at v1.1) but can currently triangulate a given set of points as long as there are no overlaps and the points are given in an anti-clockwise direction.

Future plans for this include:

  • allowing points in clockwise direction with a 'clockwise flag',
  • automatically detecting direction of points,
  • other triangulation methods,
  • triangulation refinements (e.g. post-processing),
  • allowing holes.

Note that it is not directly connected to Spline and just takes all of the points' positions and creates a polygon from that. Of course, you can get all of Spline's points' positions manually but the next version of Spline will include a simple way to 'export' all of those positions at once (and will be compatible with the 'dump' style method of Polygon that takes all points at once).

So, I shall now consider this issue complete (i.e. fixed) although feel free to open others for separate issues or others regarding Polygon/Spline.

Fixed in commit 3a65737

Hapaxia avatar Jan 12 '23 16:01 Hapaxia