-
Notifications
You must be signed in to change notification settings - Fork 360
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
fix treatment of spine paths with explicit path-codes #2362
base: main
Are you sure you want to change the base?
Conversation
|
In case the GeoSpine path represents a multi-path, don't attemt to close it since this would convert the multi-path into a single closed path resulting in unwanted connector-lines between the individual polygons.
5e3889d
to
7bca0a3
Compare
@greglucas
To keep your changes for single closed paths, I've implemented the fix so that it only triggers if the path actually represents a multi-path (e.g. if it contains more than 1 |
Tests fail with |
Is there a way to do something like: One other thought is that perhaps the previous fix was actually a non-ideal one where This should get a test somehow, can you modify your example figure output to count moveto/close before/after this change? |
Closing is hereby performed by appending the first vertex with a CLOSEPOLY code rather than treating the last vertex as CLOSEPOLY to avoid gaps at the corner.
Hey, @greglucas, thanks for the quick response!
I had a quick look... it seems that using ...
elif closed and len(vertices):
codes = np.empty(len(vertices), dtype=self.code_type)
codes[0] = self.MOVETO
codes[1:-1] = self.LINETO
codes[-1] = self.CLOSEPOLY I agree that this might cause problems if the last vertex and the first should actually be connected.
I've now updated the PR to perform a more complete check and make sure that the path (and all potential sub-paths) are properly closed with the start-vertex.
For the currently implemented method I don't think it's necessary to count since If you agree with my proposed solution, I can write a test for |
Test-failure is again just a download-issue. |
@raphaelquast , some tests would be good regardless of the solution I think! You've definitely found some issues, so codifying those with tests would be great. I think this is good. I do have some concern that this is in a potential hot-loop when zooming/panning around, but the fix looks like the "proper" solution to account for the various cases. |
@greglucas I've now added some basic unittests to check proper handling of single- and multi-path boundaries (based on image-comparison) |
Test failures are again unrelated but I don't seem to have the rights to trigger a manual re-run. |
Hey, just checking in to see what's missing to get this merged?
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, been really busy on other projects the past month and lost track of this, thanks for the ping!
CLA
Yes, you should sign it again. There is a new CLA on all SciTools contributions now. It is a much simpler process and should take place immediately instead of needing a human to review it.
Code
Did you look at this as an option for closing the polygons? https://matplotlib.org/stable/api/path_api.html#matplotlib.path.Path.to_polygons
Specifically, this comment catches my eye saying any unclosed polys will be closed:
If closed_only is True (default), only closed polygons, with the last point being the same as the first point, will be returned. Any unclosed polylines in the path will be explicitly closed.
Testing
Are you able to put all of those tests into a single image with subplots to reduce the number of image comparisons/binary data you're adding?
Is there a way to test this without image comparisons. Our image comparisons are always fragile, so I'm wondering if you can say something like "before this change the boundary path had only 1 CLOSEPOLY, now it should have 5".
Rationale
The current implementation of the
adjust_location
method ofGeoSpines
assumes that the spine-path is a single connected path and potential path-codes are ignored.This causes problems if multi-paths are used as bounaries to clip the map (e.g. with
ax.set_boundary()
.... for example:Implications
With the proposed changes, path-codes are preserved and multi-path clipping works as expected