williamngan / pts

A library for visualization and creative-coding
https://ptsjs.org
Apache License 2.0
5.16k stars 182 forks source link

Add support for polygons with holes #222

Open tibotiber opened 2 months ago

tibotiber commented 2 months ago

Hey @williamngan, I was wondering if there was any interest to support polygons with holes in the API? I see that the canvas API supports it (stackoverflow).

williamngan commented 2 months ago

Oh right, that would be a good feature. Maybe the API can be something like form.fillRule('evenodd').fill("#f00") ?

My bandwidth is very limited until probably mid Aug. Please send a PR if you would like to add this feature. Thanks so much!

tibotiber commented 2 months ago

I think the fill itself will be automatic, it's more about building the path. We'll need something like a polygonWithHoles(ptRings: PtLikeIterable[]) where the first ring is the outer one and then the others are the holes. Or maybe polygonWithHoles(pts: PtLikeIterable, holes: PtLikeIterable[]). What do you think? Any preferred naming/vocabulary?

I'm also swamped for now, but I've got a card opened for this in our backlog ;)