From 3d82004e582bc34532b5e633d71f3a7dfad7d26e Mon Sep 17 00:00:00 2001 From: Maayan Matsliah Date: Mon, 4 May 2026 14:31:08 -0400 Subject: [PATCH] refactor: vectorize rotate_vectors, remove per-vertex loop --- polygon_packer.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/polygon_packer.py b/polygon_packer.py index eeb3e7f..6c30b6b 100644 --- a/polygon_packer.py +++ b/polygon_packer.py @@ -44,15 +44,11 @@ def transform_polygon(x, y, a, vertices): @njit(cache=True) def rotate_vectors(a, vectors): - n_vectors = vectors.shape[0] - rotated = np.empty_like(vectors) sina = np.sin(a) cosa = np.cos(a) - for i in range(n_vectors): - vecx = vectors[i, 0] - vecy = vectors[i, 1] - rotated[i, 0] = vecx * cosa - vecy * sina - rotated[i, 1] = vecx * sina + vecy * cosa + rotated = np.empty_like(vectors) + rotated[:, 0] = vectors[:, 0] * cosa - vectors[:, 1] * sina + rotated[:, 1] = vectors[:, 0] * sina + vectors[:, 1] * cosa return rotated @njit(cache=True)