From 27f4f0e86ec0421998266e6bd093169b6807ac4e Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Thu, 2 Apr 2026 19:42:39 -0700 Subject: [PATCH] [Polygon / PolyCollection] add raw constructors --- masque/shapes/poly_collection.py | 16 ++++++++++++++++ masque/shapes/polygon.py | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/masque/shapes/poly_collection.py b/masque/shapes/poly_collection.py index 6c23da7..0b5543f 100644 --- a/masque/shapes/poly_collection.py +++ b/masque/shapes/poly_collection.py @@ -119,6 +119,22 @@ class PolyCollection(Shape): if numpy.any(offset): self.translate(offset) + @classmethod + def _from_raw( + cls, + *, + vertex_lists: NDArray[numpy.float64], + vertex_offsets: NDArray[numpy.integer[Any]], + annotations: annotations_t = None, + repetition: Repetition | None = None, + ) -> Self: + new = cls.__new__(cls) + new._vertex_lists = vertex_lists + new._vertex_offsets = vertex_offsets + new._repetition = repetition + new._annotations = annotations + return new + def __deepcopy__(self, memo: dict | None = None) -> Self: memo = {} if memo is None else memo new = copy.copy(self) diff --git a/masque/shapes/polygon.py b/masque/shapes/polygon.py index a743de2..42c2f78 100644 --- a/masque/shapes/polygon.py +++ b/masque/shapes/polygon.py @@ -131,6 +131,20 @@ class Polygon(Shape): if numpy.any(offset): self.translate(offset) + @classmethod + def _from_raw( + cls, + *, + vertices: NDArray[numpy.float64], + annotations: annotations_t = None, + repetition: Repetition | None = None, + ) -> Self: + new = cls.__new__(cls) + new._vertices = vertices + new._repetition = repetition + new._annotations = annotations + return new + def __deepcopy__(self, memo: dict | None = None) -> 'Polygon': memo = {} if memo is None else memo new = copy.copy(self)