[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2100] trunk/py/scripts/addons/modules/ curve_utils.py: pep8 edits

Campbell Barton ideasman42 at gmail.com
Wed Jul 6 14:20:27 CEST 2011


Revision: 2100
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2100
Author:   campbellbarton
Date:     2011-07-06 12:20:27 +0000 (Wed, 06 Jul 2011)
Log Message:
-----------
pep8 edits

Modified Paths:
--------------
    trunk/py/scripts/addons/modules/curve_utils.py

Modified: trunk/py/scripts/addons/modules/curve_utils.py
===================================================================
--- trunk/py/scripts/addons/modules/curve_utils.py	2011-07-06 09:32:27 UTC (rev 2099)
+++ trunk/py/scripts/addons/modules/curve_utils.py	2011-07-06 12:20:27 UTC (rev 2100)
@@ -20,8 +20,9 @@
 
 import bpy
 
+
 def vis_curve_object():
-    scene = bpy.data.scenes[0] # weak!
+    scene = bpy.data.scenes[0]  # weak!
     cu = bpy.data.curves.new(name="Line", type='CURVE')
     ob = bpy.data.objects.new(name="Test", object_data=cu)
     ob.layers = [True] * 20
@@ -42,7 +43,7 @@
 
 def vis_circle_object(co, rad=1.0):
     import math
-    scene = bpy.data.scenes[0] # weak!
+    scene = bpy.data.scenes[0]  # weak!
     ob = bpy.data.objects.new(name="Circle", object_data=None)
     ob.rotation_euler.x = math.pi / 2
     ob.location = co.to_3d()
@@ -60,7 +61,7 @@
     spline.points.add(1)
     for co, v in zip((pair), spline.points):
         v.co.xyz = co
-    
+
     if p3:
         spline = ob.data.splines.new(type='POLY')
         spline.points[0].co.xyz = p3.to_3d()
@@ -89,7 +90,7 @@
 
 
 def solve_curvature(p1, p2, n1, n2, fac, fallback):
-    """ Add a nice circular curvature on 
+    """ Add a nice circular curvature on
     """
     from mathutils import Vector
     from mathutils.geometry import (barycentric_transform,
@@ -115,11 +116,11 @@
         p1_first_order = p1.lerp(corner, fac)
         p2_first_order = corner.lerp(p2, fac)
         co = p1_first_order.lerp(p2_first_order, fac)
-        
+
         return co
     else:
         # cant interpolate. just return interpolated value
-        return fallback.copy() # p1.lerp(p2, fac)
+        return fallback.copy()  # p1.lerp(p2, fac)
 
 
 def points_to_bezier(points_orig,
@@ -173,7 +174,7 @@
                 v1 = (self.co - self.prev.co).normalized()
             if self.next and not self.next.is_joint:
                 v2 = (self.next.co - self.co).normalized()
-            
+
             if v1 and v2:
                 self.no = (v1 + v2).normalized()
             elif v1:
@@ -184,7 +185,6 @@
                 print("Warning, assigning dummy normal")
                 self.no = Vector((0.0, 1, 0.0))
 
-
     class Spline(object):
         __slots__ = ("points",
                      "handle_left",
@@ -224,10 +224,10 @@
 
             # invalidate self, dont reuse!
             self.points = None
-            
+
             spline_a.next = spline_b
             spline_b.prev = spline_a
-    
+
             spline_a.prev = prev
             spline_b.next = next
             if prev:
@@ -269,14 +269,14 @@
 
                 if smooth:
                     if p is None:
-                        pass # works ok but no smoothing
+                        pass  # works ok but no smoothing
                     elif (p.prev.no - p.no).length < 0.001:
-                        pass # normals are too similar, paralelle
+                        pass  # normals are too similar, paralelle
                     elif (p.angle > 0.0) != (p.prev.angle > 0.0):
                         pass
                     else:
                         # visualize_line(p.co, p.co + p.no)
-                        
+
                         # this assumes co is on the line
                         fac = ((p.prev.co - co).length /
                                (p.prev.co - p.co).length)
@@ -303,12 +303,12 @@
             print("START")
             while p:
                 # we want the first pont past the segment size
-                
+
                 #if p.is_joint:
                 #    vis_circle_object(p.co)
 
                 length = (points[-1][0] - p.co).length
-                
+
                 if abs(length - segment_length) < 0.00001:
                     # close enough to be considered on the circle bounds
                     point_add(p.co)
@@ -319,7 +319,7 @@
                 else:
                     # the point is further then the segment width
                     p_start = points[-1][0] if p.prev is p_line else p.prev.co
-                    
+
                     if (p_start - points[-1][0]).length > segment_length:
                         raise Exception("eek2")
                     if (p.co - points[-1][0]).length < segment_length:
@@ -339,8 +339,7 @@
                         p_line = p.prev
                     elif i2:
                         raise Exception("err")
-                    
-                    
+
                     elif i1 is None and i2 is None:
                         visualize_line(p_start,
                                        p.co,
@@ -353,13 +352,13 @@
                         point_add(p.co)
                         p_line = p
                         p = point_step(p)
-                
+
             joint = self.points[0].is_joint, self.points[-1].is_joint
 
             self.points = [Point(p[1]) for p in points]
 
             self.points[0].is_joint, self.points[-1].is_joint = joint
-            
+
             self.calc_all()
             # raise Exception("END")
 
@@ -388,7 +387,7 @@
 
             for p_apex in point_iter:
                 ix, fac = intersect_point_line(p_apex.co, bi_l1, bi_l2)
-                
+
                 if fac < 0.0001:
 
                     if reverse:
@@ -407,7 +406,7 @@
 
                     w1 = (p_test_1 - p_apex.co).length
                     w2 = (p_test_2 - p_apex_other.co).length
-                    
+
                     #assert(w1 + w2 != 0)
                     try:
                         fac = w1 / (w1 + w2)
@@ -423,7 +422,7 @@
                     # visualize_line(p_apex.co.to_3d(), p_apex_co.to_3d())
 
                     return p_apex_co, p_apex_no, p_apex
-            
+
             # intersection not found
             return None, None, None
 
@@ -431,7 +430,7 @@
             """ Calculate bezier handles,
                 assume the splines have been broken up.
 
-                
+
             """
 
             from mathutils.geometry import (intersect_point_line,
@@ -445,17 +444,17 @@
             # ------
             # take 2
             p_vec = (p2.co - p1.co).normalized()
-            
+
             # vector between line and point directions
             l1_no = (p1.no + p_vec).normalized()
             l2_no = ((-p2.no) - p_vec).normalized()
-            
+
             l1_co = p1.co + l1_no
             l2_co = p2.co + l2_no
-            
+
             # visualize_line(p1.co, l1_co)
             # visualize_line(p2.co, l2_co)
-            
+
             line_ix_p1_co, line_ix_p1_no, line_ix_p1 = \
                     self.intersect_line(p1.co,
                                         l1_co,
@@ -472,7 +471,6 @@
                 line_ix_p2_co, line_ix_p2_no, line_ix_p2 = \
                         p2.prev.co, p2.prev.no, p2.prev
 
-
             # vis_circle_object(line_ix_p1_co)
             # vis_circle_object(line_ix_p2_co)
 
@@ -498,16 +496,14 @@
                     p2_apex_co = p.co
                 p = p.prev
 
-            
             if p1_apex_co is None:
                 p1_apex_co = p1.next.co
             if p2_apex_co is None:
                 p2_apex_co = p2.prev.co
 
-
             l1_tan = (p1.no - p1.no.project(l1_no)).normalized()
             l2_tan = -(p2.no - p2.no.project(l2_no)).normalized()
-            
+
             # values are good!
             #~ visualize_line(p1.co, p1.co + l1_tan)
             #~ visualize_line(p2.co, p2.co + l2_tan)
@@ -517,20 +513,25 @@
 
             # calculate bias based on the position of the other point allong
             # the tangent.
-            
+
             # first need to reflect the second normal for angle comparison
             # first fist need the reflection normal
             no_ref = p_vec.cross(p2.no).cross(p_vec).normalized()
             l2_no_ref = p2.no.reflect(no_ref).normalized()
             del no_ref
 
-
             from math import pi
             # This could be tweaked but seems to work well
-            fac_fac = (p1.co - p2.co).length * (0.5 / 0.75) * p1.no.angle(l2_no_ref) / pi
+            fac_fac = (p1.co - p2.co).length * p1.no.angle(l2_no_ref) / pi
 
-            fac_1 = intersect_point_line(p2_apex_co, p1.co, p1.co + l1_tan)[1] * fac_fac
-            fac_2 = intersect_point_line(p1_apex_co, p2.co, p2.co + l2_tan)[1] * fac_fac
+            fac_1 = intersect_point_line(p2_apex_co,
+                                         p1.co,
+                                         p1.co + l1_tan,
+                                         )[1] * fac_fac
+            fac_2 = intersect_point_line(p1_apex_co,
+                                         p2.co,
+                                         p2.co + l2_tan,
+                                         )[1] * fac_fac
 
             h1_fac = ((p1.co - p1_apex_co).length / 0.75) - fac_1
             h2_fac = ((p2.co - p2_apex_co).length / 0.75) - fac_2
@@ -544,11 +545,10 @@
             '''
             visualize_line(p1.co, p1_apex_co)
             visualize_line(p1_apex_co, p2_apex_co)
-            visualize_line(p2.co, p2_apex_co) 
+            visualize_line(p2.co, p2_apex_co)
             visualize_line(p1.co, p2.co)
             '''
 
-
         def bezier_error(self, error_max=-1.0, test_count=8):
             from mathutils.geometry import interpolate_bezier
 
@@ -563,7 +563,7 @@
 
             error = 0.0
 
-            # this is a rough method measuring the error but should be good enough
+            # this is a rough method measuring the error but should be ok
             # TODO. dont test against every single point.
             for co in test_points:
                 co = co
@@ -577,7 +577,7 @@
                     if length < length_best:
                         length_best = length
                         co_best = p.co
-                    
+
                     p_ix, fac = intersect_point_line(co, p.co, p.prev.co)
                     p_ix = p_ix
                     if fac >= 0.0 and fac <= 1.0:
@@ -585,9 +585,9 @@
                         if length < length_best:
                             length_best = length
                             co_best = p_ix
-                
+
                 error += length_best / test_count
-                
+
                 if error_max != -1.0 and error > error_max:
                     return True
 
@@ -629,7 +629,7 @@
             s = self.splines[s_index]
             while s:
                 assert(self.splines[s_index] == s)
-                
+

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list