From af509bf17fa12c2f673738ec0995df20fd1b3efb Mon Sep 17 00:00:00 2001 From: robrui <128964181+robrui@users.noreply.github.com> Date: Fri, 15 May 2026 03:28:50 +0000 Subject: [PATCH] spiral_2D_array now uses the center parameter --- CHANGELOG.rst | 5 ++++- pyroomacoustics/beamforming.py | 2 +- tests/test_issue_413.py | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 tests/test_issue_413.py diff --git a/CHANGELOG.rst b/CHANGELOG.rst index ae73d7e2..ea7a0efe 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -11,7 +11,10 @@ adheres to `Semantic Versioning `_. `Unreleased`_ ------------- -Nothing yet. +Fixed +~~~~~ + +- `spiral_2D_array` now correctly uses the ``center`` parameter. Previously, it always returned the array at the origin. (`#413 `_). `0.10.1`_ - 2026-05-01 diff --git a/pyroomacoustics/beamforming.py b/pyroomacoustics/beamforming.py index 817379b2..2ecfb9a9 100644 --- a/pyroomacoustics/beamforming.py +++ b/pyroomacoustics/beamforming.py @@ -242,7 +242,7 @@ def spiral_2D_array(center, M, radius=1.0, divi=3, angle=None): pos_mic_x = pos_array_norm * np.cos(pos_array_angle) pos_mic_y = pos_array_norm * np.sin(pos_array_angle) - return np.array([pos_mic_x, pos_mic_y]) + return np.array(center)[:, np.newaxis] + np.array([pos_mic_x, pos_mic_y]) def fir_approximation_ls(weights, T, n1, n2): diff --git a/tests/test_issue_413.py b/tests/test_issue_413.py new file mode 100644 index 00000000..e82aeb4e --- /dev/null +++ b/tests/test_issue_413.py @@ -0,0 +1,29 @@ +import numpy as np + +import pyroomacoustics as pra + + +def test_spiral_2d_array_center(): + """Test that spiral_2D_array correctly uses the center parameter.""" + + # Test with fixed angle to avoid random variance + angle = 0.3 + + # Array at origin + arr0 = pra.spiral_2D_array([0, 0], 10, radius=1.0, divi=3, angle=angle) + + # Same array shifted + center = np.array([2.5, -1.5]) + arr_shifted = pra.spiral_2D_array(center, 10, radius=1.0, divi=3, angle=angle) + + # Every point should be shifted by exactly the center offset + np.testing.assert_allclose(arr_shifted[0] - arr0[0], center[0]) + np.testing.assert_allclose(arr_shifted[1] - arr0[1], center[1]) + + # Test single point (M=1) — should be at center + arr_single = pra.spiral_2D_array([5.0, -3.0], 1, radius=2.0, angle=0.0) + np.testing.assert_allclose(arr_single.ravel(), [5.0, -3.0]) + + # Test that center as list also works + arr_list = pra.spiral_2D_array([1.0, 2.0], 4, radius=0.5, divi=2, angle=0.0) + assert arr_list.shape == (2, 4)