From 7b65f39008e9a894e7dad957aebe15f826290297 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Fri, 6 Mar 2020 00:13:02 +0100 Subject: [PATCH] Backport PR #16682: Avoid floating point rounding causing bezier.get_parallels to fail --- lib/matplotlib/bezier.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/matplotlib/bezier.py b/lib/matplotlib/bezier.py index 44c74c458982..d3e74afb4881 100644 --- a/lib/matplotlib/bezier.py +++ b/lib/matplotlib/bezier.py @@ -429,23 +429,23 @@ def get_parallels(bezier2, width): # find cm_left which is the intersecting point of a line through # c1_left with angle t1 and a line through c2_left with angle # t2. Same with cm_right. - if parallel_test != 0: - # a special case for a straight line, i.e., angle between two - # lines are smaller than some (arbitrary) value. - cmx_left, cmy_left = ( - 0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left) - ) - cmx_right, cmy_right = ( - 0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right) - ) - else: + try: cmx_left, cmy_left = get_intersection(c1x_left, c1y_left, cos_t1, sin_t1, c2x_left, c2y_left, cos_t2, sin_t2) - cmx_right, cmy_right = get_intersection(c1x_right, c1y_right, cos_t1, sin_t1, c2x_right, c2y_right, cos_t2, sin_t2) + except ValueError: + # Special case straight lines, i.e., angle between two lines is + # less than the threshold used by get_intersection (we don't use + # check_if_parallel as the threshold is not the same). + cmx_left, cmy_left = ( + 0.5 * (c1x_left + c2x_left), 0.5 * (c1y_left + c2y_left) + ) + cmx_right, cmy_right = ( + 0.5 * (c1x_right + c2x_right), 0.5 * (c1y_right + c2y_right) + ) # the parallel Bezier lines are created with control points of # [c1_left, cm_left, c2_left] and [c1_right, cm_right, c2_right] 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