[Bf-extensions-cvs] [9703906] master: Replace some 'sqrt(a*a, b*b)' by 'hypot(a, b)'.

Bastien Montagne noreply at git.blender.org
Thu May 29 10:16:15 CEST 2014


Commit: 97039067dacef98b10f985770468a8eb4dd97aa9
Author: Bastien Montagne
Date:   Thu May 29 09:27:38 2014 +0200
https://developer.blender.org/rBA97039067dacef98b10f985770468a8eb4dd97aa9

Replace some 'sqrt(a*a, b*b)' by 'hypot(a, b)'.

Patch by ldo (Lawrence D'Oliveiro), with very minor changes by myself.

===================================================================

M	add_mesh_ant_landscape.py
M	mesh_inset/triquad.py
M	node_efficiency_tools.py

===================================================================

diff --git a/add_mesh_ant_landscape.py b/add_mesh_ant_landscape.py
index b99eb2b..e83b613 100644
--- a/add_mesh_ant_landscape.py
+++ b/add_mesh_ant_landscape.py
@@ -332,7 +332,7 @@ def landscape_gen(x,y,z,falloffsize,options=[0,1.0,1, 0,0,1.0,0,6,1.0,2.0,1.0,2.
     # edge falloff
     if sphere == 0: # no edge falloff if spherical
         if falloff != 0:
-            fallofftypes = [ 0, sqrt((x*x)**2+(y*y)**2), sqrt(x*x+y*y), sqrt(y*y), sqrt(x*x) ]
+            fallofftypes = [0, hypot(x * x, y * y), hypot(x, y), abs(y), abs(x)]
             dist = fallofftypes[ falloff]
             if falloff ==1:
                 radius = (falloffsize/2)**2
diff --git a/mesh_inset/triquad.py b/mesh_inset/triquad.py
index 88affa8..0c4fc84 100644
--- a/mesh_inset/triquad.py
+++ b/mesh_inset/triquad.py
@@ -22,7 +22,7 @@
 from . import geom
 import math
 import random
-from math import sqrt
+from math import sqrt, hypot
 
 # Points are 3-tuples or 2-tuples of reals: (x,y,z) or (x,y)
 # Faces are lists of integers (vertex indices into coord lists)
@@ -1051,7 +1051,7 @@ def Add2(a, b):
 def Length2(v):
     """Return length of vector v=(x,y)."""
 
-    return sqrt(v[0] * v[0] + v[1] * v[1])
+    return hypot(v[0], v[1])
 
 
 def LinInterp2(a, b, alpha):
diff --git a/node_efficiency_tools.py b/node_efficiency_tools.py
index 2451b5a..1a7941a 100644
--- a/node_efficiency_tools.py
+++ b/node_efficiency_tools.py
@@ -34,7 +34,7 @@ from bpy.types import Operator, Panel, Menu
 from bpy.props import FloatProperty, EnumProperty, BoolProperty, IntProperty, StringProperty, FloatVectorProperty, CollectionProperty
 from bpy_extras.io_utils import ImportHelper
 from mathutils import Vector
-from math import cos, sin, pi, sqrt
+from math import cos, sin, pi, hypot
 from os import listdir
 
 #################
@@ -561,15 +561,15 @@ def node_at_pos(nodes, context, event):
                             # There's got to be a better way to do this...
                             skipnode = True
             if not skipnode:
-                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - locy) ** 2)])  # Top Left
-                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - locy) ** 2)])  # Top Right
-                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Left
-                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-dimy)) ** 2)])  # Bottom Right
-
-                node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - locy) ** 2)])  # Mid Top
-                node_points_with_dist.append([node, sqrt((x - (locx+(dimx/2))) ** 2 + (y - (locy-dimy)) ** 2)])  # Mid Bottom
-                node_points_with_dist.append([node, sqrt((x - locx) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Left
-                node_points_with_dist.append([node, sqrt((x - (locx+dimx)) ** 2 + (y - (locy-(dimy/2))) ** 2)])  # Mid Right
+                node_points_with_dist.append([node, hypot(x - locx, y - locy)])  # Top Left
+                node_points_with_dist.append([node, hypot(x - (locx + dimx), y - locy)])  # Top Right
+                node_points_with_dist.append([node, hypot(x - locx, y - (locy - dimy))])  # Bottom Left
+                node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - dimy))])  # Bottom Right
+
+                node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - locy)])  # Mid Top
+                node_points_with_dist.append([node, hypot(x - (locx + (dimx / 2)), y - (locy - dimy))])  # Mid Bottom
+                node_points_with_dist.append([node, hypot(x - locx, y - (locy - (dimy / 2)))])  # Mid Left
+                node_points_with_dist.append([node, hypot(x - (locx + dimx), y - (locy - (dimy / 2)))])  # Mid Right
 
     nearest_node = sorted(node_points_with_dist, key=lambda k: k[1])[0][0]



More information about the Bf-extensions-cvs mailing list