You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: split_bezier_intersecting_with_closedpath fails to return #27753
It looks like, for some inputs, split_bezier_intersecting_with_closedpath never returns, as the while True: loop inside find_bezier_t_intersecting_with_closedpath fails to converge.
I'm not sure there is a whole lot we can do here... this ultimately just comes down to floating point precision being asked to compare a tolerance that is smaller than it can actually distinguish at the scale of the numbers you are working with.
The default tolerance is 0.01 and the np.spacing on the largest of the numbers you are working with is 0.015625... Thus it is impossible (or at least within rounding modes on the least significant bit of the floating point calculation) to be better than the tolerance requested, but it is not within tolerance, so it doesn't stop.
Increasing the tolerance (the third parameter to the split_bezier_intersecting_with_closedpath function) will help, but note you are still at the edges of floating point precision with some of these, so be a little careful. This particular example I was able to get to converge with a tolerance of 0.014, though I would be weary of anything that is below at least about 4x np.spacing of your largest values (maybe even 10x, honestly)
I'm inclined to close this as "won't fix" since the only real alternative would be to detect stable cycles (this one was just repeating the same values, so maybe just looking for repeated consecutive values would be enough) and either error, or warn and return the closest values... But neither of those options seem great and it introduces some complexity only for some pretty rare edge cases. Though I will give other maintainers the opportunity to weigh in before actually closing.
Regardless, the tools exist to allow you to get what you want (i.e. specifying a larger tolerance)q
I could also see an argument for scaling the default tolerance to the magnitude of the values given, I suppose, as 0.01 is not a good value for really large (as here) or really small coordinate values (where it will terminate potentially too early instead). But that would be a behavior change that may even need to go through deprecation cycles.
Increasing the tolerance (the third parameter to the split_bezier_intersecting_with_closedpath function)
This is actually happening inside ax.add_patch(arrow) (where arrow is a FancyArrowPatch) , and I'm not specifying the tolerances directly (not sure at this stage where they comeform). Can I somehow define the tolenrance for the FancyArrowPatch or the axes, or a somesort of global matplotlib config?
I'm not sure there is a whole lot we can do here... this ultimately just comes down to floating point precision being asked to compare a tolerance that is smaller than it can actually distinguish at the scale of the numbers you are working with.
Is this something that can be detected and adjusted/raised as an error auotmatically by checking the values? Or alternatively, is this something I can guard against when creating the FancyArrowPatch?
Activity
ksunden commentedon Feb 7, 2024
I'm not sure there is a whole lot we can do here... this ultimately just comes down to floating point precision being asked to compare a tolerance that is smaller than it can actually distinguish at the scale of the numbers you are working with.
The default tolerance is 0.01 and the
np.spacingon the largest of the numbers you are working with is0.015625... Thus it is impossible (or at least within rounding modes on the least significant bit of the floating point calculation) to be better than the tolerance requested, but it is not within tolerance, so it doesn't stop.Increasing the tolerance (the third parameter to the
split_bezier_intersecting_with_closedpathfunction) will help, but note you are still at the edges of floating point precision with some of these, so be a little careful. This particular example I was able to get to converge with a tolerance of0.014, though I would be weary of anything that is below at least about 4xnp.spacingof your largest values (maybe even 10x, honestly)I'm inclined to close this as "won't fix" since the only real alternative would be to detect stable cycles (this one was just repeating the same values, so maybe just looking for repeated consecutive values would be enough) and either error, or warn and return the closest values... But neither of those options seem great and it introduces some complexity only for some pretty rare edge cases. Though I will give other maintainers the opportunity to weigh in before actually closing.
Regardless, the tools exist to allow you to get what you want (i.e. specifying a larger tolerance)q
I could also see an argument for scaling the default
toleranceto the magnitude of the values given, I suppose, as 0.01 is not a good value for really large (as here) or really small coordinate values (where it will terminate potentially too early instead). But that would be a behavior change that may even need to go through deprecation cycles.setrofim commentedon Feb 7, 2024
This is actually happening inside
ax.add_patch(arrow)(wherearrowis aFancyArrowPatch) , and I'm not specifying the tolerances directly (not sure at this stage where they comeform). Can I somehow define the tolenrance for theFancyArrowPatchor the axes, or a somesort of globalmatplotlibconfig?Is this something that can be detected and adjusted/raised as an error auotmatically by checking the values? Or alternatively, is this something I can guard against when creating the
FancyArrowPatch?Add protections against infinite loop in bezier calculations
Add protections against infinite loop in bezier calculations