From cb2e4fd4fe71ea7b1f9fa9be90b1293cb1790020 Mon Sep 17 00:00:00 2001
From: Bart Crouch <bartius.crouch@gmail.com>
Date: Tue, 1 Nov 2011 18:52:14 +0000
Subject: [PATCH] Fix for divide-by-zero errors.

---
 mesh_looptools.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/mesh_looptools.py b/mesh_looptools.py
index 0bfb876e5..174c32240 100644
--- a/mesh_looptools.py
+++ b/mesh_looptools.py
@@ -19,9 +19,9 @@
 bl_info = {
     'name': "LoopTools",
     'author': "Bart Crouch",
-    'version': (3, 2, 0),
-    'blender': (2, 5, 7),
-    'api': 35979,
+    'version': (3, 2, 1),
+    'blender': (2, 6, 0),
+    'api': 41270,
     'location': "View3D > Toolbar and View3D > Specials (W-key)",
     'warning': "",
     'description': "Mesh modelling toolkit. Several tools to aid modelling",
@@ -249,9 +249,13 @@ def calculate_plane(mesh_mod, loop, method="best_fit", object=False):
             vec = mathutils.Vector((1.0, 1.0, 1.0))
             vec2 = (mat * vec)/(mat * vec).length
             while vec != vec2 and iter<itermax:
-                iter += 1
+                iter+=1
                 vec = vec2
-                vec2 = (mat * vec)/(mat * vec).length
+                vec2 = mat * vec
+                if vec2.length != 0:
+                    vec2 /= vec2.length
+            if vec2.length == 0:
+                vec2 = mathutils.Vector((1.0, 1.0, 1.0))
             normal = vec2
     
     elif method == 'normal':
@@ -936,7 +940,11 @@ def bridge_calculate_lines(mesh, loops, mode, twist, reverse):
             while vec != vec2 and iter<itermax:
                 iter+=1
                 vec = vec2
-                vec2 = (mat * vec)/(mat * vec).length
+                vec2 = mat * vec
+                if vec2.length != 0:
+                    vec2 /= vec2.length
+            if vec2.length == 0:
+                vec2 = mathutils.Vector((1.0, 1.0, 1.0))
             normal = vec2
         normals.append(normal)
     # have plane normals face in the same direction (maximum angle: 90 degrees)
-- 
GitLab