Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix containment test with nonlinear transforms.#7844

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

anntzer
Copy link
Contributor

@anntzeranntzer commentedJan 16, 2017
edited
Loading

Fixes#3540; see in particular#3540 (comment).

Edit: Alsofixes#7655.

@mdboom Would it be reasonable to remove the definition ofTransform.__array__ and only keepAffine2D.__array__, thus forcing call sites to explicitly only pass in affine transforms to the C++ code, rather than sometimes silently dropping the nonlinear part (as in this case)?

@codecov-io
Copy link

Current coverage is 62.10% (diff: 60.00%)

Merging#7844 intomaster will increase coverage by<.01%

@@             master      #7844   diff @@==========================================  Files           174        174            Lines         56051      56054     +3     Methods           0          0            Messages          0          0            Branches          0          0          ==========================================+ Hits          34808      34811     +3  Misses        21243      21243            Partials          0          0

Powered byCodecov. Last update3b9a92d...050b20c

@NelleV
Copy link
Member

Can you add a regression test?

@anntzer
Copy link
ContributorAuthor

Done.

NelleV
NelleV previously approved these changesJan 28, 2017
Copy link
Member

@NelleVNelleV left a comment
edited
Loading

Choose a reason for hiding this comment

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

It looks good.
Can you move the import at the top of module?

result = _path.point_in_path(point[0], point[1], radius, self,
transform)
return result
from .transforms import Affine2D
Copy link
Member

Choose a reason for hiding this comment

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

Any reason to have this here and not at the top of the module as python convention require?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Probably dates back to when I implemented this as a quickfix. Moved up.

@anntzer
Copy link
ContributorAuthor

Actually there is a circular import between transforms.py and path.py, so I left the Affine2D import inside the function, with a note to that effect.

@anntzer
Copy link
ContributorAuthor

Test failure is probably related to pytest migration... we can wait until it is done, as that seems close(?).

@NelleVNelleV changed the titleFix containment test with nonlinear transforms.[MRG+1] Fix containment test with nonlinear transforms.Jan 29, 2017
@NelleV
Copy link
Member

Let's wait until the pytest migration is over.

But, can we fix the circular import in a more robust way?

@anntzer
Copy link
ContributorAuthor

This would likely imply a small performance cost astransforms relies on passing a Path toupdate_path_extent to compute not only extremal points (which is just as cheap in numpy) but also minpos (andx[x > 0].min() is very likely slower than a C loop). (Fixing#7413 would probably help.)

@NelleV
Copy link
Member

I would feel much more comfortable with fixing the circular import.

@anntzer
Copy link
ContributorAuthor

There's alsotransform_path_affine, which currently reads

    def transform_path_affine(self, path):        return Path(self.transform_affine(path.vertices),                    path.codes, path._interpolation_steps)

and would have to become something like

    def transform_path_affine(self, path):        return type(path)(self.transform_affine(path.vertices),                    path.codes, path._interpolation_steps)

which is worse than a circular import IMO.

@NelleVNelleV changed the title[MRG+1] Fix containment test with nonlinear transforms.Fix containment test with nonlinear transforms.Jan 29, 2017
@NelleVNelleV dismissed theirstale reviewJanuary 29, 2017 20:39

I don't think this should be merge with a circular import.

@anntzer
Copy link
ContributorAuthor

What is you preferred solution other than the circular import, then? As mentioned above I can work around it by obfuscating the implementation oftransform_path_affine to sneakily get a handle to the Path class without a circular import, but that's not really better IMO.

# We need to import Affine2D here to prevent a circular import between
# the .path and .transforms modules.
from .transforms import Affine2D
if transform and not isinstance(transform, Affine2D):
Copy link
Member

Choose a reason for hiding this comment

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

Can't this beif not transform.is_affine: ? That seems way better thatisinstance anyway.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Good catch, done.

@anntzeranntzerforce-pushed thenonlinear-transformed-path-containment branch from7d67293 toffd60aaCompareFebruary 21, 2017 01:46
@tacaswelltacaswell added this to the2.1 (next point release) milestoneFeb 23, 2017
@anntzeranntzer changed the titleFix containment test with nonlinear transforms.[MRG] Fix containment test with nonlinear transforms.Mar 15, 2017
Copy link
Member

@NelleVNelleV left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@NelleVNelleV changed the title[MRG] Fix containment test with nonlinear transforms.[MRG+"] Fix containment test with nonlinear transforms.Mar 19, 2017
@NelleVNelleV changed the title[MRG+"] Fix containment test with nonlinear transforms.[MRG+1] Fix containment test with nonlinear transforms.Mar 19, 2017
polygon = ax.axvspan(1, 10)
assert polygon.get_path().contains_point(
ax.transData.transform_point((5, .5)), ax.transData)

Copy link
Member

Choose a reason for hiding this comment

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

May also be worth checking that the points (0.5, 0.5) and (20, 0.5) are not insidepolygon

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

done

# transform the path ourselves. If `transform` is affine, letting
# `point_in_path` handle the transform avoids allocating an extra
# buffer.
if transform and not transform.is_affine:
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason not to just do the transformation here even if it is an affine transformation? (thus removing theif block)

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Iguess you may save the creation of a large temporary (if the c++ code does the transform one point at a time), which would be relevant for very large paths.

To be honest I don't know but decided not to take any risks.

dstansby reacted with thumbs up emoji
@anntzeranntzerforce-pushed thenonlinear-transformed-path-containment branch fromffd60aa to76173e1CompareMarch 19, 2017 19:11
Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

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

👍 Will merge if/when tests pass

@dstansbydstansby self-assigned thisMar 19, 2017
@dstansbydstansby merged commit0611b61 intomatplotlib:masterMar 19, 2017
@dstansbydstansby changed the title[MRG+1] Fix containment test with nonlinear transforms.Fix containment test with nonlinear transforms.Mar 19, 2017
@anntzeranntzer deleted the nonlinear-transformed-path-containment branchMarch 19, 2017 20:33
@dstansbydstansby removed their assignmentApr 10, 2017
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@tacaswelltacaswelltacaswell left review comments

@NelleVNelleVNelleV approved these changes

@dstansbydstansbydstansby approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

Event picking does not seem to work on polar bar plots Pick events broken in log axes
5 participants
@anntzer@codecov-io@NelleV@tacaswell@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp