Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e72ed82

Browse files
authored
Merge pull request #16690 from meeseeksmachine/auto-backport-of-pr-16682-on-v3.2.x
Backport PR #16682 on branch v3.2.x (Avoid floating point rounding causing bezier.get_parallels to fail)
2 parents 71a13b0 + 7b65f39 commit e72ed82

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

lib/matplotlib/bezier.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,23 @@ def get_parallels(bezier2, width):
429429
# find cm_left which is the intersecting point of a line through
430430
# c1_left with angle t1 and a line through c2_left with angle
431431
# t2. Same with cm_right.
432-
if parallel_test != 0:
433-
# a special case for a straight line, i.e., angle between two
434-
# lines are smaller than some (arbitrary) value.
435-
cmx_left, cmy_left = (
436-
0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left)
437-
)
438-
cmx_right, cmy_right = (
439-
0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right)
440-
)
441-
else:
432+
try:
442433
cmx_left, cmy_left = get_intersection(c1x_left, c1y_left, cos_t1,
443434
sin_t1, c2x_left, c2y_left,
444435
cos_t2, sin_t2)
445-
446436
cmx_right, cmy_right = get_intersection(c1x_right, c1y_right, cos_t1,
447437
sin_t1, c2x_right, c2y_right,
448438
cos_t2, sin_t2)
439+
except ValueError:
440+
# Special case straight lines, i.e., angle between two lines is
441+
# less than the threshold used by get_intersection (we don't use
442+
# check_if_parallel as the threshold is not the same).
443+
cmx_left, cmy_left = (
444+
0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left)
445+
)
446+
cmx_right, cmy_right = (
447+
0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right)
448+
)
449449

450450
# the parallel Bezier lines are created with control points of
451451
# [c1_left, cm_left, c2_left] and [c1_right, cm_right, c2_right]

0 commit comments

Comments
 (0)