dhermes / bezier

Helper for Bézier Curves, Triangles, and Higher Order Objects
Apache License 2.0
262 stars 36 forks source link

Algebraic intersection fails curves 1 and 13 (ID: 10) in PyPy #33

Open dhermes opened 7 years ago

dhermes commented 7 years ago

We have the curves

>>> import numpy as np
>>>
>>> nodes1 = np.asfortranarray([
...     [0.0, 0.0],
...     [0.5, 1.0],
...     [1.0, 0.0],
... ])
>>> nodes13 = np.asfortranarray([
...     [0.0 ,  0.0],
...     [0.25,  2.0],
...     [0.5 , -2.0],
...     [0.75,  2.0],
...     [1.0 ,  0.0]
... ])

Visual inspection shows 4 intersections:

>>> import matplotlib.pyplot as plt
>>> import seaborn
>>>
>>> import bezier
>>>
>>> seaborn.set()
>>>
>>> curve1 = bezier.Curve.from_nodes(nodes1, _copy=False)
>>> curve13 = bezier.Curve.from_nodes(nodes13, _copy=False)
>>>
>>> ax = curve1.plot(256)
>>> _ = curve13.plot(256, ax=ax)
>>> _ = ax.axis('scaled')
>>> ax.figure.show()

figure_1


When using CPython (2.7 here, but any version works) there are 4 intersections as expected

Python 2.7.13 (default, Jan  5 2017, 18:58:25) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from bezier._intersection_helpers import all_intersections
>>> from bezier._intersection_helpers import IntersectionStrategy
>>>
>>> candidates = [(curve1, curve13)]
>>>
>>> intersections = all_intersections(
...     candidates, strategy=IntersectionStrategy.algebraic)
>>> for intersection in intersections:
...     print((intersection.s, intersection.t))
... 
(0.0, 0.0)
(0.3110177634953864, 0.3110177634953864)
(0.68898223650461365, 0.68898223650461365)
(1.0, 1.0)

However, using PyPy there are only 3

Python 2.7.12 (aff251e543859ce4508159dd9f1a82a2f553de00, Nov 12 2016, 08:50:18)
[PyPy 5.6.0 with GCC 6.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>> # imports, set-up of curve1 and curve13, etc.
>>>> intersections = all_intersections(
....     candidates, strategy=IntersectionStrategy.algebraic)
>>>> for intersection in intersections:
....     print((intersection.s, intersection.t))
....
(0.0, 0.0)
(0.31101776349538629, 0.31101776349538635)
(1.0, 1.0)

$ git log -1 --pretty=%H
ccfd43f0b594188d26df0910fe1c46827048435c
dhermes commented 7 years ago

Added a switch for this in 2fd702daa29468d49aaf6b49ce0ec1e66830f40d.