@@ -1049,14 +1049,14 @@ def __init__(self, x, y, dx, dy, width=1.0, **kwargs):
1049
1049
%(Patch)s
1050
1050
"""
1051
1051
Patch .__init__ (self , ** kwargs )
1052
- L = np . sqrt (dx ** 2 + dy ** 2 )
1052
+ L = ny . hypot (dx , dy )
1053
1053
1054
- # Account for divide by zero
1055
- if L == 0 :
1056
- L = 1
1057
-
1058
- cx = float ( dx ) / L
1059
- sx = float ( dy ) / L
1054
+ if L != 0 :
1055
+ cx = float ( dx ) / L
1056
+ sx = float ( dy ) / L
1057
+ else :
1058
+ # Account for division by zero
1059
+ cx , sx = 0 , 1
1060
1060
1061
1061
trans1 = transforms .Affine2D ().scale (L , width )
1062
1062
trans2 = transforms .Affine2D .from_values (cx , sx , - sx , cx , 0.0 , 0.0 )
@@ -1117,11 +1117,7 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
1117
1117
if head_length is None :
1118
1118
head_length = 1.5 * head_width
1119
1119
1120
- distance = np .sqrt (dx ** 2 + dy ** 2 )
1121
-
1122
- # Account for divide by zero
1123
- if distance == 0 :
1124
- distance = 1
1120
+ distance = np .hypot (dx , dy )
1125
1121
1126
1122
if length_includes_head :
1127
1123
length = distance
@@ -1160,8 +1156,12 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
1160
1156
right_half_arrow [- 2 ::- 1 ]])
1161
1157
else :
1162
1158
raise ValueError ("Got unknown shape: %s" % shape )
1163
- cx = float (dx ) / distance
1164
- sx = float (dy ) / distance
1159
+ if distance != 0 :
1160
+ cx = float (dx ) / distance
1161
+ sx = float (dy ) / distance
1162
+ else :
1163
+ #Account for division by zero
1164
+ cx , sx = 0 , 1
1165
1165
M = np .array ([[cx , sx ], [- sx , cx ]])
1166
1166
verts = np .dot (coords , M ) + (x + dx , y + dy )
1167
1167
@@ -3210,16 +3210,16 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
3210
3210
# arrow from x0, y0 to x1, y1
3211
3211
dx , dy = x0 - x1 , y0 - y1
3212
3212
3213
- cp_distance = math .sqrt (dx ** 2 + dy ** 2 )
3214
-
3215
- # Account for divide by zero
3216
- if cp_distance == 0 :
3217
- cp_distance = 1
3213
+ cp_distance = np .hypot (dx , dy )
3218
3214
3219
3215
# pad_projected : amount of pad to account the
3220
3216
# overshooting of the projection of the wedge
3221
3217
pad_projected = (.5 * linewidth / sin_t )
3222
3218
3219
+ # Account for division by zero
3220
+ if cp_distance == 0 :
3221
+ cp_distance = 1
3222
+
3223
3223
# apply pad for projected edge
3224
3224
ddx = pad_projected * dx / cp_distance
3225
3225
ddy = pad_projected * dy / cp_distance
0 commit comments