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
triplot(x, y, simplex) should not modify the simplex array as a side effect. #1584
Comments
OK, here is my analysis of the problem. There are two ways of using a Triangulation, you either specify the triangles yourself or let the code create a Delaunay triangulation for you. The bug only affects the former. The triangles are specified as an array of triangles, each of which is three point indices. Triangulation expects the triangles to be ordered in an anticlockwise manner; if they are ordered in a clockwise manner the indices of the incorrect triangles are reordered so that they are anticlockwise. As the triangles array is not copied before it is altered, this has the unwanted side effect of changing the user's triangles array. The problem occurs only if a user specifies a triangles array containing one or more incorrectly-ordered (clockwise) triangles. If we fix this, there may be other users who are inadvertently relying on the Triangulation 'correcting' their triangles array and who now observe different behaviour. This is acceptable, but we need to be aware that some users may be confused by the change. There are two options for a fix:
Option 1 is quick and easy, but for users using the 'correct' triangle order may result in an unnecessary array copy. Option 2 is more work, some in C++, but is not difficult. I am happy to do either, but what do other developers prefer? Is avoiding an unnecessary array copy worth the extra complexity of option 2? |
Could another option be to detect the clockwise orientation and consider it |
The plotting functions probably should still work with badly oriented arrays. Note that a copy is silently made also if the input data type happens to be something else than int32 (for instance, the default Numpy int type on 64-bit platforms is int64). So users relying on this may be playing a bit of a dangerous game. |
@WeatherGod: I would rather not change the existing behaviour of accepting and correcting clockwise orientation as it has worked liked this since the tri-functions were added and changing it will have a large impact. Also, the choice of anticlockwise as the 'correct' orientation is somewhat arbitrary, so accepting either orientation is sensible. |
After consideration, I think we should go for the simplest option for the fix (item 1 above) as in @pv's original PR #1576. @pv: I can't seem to reopen your PR. Perhaps, as the owner, you can do so. If not, could submit a new PR? Could you also change your use of 'simplices' to 'triangles', as this is consistent with other usage of the tri-functions? Then I will merge the changes into both the maintenance and master branches. If you can't or don't want to then I can create a new PR and merge it, but then your name won't be attached to the fix so you won't get the credit you are due for writing the fix. |
@ianthomas23: sure, I'll try to reopen it. |
PR #1576 applied to both v1.2.x and master. |
triplot modifies its input simplex argument, as it orients the triangles anticlockwise. Plotting something should not change the data provided, as this is rather unexpected.
Example case:
This e.g. breaks the Qhull invariant on how vertices relate to the neighborhood structure, so it would be useful not to do this.
The text was updated successfully, but these errors were encountered: