""".. The Geometry API"""from__future__importannotations__all__=("RawSize","Size")fromtyping_extensionsimportNamedTuple,Selffrom.utilsimportarg_value_error_range
[docs]classRawSize(NamedTuple):"""The dimensions of a rectangular region. Args: width: The horizontal dimension height: The vertical dimension NOTE: * A dimension may be non-positive but the validity and meaning would be determined by the receiving interface. * This is a subclass of :py:class:`tuple`. Hence, instances can be used anyway and anywhere tuples can. """width:intheight:int@classmethoddef_new(cls,width:int,height:int)->Self:"""Alternate constructor for internal use only."""returntuple.__new__(cls,(width,height))
[docs]classSize(RawSize):"""The dimensions of a rectangular region. Raises: ValueError: Either dimension is non-positive. Same as :py:class:`RawSize`, except that both dimensions must be **positive**. IMPORTANT: In the case of multiple inheritance i.e if subclassing this class along with other classes, this class should appear last (i.e to the far right) in the base class list. """__slots__=()def__new__(cls,width:int,height:int)->Self:ifwidth<1:raisearg_value_error_range("width",width)ifheight<1:raisearg_value_error_range("height",height)# Using `tuple` directly instead of `super()` for performancereturntuple.__new__(cls,(width,height))