Skip to content

Conversation

@kennyweiss
Copy link
Contributor

When loading an SVG with rounded rectangles and transforms, the Path transform function gave the following error when transforming some of the Arc paths:

TypeError: ufunc 'arctan2' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

After digging into it, some rotations generated eigenvectors with complex values rather than real values.

The fix was to use the Hermitian form (np.linalg.eigh) instead of np.linalg.eig for the eigenvector/value computations which is guaranteed to return reals. As far as I can tell, this is valid based on how the D matrix is generated as invT * Q * T.

The following SVG is (close to) a minimal reproducer:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg width="416.53091" height="506.883"
   viewBox="0 0 416.53091 506.88299"
   version="1.1"
   xmlns="http://www.w3.org/2000/svg" >
  <g transform="translate(-104.31227,-107.15344)" style="display:inline">
    <rect
       x="116.40955"
       y="202.60011"
       width="32"
       height="10"
       rx="5"
       ry="5"
       fill="#8338ec"
       transform="rotate(-8)"
       id="rect10" />
  </g>
</svg>

I added a test to ArcTest that triggers the error before the bugfix and is resolved by the bugfix.

Some rotations produced complex eigenvalues and the atan2 function
in transform(Arc,transform_matrix) expects reals.
We're computing eigenvectors/eigenvalues on real symmetric matrices
so we should use the Hermitian form (np.linalg.eigh),
which is guaranteed to return real eigenvectors/eigenvalues.
Copy link
Owner

@mathandy mathandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just the one suggestion. Thanks @kennyweiss !

Co-authored-by: Andrew Port <andyaport@gmail.com>
@mathandy mathandy merged commit c10dc67 into mathandy:master Sep 25, 2025
21 checks passed
@kennyweiss kennyweiss deleted the bugfix/path-arc-eig branch October 3, 2025 23:24
bmwiedemann pushed a commit to bmwiedemann/openSUSE that referenced this pull request Dec 5, 2025
https://build.opensuse.org/request/show/1321070
by user mia + anag_factory
- Update to 1.7.2
  * Fix for arc transforms -- use eigh instead of eig
    #gh/mathandy/svgpathtools#238
  * Fixed wrong length of flat quadratic bezier
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants