From 65a45fe817f23c2ea47490a209e31bc0858b3a86 Mon Sep 17 00:00:00 2001 From: Kaushik Gunasekaren Date: Thu, 12 Nov 2026 10:48:00 -0700 Subject: [PATCH 1/2] Preserve all values when copying spatial vector sequences --- spatialmath/spatialvector.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spatialmath/spatialvector.py b/spatialmath/spatialvector.py index 52a2641c..a8758295 100644 --- a/spatialmath/spatialvector.py +++ b/spatialmath/spatialvector.py @@ -100,7 +100,7 @@ def __init__(self, value): elif base.isvector(value, 3): self.data = [np.r_[value, 0, 0, 0]] elif isinstance(value, SpatialVector): - self.data = [value.A] + self.data = list(value.data) elif base.ismatrix(value, (6, None)): self.data = [x for x in value.T] elif not super().arghandler(value): From 369ecc0e316562e066fad17aed798abbfc49eaa7 Mon Sep 17 00:00:00 2001 From: Kaushik Gunasekaren Date: Thu, 12 Nov 2026 10:48:36 -0700 Subject: [PATCH 2/2] Implement tests for copy constructor behavior --- tests/test_spatialvector.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_spatialvector.py b/tests/test_spatialvector.py index 18c81c42..7766c738 100644 --- a/tests/test_spatialvector.py +++ b/tests/test_spatialvector.py @@ -6,6 +6,30 @@ class TestSpatialVector(unittest.TestCase): + def test_copy_constructor_preserves_sequence(self): + classes = (SpatialVelocity, SpatialAcceleration, SpatialForce, SpatialMomentum) + for cls in classes: + for count in (0, 1, 2, 4): + with self.subTest(cls=cls.__name__, count=count): + values = np.arange(6 * count, dtype=float).reshape(6, count) + original = cls(values[:, 0] if count == 1 else values) + copied = cls(original) + self.assertEqual(len(copied), count) + self.assertEqual(copied.shape, (6,)) + for i in range(count): + nt.assert_array_equal(copied[i].A, values[:, i]) + self.assertEqual(str(copied), str(original)) + copied.append(cls(np.ones(6))) + self.assertEqual(len(original), count) + self.assertEqual(len(copied), count + 1) + + def test_copy_constructor_cross_subclass(self): + original = SpatialVelocity(np.arange(18).reshape(6, 3)) + copied = SpatialAcceleration(original) + self.assertEqual(len(copied), 3) + for i in range(3): + nt.assert_array_equal(copied[i].A, original[i].A) + def test_list_powers(self): x = SpatialVelocity.Empty() self.assertEqual(len(x), 0)