From 7c3d7209e2ca21d84139ba0bda0ad7770981a58b Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Wed, 11 Jun 2025 22:41:40 +0200 Subject: [PATCH] Provide __array_interface__ implementation on ImmutableVector2D --- inkex/transforms.py | 9 +++++++++ tests/test_inkex_transforms.py | 2 -- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/inkex/transforms.py b/inkex/transforms.py index ec2a3d268..9a35a77d6 100644 --- a/inkex/transforms.py +++ b/inkex/transforms.py @@ -42,6 +42,8 @@ from typing import ( ) import cmath +import numpy as np + from .utils import strargs, KeyDict @@ -83,6 +85,13 @@ class ImmutableVector2d: x = property(lambda self: self._x) y = property(lambda self: self._y) + @property + def __array_interface__(self): + z = complex(self) + # Allocate a NumPy scalar just to get the memory buffer + arr = np.array([z], dtype=np.complex128) + return {"shape": (), "typestr": arr.dtype.str, "data": (arr.ctypes.data, False)} + @overload def __init__(self): pass diff --git a/tests/test_inkex_transforms.py b/tests/test_inkex_transforms.py index 5965f5d93..35844edad 100644 --- a/tests/test_inkex_transforms.py +++ b/tests/test_inkex_transforms.py @@ -22,7 +22,6 @@ from inkex.tester import TestCase class ImmutableVector2dTest(TestCase): """Test the ImmutableVector2d object""" - @pytest.mark.xfail def test_numpy_conversion(self): """Check that vectors work fine in numpy datatypes (they are complex under the hood)""" @@ -796,7 +795,6 @@ class ExtremaTest(TestCase): self.assertAlmostEqual(cmin, a, delta=1e-6) self.assertAlmostEqual(cmax, a, delta=1e-6) - @pytest.mark.xfail def test_numpy_conversion(self): """Conversion to numpy""" -- GitLab