Skip to content

Commit 7bae46c

Browse files
authored
Merge pull request #16682 from ksunden/bezier_parallel
Avoid floating point rounding causing bezier.get_parallels to fail
2 parents 858f9ca + 4c2bdc3 commit 7bae46c

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
@@ -389,23 +389,23 @@ def get_parallels(bezier2, width):
389389
# find cm_left which is the intersecting point of a line through
390390
# c1_left with angle t1 and a line through c2_left with angle
391391
# t2. Same with cm_right.
392-
if parallel_test != 0:
393-
# a special case for a straight line, i.e., angle between two
394-
# lines are smaller than some (arbitrary) value.
395-
cmx_left, cmy_left = (
396-
0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left)
397-
)
398-
cmx_right, cmy_right = (
399-
0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right)
400-
)
401-
else:
392+
try:
402393
cmx_left, cmy_left = get_intersection(c1x_left, c1y_left, cos_t1,
403394
sin_t1, c2x_left, c2y_left,
404395
cos_t2, sin_t2)
405-
406396
cmx_right, cmy_right = get_intersection(c1x_right, c1y_right, cos_t1,
407397
sin_t1, c2x_right, c2y_right,
408398
cos_t2, sin_t2)
399+
except ValueError:
400+
# Special case straight lines, i.e., angle between two lines is
401+
# less than the threshold used by get_intersection (we don't use
402+
# check_if_parallel as the threshold is not the same).
403+
cmx_left, cmy_left = (
404+
0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left)
405+
)
406+
cmx_right, cmy_right = (
407+
0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right)
408+
)
409409

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy