changeset 449:a99e5e724545

Better convex polygon protection
author Neil Muller <drnlmuller@gmail.com>
date Sat, 07 Sep 2013 15:08:59 +0200
parents 044b53eb22df
children fe6546d07d5e
files tools/area_editor.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/tools/area_editor.py	Sat Sep 07 15:04:39 2013 +0200
+++ b/tools/area_editor.py	Sat Sep 07 15:08:59 2013 +0200
@@ -379,18 +379,23 @@
                 # Evil, but faster than good
                 try:
                     l = eval(text)
-                    args.append(' - - %s' % l[0])
-                    for coord in l[1:]:
-                        args.append('   - %s' % coord)
                 except Exception:
                     alert("Invalid polygon %s" % text)
                     self.needs_cleanup = False
                     return None
                 # Check for convexity
-                hull = pymunk.util.convex_hull(l)
-                if hull != l:
+                if not pymunk.util.is_convex(l):
                     alert("Invalid polygon %s - not convex" % text)
                     return None
+                if not pymunk.util.is_clockwise(l):
+                    l.reverse()
+                    if not pymunk.util.is_clockwise(l):
+                        alert("Invalid polygon %s - unable to make clockwise"
+                              % text)
+                        return None
+                args.append(' - - %s' % l[0])
+                for coord in l[1:]:
+                    args.append('   - %s' % coord)
             else:
                 args.append(' - ' + text)
         data = "args:\n" + '\n'.join(args)