-
Notifications
You must be signed in to change notification settings - Fork 22.9k
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
d3.geo.circle clipping is buggy #691
Comments
I started working on a fix for clipping a while ago, sorry it’s taken so long! I should have some time to look at this soon, as I need it to work for an upcoming project. For clipping, I can see two possibilities:
In both cases I would use Weiler-Atherton as it handles holes correctly, and my preference is for no. 1 as I think it's faster and you can reuse the projected coordinates. As for resampling, this was there mainly to handle the clipped edges, since most unclipped geo polygons are reasonably high precision already. At the moment, we just resample everything after clipping, regardless if it was a clipped or unclipped edge. So I think it would be reasonable to only resample clipped edges. If necessary, polygons can be resampled beforehand e.g. for the grid, but this wouldn't be necessary in most cases e.g. most country polygons. Do you have any ideas about how reusing the Cartesian coordinates would look for the API? (It could also just be the sin/cos values if that's more usable). Perhaps the cached values could be piggy-backed onto the coordinates array, but that seems like a hack. Or we could expose projecting to Cartesian space so that it's explicitly cached, and this can be used for any animated projections. If a projection receives spherical coordinates, it can just convert on-the-fly instead. Anyway, I guess fixing the clipping bug should be done first, then optimised afterwards. :) |
Thanks for looking into this! I think the bug might be how the interpolation point is generated; I'm not sure Clipping to a circle sounds simpler than clipping to a convex polygon, and also more precise. I don't have any specific guidance on other improvements to make yet. Mainly I'd like to fix the clipping bug. :) |
Here is a fixed version of the spinning globe that only clips points (no resampling): http://bl.ocks.org/3031319 It also uses d3.svg.line’s defined property to split clipped lines into multiple segments. Clever, eh? :) |
Ooh, very nice! See #695 for a fix, it turns out the last interpolation step was buggy. |
There’s still a bug. It's fairly easy to see if you reduce the geodesic subdivision to 1 and clip an icosahedron: http://bl.ocks.org/3061181. I suspect that the bug is still related to how we handle closed polygons. Would love if you could take another look, @jasondavies. :) Edit: Actually, you don't get this bug when using d3.geodesic.multilinestring (as in the grid example), because those aren't closed polygons. You only get it with a multipolygon or polygons. |
I have devised a solution for closed polygons (with holes). Now I just need to implement it. Watch this space. :) |
The icosahedron bug is actually due to a bug in the way d3.geodesic inserts the final point; it should be: face.push(face[0]) Instead of: face.push(face[2]) |
The fixed version: http://bl.ocks.org/3072830 Although note that it's using my new clipping algorithm now, too. :) |
Aw, man! Nice find on the bug, and sorry it was my fault. :) Let me know how the new clipping algorithm progresses. |
Hey guys -- I think I'm experiencing a related set of issues to the above with Basically, I get an error The error occurs for me on the latest versions of Chrome and Safari on OS X, though I can't seem to reproduce it in Firefox. It's also apparent in the above referenced Orthographic Clipping example and older examples ():
Notably, I can't get the console to squawk for this example in either Safari or Chrome:
I've also gone so far as to litter my own copy of the lastest I hope the above details are helpful in tracking down some deeper bug, rather than simply dealing with some aberrant edge case.* Please let me know if there's anything I can do to help, though I'm basically brand new to the world of JS and know next-to-nothing about SVG as well (sorry!). Thanks for all the work on this -- it's an awesome library. Nick
|
Circle clipping seems to mostly work, but I think it's buggy.
For example, say you're viewing the default hemisphere centered around ⟨0,0⟩ and have a simple two-point LineString that starts at ⟨+60,0⟩ and ends at ⟨-60,0⟩. To render this correctly, you actually need to convert a LineString to a MultiLineString: you have one visible segment from ⟨+60,0⟩ to ⟨+90,0⟩ and another visible segment from ⟨-90,0⟩ to ⟨-60,0⟩. There's no way to represent the discontinuity here based on the current implementation; we'd need to change the
clip(coordinates)
function to return an array of coordinates to represent broken segments.It's pretty easy to see this bug when you enable clipping with the rotating Azimuthal grid example.
Related: I also wonder if there is a more efficient way to enable clipping with animation. Currently, we resample after clipping. If we resampled before clipping, perhaps we wouldn't need to resample at each frame of the animation—we could just clip the coordinates directly. But maybe that's not possible.
/cc @jasondavies
The text was updated successfully, but these errors were encountered: