From 97039067dacef98b10f985770468a8eb4dd97aa9 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 29 May 2014 09:27:38 +0200 Subject: Replace some 'sqrt(a*a, b*b)' by 'hypot(a, b)'. Patch by ldo (Lawrence D'Oliveiro), with very minor changes by myself. --- node_efficiency_tools.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'node_efficiency_tools.py') diff --git a/node_efficiency_tools.py b/node_efficiency_tools.py index 2451b5a7..1a7941a6 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] -- cgit v1.2.3