Catch a failed math.triangulate without crashing?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Catch a failed math.triangulate without crashing?
This one's pretty straightforward. I would like to be able to call triangulate without the game crashing if it fails. Failing that, I'd like to be able to test whether my points can be triangulated or not (I want the user to be able to draw polygons without crashing the game).
Re: Catch a failed math.triangulate without crashing?
Doesn't pcall() help?
Re: Catch a failed math.triangulate without crashing?
Make sure you are working with simple polygons:
https://2dengine.com/?p=polygons#Simple_or_complex
Yes, you can use pcall to check if the function raises an error.
But note that Love2D's triangulation function is not efficient and the quality of triangulation is poor.
I think love.math.triangulate uses "ear clipping" as described in my tutorial:
https://2dengine.com/?p=polygons#Triangulation
This is a simple technique but it's slow and produces long skinny triangles.
Re: Catch a failed math.triangulate without crashing?
Thanks for the help! I wound up using a pcall to catch it.
Perhaps I'll look into other triangulate options in the future, but for now Love's seems to work.
Perhaps I'll look into other triangulate options in the future, but for now Love's seems to work.
Who is online
Users browsing this forum: Ahrefs [Bot] and 148 guests