Skip to content

[Bug]: split_bezier_intersecting_with_closedpath fails to return #27753

Closed

Description

@setrofim

Bug summary

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.

Code for reproduction

from matplotlib.patches import inside_circle, split_bezier_intersecting_with_closedpath

arrow_path = [(96950809781500.0, 804.7503795623779), (96950809781500.0, 859.6242585800646), (96950809781500.0, 914.4981375977513)]
in_f = inside_circle(96950809781500.0, 804.7503795623779, 0.06)
split_bezier_intersecting_with_closedpath(arrow_path, in_f)

Actual outcome

The call to split_bezier_intersecting_with_closedpath never returns.

Expected outcome

The call to split_bezier_intersecting_with_closedpath should return the split segment.

Additional information

No response

Operating system

confirmed on Arch and Ubuntu 22.04 LTS

Matplotlib Version

3.8.2

Matplotlib Backend

agg

Python version

3.11.6 (Arch) and 3.10.12 (Ubuntu)

Jupyter version

4.0.11 (note: reproducible outside jupyter)

Installation

None

Activity

  1. ksunden commented on Feb 7, 2024

    @ksunden
    Member

    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.

  2. setrofim commented on Feb 7, 2024

    @setrofim
    Author

    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?

  3. added a commit that references this issue on Feb 7, 2024
    86790e6
  4. added a commit that references this issue on Mar 8, 2024
    7c2aa49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions