From a713967911436c6cbd89f83c203092ec26920007 Mon Sep 17 00:00:00 2001 From: Jan Petykiewicz Date: Wed, 4 Jan 2023 22:37:26 -0800 Subject: [PATCH] Add an alternate constructor for axis-aligned 2D grids --- masque/repetition.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/masque/repetition.py b/masque/repetition.py index 6861323..13e47d9 100644 --- a/masque/repetition.py +++ b/masque/repetition.py @@ -3,7 +3,7 @@ instances of an object . """ -from typing import Union, Dict, Optional, Sequence, Any +from typing import Union, Dict, Optional, Sequence, Any, Type import copy from abc import ABCMeta, abstractmethod @@ -106,6 +106,28 @@ class Grid(LockableImpl, Repetition, metaclass=AutoSlots): self.b_count = b_count self.locked = locked + @classmethod + def aligned( + cls: Type, + x: float, + y: float, + x_count: int, + y_count: int, + ) -> 'Grid': + """ + Simple constructor for an axis-aligned 2D grid + + Args: + x: X-step + y: Y-step + x_count: count of columns + y_count: count of rows + + Returns: + An Grid instance with the requested values + """ + return cls(a_vector=(x, 0), b_vector=(0, y), a_count=x_count, b_count=y_count) + def __copy__(self) -> 'Grid': new = Grid(a_vector=self.a_vector.copy(), b_vector=copy.copy(self.b_vector),