[docs]classRegularTicks(collections.abc.Sequence):""" Regular ticks of equal spacing until a limit is reached, at which point the sequence terminates at that limit. This is intended for use as grid boundaries in :py:class:`~delayedarray.Grid.SimpleGrid`, where the last element of the boundary sequence needs to be equal to the grid extent. (We do not use :py:class:`~range` as it may omit the last element if the extent is not a multiple of the spacing.) """
[docs]def__init__(self,spacing:int,final:int):""" Args: spacing: Positive integer specifying the spacing between ticks. final: Position of the final tick, should be non-negative. """ifspacing<=0:raiseValueError("spacing should be positive")iffinal<0:raiseValueError("final should be positive")self._spacing=spacingself._final=finalself._len=(final//spacing)+(final%spacing>0)
[docs]def__len__(self)->int:""" Returns: Length of the tick sequence. """returnself._len
[docs]def__getitem__(self,i:int)->int:""" Args: i: Index of the tick of interest. Returns: Position of tick ``i``. """ifi<0:i+=self._lenifi<0:raiseIndexError("'i' is out of range")elifi>=self._len:raiseIndexError("'i' is out of range")returnmin(self._final,self._spacing*(i+1))
@propertydefspacing(self)->int:""" Returns: The spacing between ticks. """returnself._spacing@propertydeffinal(self)->int:""" Returns: Position of the final tick. """returnself._final