10000 Fix zerolen intersect by tacaswell · Pull Request #16250 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Fix zerolen intersect #16250

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 23, 2020
Merged

Conversation

tacaswell
Copy link
Member

PR Summary

This provides two fixes for #15842 which independently fix the reported bug.

The first merges segments when iterating through the paths, the second ensures that a 0 length segment intersects with no other segment (rather than all (or maybe just some?) segments.

The 0 length segment not intersecting any segments, including ones it is a point on, matches the behavior of shapely.

attn @TarasKuzyo

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant

@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 18, 2020
@tacaswell tacaswell added this to the v3.1.3 milestone Jan 18, 2020
@tacaswell tacaswell requested a review from QuLogic January 18, 2020 00:36
@tacaswell
Copy link
Member Author

Compare df6316c and 325d0ce , I am not sure which of those is the correct way to ID "zero length" segments. I am open to only one of these fixes going in, but this seems like a case where a belt-and-suspenders approach is warranted.

while (c2.vertex(&x22, &y22) != agg::path_cmd_stop) {
// if the segment in path 2 is 0 length, skip to next vertex
if ((x21 == x22) && (y21 == y22)) {
continue;
Copy link
Contributor
@anntzer anntzer Jan 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you're really going to do the check to zero-len both here and in segments_intersect (which seems weird as well, I'd rather not(?)) at least the check should be the same in both places (len < epsilon)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My logic was this:

  • computing == is cheaper
  • if trip the == condition, we will trigger the determinant condition, but the converse is not true.
  • do the cheaper, stricter thing here
  • do the more expensive looser thing where we have to (see my discussion with @timhoffm above)
  • keep all of the "isclose" logic together in the code so we are sure that the numbers don't get out of sync

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well you could change the signature of isclose() to just isclose(a, b) and force atol and rtol as constants in the body of the function... I'm not going to block over that though.

Copy link
Contributor
@anntzer anntzer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if CI passes

One method to fix matplotlib#15842

In this case we check in `path_intersect_path` that as we iterate
through the segments, if we hit a 0 length segment we grab the next
vertex before checking if the segments from the two paths intersect.
One method to fix matplotlib#15842

In this case we check that if either segment is 0 length, it
intersects with no other segments, not all other segments.
To make clear we won't be changing them.
Use length square being close to 0 rather than strict.  I have a worry
that because we are using "close" for identifying the determinant is
0, if we use strict equality for the length, then we may pass through
the length check, but erroneously go through the den == 0 path.
Makes it a bit easier to identify failing cases.
 - move the "close to 0" computation from segments_intersect to
 path_intersects_path so we only do it once.
 - change the signature of the c function isclose to back the atol and
 rtol into the function (to make sure the two places we use it stay in
 sync)
@tacaswell tacaswell force-pushed the fix_zerolen_intersect branch from fef57d4 to ffaf302 Compare January 23, 2020 06:12
@jklymak jklymak merged commit 7e1a47c into matplotlib:master Jan 23, 2020
@lumberbot-app
Copy link
lumberbot-app bot commented Jan 23, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.1.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 7e1a47c252a5da06961dc2484602f57fa3009d77
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #16250: Fix zerolen intersect'
  1. Push to a named branch :
git push YOURFORK v3.1.x:auto-backport-of-pr-16250-on-v3.1.x
  1. Create a PR against branch v3.1.x, I would have named this PR:

"Backport PR #16250 on branch v3.1.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 23, 2020
timhoffm added a commit that referenced this pull request Jan 23, 2020
…250-on-v3.2.x

Backport PR #16250 on branch v3.2.x (Fix zerolen intersect)
@tacaswell tacaswell deleted the fix_zerolen_intersect branch January 24, 2020 21:15
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Jan 25, 2020
Merge pull request matplotlib#16250 from tacaswell/fix_zerolen_intersect

Fix zerolen intersect

Also re-factors some tests.

Conflicts:
	lib/matplotlib/tests/test_path.py
          - unrelated change to test above new test.  Kept old version
            of test and added new test
timhoffm added a commit that referenced this pull request Jan 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
0