Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit aa70121

Browse filesBrowse files
committed
Merge pull request #4173 from basharovV/master
BUG : fix zero length ConnectionPatch closes #3930
2 parents 893dfa3 + ddb7798 commit aa70121
Copy full SHA for aa70121

File tree

Expand file treeCollapse file tree

6 files changed

+1278
-681
lines changed
Filter options
Expand file treeCollapse file tree

6 files changed

+1278
-681
lines changed

‎lib/matplotlib/bezier.py

Copy file name to clipboardExpand all lines: lib/matplotlib/bezier.py
+8-4Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ def find_bezier_t_intersecting_with_closedpath(bezier_point_at_t,
124124
start_inside = inside_closedpath(start)
125125
end_inside = inside_closedpath(end)
126126

127-
if not xor(start_inside, end_inside):
128-
raise NonIntersectingPathException(
129-
"the segment does not seem to intersect with the path"
130-
)
127+
if start_inside == end_inside:
128+
if start != end:
129+
raise NonIntersectingPathException(
130+
"the segment does not seem to intersect with the path"
131+
)
131132

132133
while 1:
133134

@@ -317,6 +318,9 @@ def _f(xy):
317318
def get_cos_sin(x0, y0, x1, y1):
318319
dx, dy = x1 - x0, y1 - y0
319320
d = (dx * dx + dy * dy) ** .5
321+
# Account for divide by zero
322+
if d == 0:
323+
return 0.0, 0.0
320324
return dx / d, dy / d
321325

322326

‎lib/matplotlib/patches.py

Copy file name to clipboardExpand all lines: lib/matplotlib/patches.py
+22-8Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,9 +1048,14 @@ def __init__(self, x, y, dx, dy, width=1.0, **kwargs):
10481048
%(Patch)s
10491049
"""
10501050
Patch.__init__(self, **kwargs)
1051-
L = np.sqrt(dx ** 2 + dy ** 2) or 1 # account for div by zero
1052-
cx = float(dx) / L
1053-
sx = float(dy) / L
1051+
L = np.hypot(dx, dy)
1052+
1053+
if L != 0:
1054+
cx = float(dx) / L
1055+
sx = float(dy) / L
1056+
else:
1057+
# Account for division by zero
1058+
cx, sx = 0, 1
10541059

10551060
trans1 = transforms.Affine2D().scale(L, width)
10561061
trans2 = transforms.Affine2D.from_values(cx, sx, -sx, cx, 0.0, 0.0)
@@ -1111,7 +1116,8 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
11111116
if head_length is None:
11121117
head_length = 1.5 * head_width
11131118

1114-
distance = np.sqrt(dx ** 2 + dy ** 2)
1119+
distance = np.hypot(dx, dy)
1120+
11151121
if length_includes_head:
11161122
length = distance
11171123
else:
@@ -1149,8 +1155,12 @@ def __init__(self, x, y, dx, dy, width=0.001, length_includes_head=False,
11491155
right_half_arrow[-2::-1]])
11501156
else:
11511157
raise ValueError("Got unknown shape: %s" % shape)
1152-
cx = float(dx) / distance
1153-
sx = float(dy) / distance
1158+
if distance != 0:
1159+
cx = float(dx) / distance
1160+
sx = float(dy) / distance
1161+
else:
1162+
#Account for division by zero
1163+
cx, sx = 0, 1
11541164
M = np.array([[cx, sx], [-sx, cx]])
11551165
verts = np.dot(coords, M) + (x + dx, y + dy)
11561166

@@ -3193,14 +3203,18 @@ def _get_arrow_wedge(self, x0, y0, x1, y1,
31933203
"""
31943204

31953205
# arrow from x0, y0 to x1, y1
3196-
31973206
dx, dy = x0 - x1, y0 - y1
3198-
cp_distance = math.sqrt(dx ** 2 + dy ** 2)
3207+
3208+
cp_distance = np.hypot(dx, dy)
31993209

32003210
# pad_projected : amount of pad to account the
32013211
# overshooting of the projection of the wedge
32023212
pad_projected = (.5 * linewidth / sin_t)
32033213

3214+
# Account for division by zero
3215+
if cp_distance == 0:
3216+
cp_distance = 1
3217+
32043218
# apply pad for projected edge
32053219
ddx = pad_projected * dx / cp_distance
32063220
ddy = pad_projected * dy / cp_distance
Binary file not shown.
Loading

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.