beyondbeneath / bezier-curved-edges-networkx

Function to produce Bezier curves for the edges in a NetworkX graph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error in bezier.Curve due to verify argument

Izzy-Newsham opened this issue · comments

Hi,

Thanks for publishing this useful code!

The issue

When I run this code, I get the following error:

Traceback (most recent call last):
  File "bezier-curved-edges-networkx/run.py", line 14, in <module>
    curves = curved_edges(G, positions)
  File "bezier-curved-edges-networkx/curved_edges.py", line 58, in curved_edges
    curveplots.append(bezier.Curve(nodes, degree=2).evaluate_multi(np.linspace(0,1,bezier_precision)).T)
  File "/lib/python3.9/site-packages/bezier/curve.py", line 101, in __init__
    self._verify_degree(verify)
  File "/lib/python3.9/site-packages/bezier/curve.py", line 161, in _verify_degree
    raise ValueError(msg)
ValueError: A degree 2 curve should have 3 nodes, not 4.

The potential fix

It looks like this is due to a release of the bezier package adding the verify argument to the Curve constructor (this release: https://bezier.readthedocs.io/en/stable/releases/0.11.0.html).

So when I set verify=False in line 58:
curveplots.append(bezier.Curve(nodes, degree=2, verify=False).evaluate_multi(np.linspace(0,1,bezier_precision)).T)
it works!

Or instead, I can change the degree:
curveplots.append(bezier.Curve(nodes, degree=3).evaluate_multi(np.linspace(0,1,bezier_precision)).T)
and this works too.

@Izzy-Newsham Apart from your solutions, we can now use from_nodes to not bother with the degrees. The code can thus be changed like this:

curveplots.append(bezier.Curve.from_nodes(nodes).evaluate_multi(np.linspace(0,1,bezier_precision)).T)