svgpathtools icon indicating copy to clipboard operation
svgpathtools copied to clipboard

bug in Path.area()

Open SebKuzminsky opened this issue 7 years ago • 2 comments

I'm seeing this problem on the current tip of master, ae42197d1096fb1d78526e542db3e0a7fffe0790.

from svgpathtools.path import *
p = Path(Arc(start=(106.58928+132.95833j), radius=(40.82143+83.910713j), rotation=0.0, large_arc=False, sweep=True, end=(74.472411+214.93917j)),
     Arc(start=(74.472411+214.93917j), radius=(40.82143+83.910713j), rotation=0.0, large_arc=False, sweep=True, end=(28.658655+167.9207j)),
     Arc(start=(28.658655+167.9207j), radius=(40.82143+83.910713j), rotation=0.0, large_arc=False, sweep=True, end=(41.237335+65.887886j)),
     Line(start=(41.237335+65.887886j), end=(65.767853+132.95833j)),
     Line(start=(65.767853+132.95833j), end=(106.58928+132.95833j)))
p.area()

This hangs until I interrupt it with ^C, then I get this backtrace:

KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-4-38eb451037da> in <module>()
----> 1 p.area()

/home/seb/svg2gcode/svgpathtools/svgpathtools/path.pyc in area(self, chord_length)
   2568             else:
   2569                 bezier_path_approximation.append(seg)
-> 2570         return area_without_arcs(Path(*bezier_path_approximation))
   2571 
   2572     def intersect(self, other_curve, justonemode=False, tol=1e-12):

/home/seb/svg2gcode/svgpathtools/svgpathtools/path.pyc in area_without_arcs(path)
   2548             for seg in path:
   2549                 x = real(seg.poly())
-> 2550                 dy = imag(seg.poly()).deriv()
   2551                 integrand = x*dy
   2552                 integral = integrand.integ()

/home/seb/svg2gcode/svgpathtools/svgpathtools/polytools.pyc in imag(z)
     66 def imag(z):
     67     try:
---> 68         return np.poly1d(z.coeffs.imag)
     69     except AttributeError:
     70         return z.imag

/usr/lib/python2.7/dist-packages/numpy/lib/polynomial.pyc in __init__(self, c_or_r, r, variable)
   1054         if len(c_or_r.shape) > 1:
   1055             raise ValueError("Polynomial must be 1d only.")
-> 1056         c_or_r = trim_zeros(c_or_r, trim='f')
   1057         if len(c_or_r) == 0:
   1058             c_or_r = NX.array([0.])

/usr/lib/python2.7/dist-packages/numpy/lib/function_base.pyc in trim_zeros(filt, trim)
   2097             else:
   2098                 last = last - 1
-> 2099     return filt[first:last]
   2100 
   2101 

KeyboardInterrupt: 

SebKuzminsky avatar Dec 05 '18 16:12 SebKuzminsky

I added this test case to the list of failing Path.area() tests in this branch: https://github.com/SebKuzminsky/svgpathtools/commits/path-area-approximation-bugs

SebKuzminsky avatar Dec 05 '18 17:12 SebKuzminsky

I have the same problem with the following path: M 10.0,10.0 L 10.0,70.0 L 40.0,70.0 A 46.428571,46.428571 14.250033 0,1 130.0,70.0 L 190.0,70.0 A 46.428571,46.428571 14.250033 0,1 280.0,70.0 L 310.0,70.0 L 310.0,10.0 L 10.0,10.0

adrianschneider94 avatar Jan 23 '23 10:01 adrianschneider94