Title: Fix a bug of ignoring the closing path segment when automatically determining whether to snap by ayshih · Pull Request #32018 · matplotlib/matplotlib · GitHub
Open Graph Title: Fix a bug of ignoring the closing path segment when automatically determining whether to snap by ayshih · Pull Request #32018 · matplotlib/matplotlib
X Title: Fix a bug of ignoring the closing path segment when automatically determining whether to snap by ayshih · Pull Request #32018 · matplotlib/matplotlib
Description: PR summary The current code for automatic determination of whether a path should be snapped – by checking whether all line segments are either horizontal or vertical – neglects to check the closing line segment for a closed path. That is, a closed path will be automatically determined to be snappable even when the closing line segment is not horizontal or vertical as long as all other line segments are either horizontal or vertical. This PR fixes that oversight. A not-uncommon place for this bug to have an effect in the wild is when plotting contours, and one contour region is just a triangular section at the corner of the plot. If the diagonal of that triangle happens to be the closing line segment, then that contour region will snap, while its adjacent contour region will typically not snap. A handful of figure tests show this effect. Here is a minimal example illustrating the bug: import matplotlib.pyplot as plt from matplotlib.patches import Polygon # diagonal is not the closing segment, so will not be snapped triangle1 = Polygon([[0, 0], [1, 0], [0, 1]]) # diagonal is the closing segment, so will be snapped due to the bug triangle2 = Polygon([[0, 1], [1, 1], [1, 0]]) fig, ax = plt.subplots() ax.add_patch(triangle1) ax.add_patch(triangle2) plt.show() Before this PR The gap between the two triangles is not a consistent width, showing that the two triangles are not snapping the same. The gap will change/flicker if the plot window is resized due to this difference in snapping. After this PR The gap between the two triangles is a consistent width, showing that both triangles are snapping the same. AI Disclosure No AI was used PR checklist [N/A] "closes #0000" is in the body of the PR description to link the related issue new and changed code is tested [N/A] Plotting related features are demonstrated in an example [N/A] New Features and API Changes are noted with a directive and release note [N/A] Documentation complies with general and docstring guidelines
Open Graph Description: PR summary The current code for automatic determination of whether a path should be snapped – by checking whether all line segments are either horizontal or vertical – neglects to check the closin...
X Description: PR summary The current code for automatic determination of whether a path should be snapped – by checking whether all line segments are either horizontal or vertical – neglects to check the closin...
Opengraph URL: https://github.com/matplotlib/matplotlib/pull/32018
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:e2ff78e5-271f-fbd8-92e7-bae700408708 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | A334:372744:11843B2:17E5647:6A521472 |
| html-safe-nonce | 3409e3099a62b05e2a22cc1482fe711170c09047e457ed384e2a27b99978f235 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMzM0OjM3Mjc0NDoxMTg0M0IyOjE3RTU2NDc6NkE1MjE0NzIiLCJ2aXNpdG9yX2lkIjoiMjE2MTM3MzE3MDI5MjEwMjI1OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 68e9d1fb5ab22489ef14dffea3fba5add2e492a8ec7fed1a6bd7217f3769fc48 |
| hovercard-subject-tag | pull_request:4011963952 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/matplotlib/matplotlib/pull/32018/files |
| twitter:image | https://avatars.githubusercontent.com/u/991759?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/991759?s=400&v=4 |
| og:image:alt | PR summary The current code for automatic determination of whether a path should be snapped – by checking whether all line segments are either horizontal or vertical – neglects to check the closin... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/matplotlib/matplotlib git https://github.com/matplotlib/matplotlib.git |
| octolytics-dimension-user_id | 215947 |
| octolytics-dimension-user_login | matplotlib |
| octolytics-dimension-repository_id | 1385122 |
| octolytics-dimension-repository_nwo | matplotlib/matplotlib |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1385122 |
| octolytics-dimension-repository_network_root_nwo | matplotlib/matplotlib |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width