From 7c7a7e916c09e4076c07d10cbd9c56e153d01c46 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 14 Oct 2024 17:24:49 -0700 Subject: [PATCH 1/2] Fix offset handling in polygon normalized_form() --- masque/shapes/polygon.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index 1e0352f..1f72ea2 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -379,8 +379,9 @@ class Polygon(Shape): def normalized_form(self, norm_value: float) -> normalized_shape_tuple: # Note: this function is going to be pretty slow for many-vertexed polygons, relative to # other shapes - offset = self.vertices.mean(axis=0) + self.offset - zeroed_vertices = self.vertices - offset + meanv = self.vertices.mean(axis=0) + zeroed_vertices = self.vertices - meanv + offset = meanv + self.offset scale = zeroed_vertices.std() normed_vertices = zeroed_vertices / scale From 94a1b3d7937f8ffdfc83f7614c98dcb420ce3cb8 Mon Sep 17 00:00:00 2001 From: jan Date: Mon, 14 Oct 2024 17:25:01 -0700 Subject: [PATCH 2/2] cleanup comment --- masque/shapes/polygon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index 1f72ea2..cbcbe63 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -20,7 +20,7 @@ class Polygon(Shape): A polygon, consisting of a bunch of vertices (Nx2 ndarray) which specify an implicitly-closed boundary, and an offset. - Note that the setter for `Polygon.vertices` may creates a copy of the + Note that the setter for `Polygon.vertices` creates a copy of the passed vertex coordinates. A `normalized_form(...)` is available, but can be quite slow with lots of vertices.