-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Support Complex Polygons #1163
Support Complex Polygons #1163
Conversation
@DavidHudlow I'd still like to review this in more detail, but I made some updates so that it works with recent changes we made to our Cartesian types (#1120). To get my changes, first merge the main Cesium repo into your branch. There will be a couple of trivial conflicts. Fix them and commit. Then merge my complexpolygon. Here is the commit with my changes: dc703f9 |
You'll also want 2183e58, which fixes a terriable mistake I made. How hard is it to add a test case for this? |
Yes, indeed. Looks like the original code intended to compare if (s2.cross(s1) < s3.cross(s4).z) { |
@DavidHudlow would it be better to always use the same seed for this algorithm so that we get deterministic results? For example, for files like https://raw.github.com/turban/N2000-Kartdata/master/NO_Admin_latlng.topojson. What is the benefit of using a different seed? |
- Triangulation algorithm now identifies intersection and throws it instead of choking on complex polygon - PolygonGeometry will continually attempt to triangulate until all intersections have been found and polygon is simple - Added example to polygon sandcastle example - Made a change to GeometryPipeline to skip over zero vectors. Also had to update a test that was failing because of a zero vector rather than why it was supposed to be failing. Zero vectors are sometimes encountered in simplified complex polygons (or any polygon that has a non-consecutive duplicate vertex)
Computing the winding order of a complex polygon without knowing about its self-intersections is (I think) impossible. Therefore if we can't make a polygon work any other way, we'll try reversing its winding order. (The triangulation algorithm works on the assumption that the winding order will be counter-clockwise at vertex 0). Added complex polygon support to CHANGES.md
Conflicts: CHANGES.md Source/Core/GeometryPipeline.js Source/Core/PolygonGeometry.js Source/Core/PolygonPipeline.js
@pjcozzi Yes, that should have had the .z. rseed (perhaps not really a seed?), must change before each new random number is generated so that the new number will be different from the last. It can be manually reset using resetSeed() before beginning triangulation of a new polygon. There is no disadvantage to this. The reason I changed the algorithm to use this random algorithm rather than Math.random() was so that the "seed" could be reset for testing for deterministic results. |
@pjcozzi Are you still seeing failures with that file? I haven't been able to reproduce them, so maybe your fix to that cross product comparison fixed the problem? |
Also, regarding adding test cases for changes to the algorithm, unfortunately, it's difficult to come up with cases that will predictably cause the algorithm to fail because of the nature of randomly trying to find valid divisions. If a flaw in the algorithm causes some cuts to be branded invalid when they're valid, there may be alternatives found that cause the triangulation to still succeed. Likewise if a division is considered valid based on one criteria (say, it's deemed internal when it's really not), it will often be correctly branded invalid because it crosses a side of the polygon. The other difficulty is that although you can triangulate a polygon 100 times to see if it ever chokes, you can't automatically determine if each result was actually valid (because the order of the triangles is different each time). Having said that, it would certainly be possible to create some more "special case" tests that have a higher tendency to reveal problems. It might also be possible to create some good cases and iterate (or generate) every possible valid result for more thorough testing. |
David, I'm not very familiar with the polygon code, but it's possible for us to generate random, but repeatable numbers in the tests. Before each test use CesiumMath.setRnadomNumberSeed(0) and then have your code call CesiumMath.nextRandomNumber instead of the RNG you are using now. This ensures that your get the randomness you need, but it will create repeatable tests. See the bottom of https://github.com/AnalyticalGraphicsInc/cesium/blob/master/Source/Core/Math.js |
@DavidHudlow can you fix the doc build in your branch?
I think we need to remove the I am with @mramato about generating repeatable random values. My question was can we do this all the time - not just for tests - so we have consistent runtime behavior. It sounds like we can, right? With NO_Admin_latlng.topojson, I still got the error on my 3rd try running out of your fork. |
@mramato Yes, I'll definitely change it to use CesiumMath's random number generator, and have it reset the seed before beginning each polygon triangulation. I'm not sure if that was available when I first changed the triangulation algorithm, but if it was, I wasn't aware of it. @pjcozzi I'll try to track that down. |
The random number thing is indeed new. My vote would be to leave the seed alone, so it can be user-controlled when desired. This would result in different default behavior when files are loaded in a different order, but it would still be repeatable behavior, and the user could pick seeds that work better for special cases. |
David (and Ed) rather than use the CesiumMath functions, me and Cozzi feel On Thu, Sep 26, 2013 at 4:10 PM, Ed Mackey notifications@github.com wrote:
|
@mramato is spot on. |
That last commit is a bit thrown together. Not sure if it'll fix all cases, but it seems to fix the issue with the file we were testing. I'm a little concerned about the performance of these additions though. I'm afraid I may have hurt us there. I'll try to investigate that, but it may be hard to get it done before the next release. |
Back of the napkin numbers shows performance to be about the same. |
@DavidHudlow I'll close this for now, but please reopen when you are ready. We can track with #1209, which is now an enhancement, not a bug fix. |
Fixes issue #1121 by supporting the complex polygon in the given file.