vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
402 stars 48 forks source link

Make Triangulation Error Catchable #16

Closed benui-dev closed 12 years ago

benui-dev commented 12 years ago

I'm trying to triangulate concave polygon shapes as the player draws them, and as they draw the shapes they often (in moving their mouse) create un-triangulate-able shapes.

Would it be possible to change the way Triangulate fails to allow me to detect the error and simply draw the poly in red and until the user fixes the shape? At the moment Löve just dumps when an invalid shape is drawn.

vrld commented 12 years ago

You can catch error()s with pcall() or xpcall():

ok, poly = pcall(shapes.newPolygonShape, unpack(points))
if not ok then handle_error() end

or with an anonymous function

if not pcall(function() poly = HC:addPolygon(unpack(points)) end) then
    handle_error()
end