Python file param_curves.py for rendering parametric curves in Inkscape for Mac OS misses imports for "exp" and "sqrt"

Summary:

As indicated in the title, my version of Inkscape for MacOSX fails to render parametric curves using the "sqrt" and "exp" functions. If you try, you get an error message pointing to the Python file "param_curves.py" in /Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/.

This Python file indeed misses imports for "sqrt" and "exp". Also, the dictionary object returned by maths_eval() function at the beginning of the file, misses entries for "sqrt" and "exp".

Steps to reproduce:

  • open Inkscape
  • Create rectangle because this seems to be required for parametric curve rendering to work
  • Open Extensions > Render > Parametric Curves...
  • Enter following data
    • Start t-value = -3.0
    • End t-value = 3.0
    • Multiply t-range by 2*pi = FALSE
    • X-value of rectangle's left = -3.0
    • X-value of rectangle's right = 3.0
    • Y-value of rectangle's bottom = 0.0
    • Y-value of rectangle's top = 1.0
    • Samples = 300
    • Isotropic scaling = FALSE
    • X-function = t
    • Y-function = (1/sqrt(2*pi)) * exp(-pow(t, 2)/2)
    • Remove rectangle = FALSE
    • Draw axes = FALSE
    • Live preview = FALSE
    • Click "Apply"

What happened?

Parametric Curves dialog raises dialog window with following error:

Traceback (most recent call last): File "param_curves.py", line 211, in ParamCurves().run() File "/Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/inkex/base.py", line 123, in run self.save_raw(self.effect()) File "param_curves.py", line 195, in effect self.options.drawaxis)))) File "param_curves.py", line 107, in drawfunction y0 = f2(t_start) File "", line 1, in NameError: name 'sqrt' is not defined

What should have happened?

No error. The normal curve should have been drawn correctly.

Sample attachments:

See attachment which is screenshot of parametric curve dialog + error dialog

Version Info:

- Inkscape Version: 1.0 (4035a4f, 2020-05-01)
- Operating System: Mac OS Mojave
- Operating System version: 10.14.6![Screenshot_2020-06-11_at_17.47.08](/uploads/4e4261ce35b8b8630a553ce6c629437f/Screenshot_2020-06-11_at_17.47.08.png)

Quick fix

  • Open file /Applications/Inkscape.app/Contents/Resources/share/inkscape/extensions/param_curves.py

  • Add "exp" and "sqrt" to statement "from math import..."

  • Add entries for "exp" and "sqrt" to dictionary in maths_eval() function as follows:

    ...
    return eval( # pylint: disable=eval-used func, { 'pi': pi, 'sin': sin, 'cos': cos, 'tan': tan, 'sqrt': sqrt, 'exp': exp }, {})

  • Restart Inkscape and try to render normal curve again. Now it works.