8000 Updated patches.py to follow suggestions · matplotlib/matplotlib@ecdaa8e · GitHub
[go: up one dir, main page]

Skip to content

Commit ecdaa8e

Browse files
committed
Updated patches.py to follow suggestions
1 parent ee10314 commit ecdaa8e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

lib/matplotlib/patches.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,14 +1049,14 @@ def __init__(self, x, y, dx, dy, width=1.0, **kwargs):
10491049
%(Patch)s
10501050
"""
10511051
Patch.__init__(self, **kwargs)
1052-
L = np.sqrt(dx ** 2 + dy ** 2)
1052+
L = ny.hypot(dx, dy)
10531053

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
10601060

10611061
trans1 = transforms.Affine2D().scale(L, width)
10621062
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,
11171117
if head_length is None:
11181118
head_length = 1.5 * head_width
11191119

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)
11251121

11261122
if length_includes_head:
11271123
length = distance
@@ -1160,8 +1156,12 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
11601156
right_half_arrow[-2::-1]])
11611157
else:
11621158
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
11651165
M = np.array([[cx, sx], [-sx, cx]])
11661166
verts = np.dot(coords, M) + (x + dx, y + dy)
11671167

@@ -3210,16 +3210,16 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
32103210
# arrow from x0, y0 to x1, y1
32113211
dx, dy = x0 - x1, y0 - y1
32123212

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)
32183214

32193215
# pad_projected : amount of pad to account the
32203216
# overshooting of the projection of the wedge
32213217
pad_projected = (.5 * linewidth / sin_t)
32223218

3219+
# Account for division by zero
3220+
if cp_distance == 0:
3221+
cp_distance = 1
3222+
32233223
# apply pad for projected edge
32243224
ddx = pad_projected * dx / cp_distance
32253225
ddy = pad_projected * dy / cp_distance

0 commit comments

Comments
 (0)
0