(self, slice_tuple)
return yslice, xslice
Convert viewport to absolute slice tuple.
Convert viewport to absolute slice tuple.
Convert viewport to absolute slice tuple .
def _convert_slice(self, slice_tuple):
        """Convert viewport to absolute slice tuple."""
        yslice, xslice = slice_tuple
        xmin, ymin, xmax, ymax = self.get_bounds()
        if not isinstance(yslice, slice) and not isinstance(xslice, slice):
            # single pixel
            if not self.contains(xslice, yslice):
                return slice(0, 0), slice(0, 0)
            xslice, yslice = self._convert_coords(xslice, yslice)
            return yslice, xslice
        # note that integer indices are converted to slices n:n+1
        if not isinstance(yslice, slice):
            yslice = slice(yslice, yslice+1)
        if not isinstance(xslice, slice):
            xslice = slice(xslice, xslice+1)
        assert yslice.step is None
        assert xslice.step is None
        y0, y1 = yslice.start, yslice.stop
        x0, x1 = xslice.start, xslice.stop
        if x0 is None:
            x0 = xmin
        if y0 is None:
            y0 = ymin
        if x1 is None:
            x1 = xmax
        if y1 is None:
            y1 = ymax
        # clip to bounds
        x0 = max(x0, xmin)
        y0 = max(y0, ymin)
        x1 = min(x1, xmax+1)
        y1 = min(y1, ymax+1)
        # convert top-left and bottom-right coordinates
        x0, y0 = self._convert_coords(x0, y0)
        x1, y1 = self._convert_coords(x1, y1)
        # rebuild slices
        yslice = slice(y0, y1)
        xslice = slice(x0, x1)
        return yslice, xslice
def _convert_slice ( self , slice_tuple ) : yslice , xslice = slice_tuple xmin , ymin , xmax , ymax = self . get_bounds ( ) if not isinstance ( yslice , slice ) and not isinstance ( xslice , slice ) : # single pixel if not self . contains ( xslice , yslice ) : return slice ( 0 , 0 ) , slice ( 0 , 0 ) xslice , yslice = self . _convert_coords ( xslice , yslice ) return yslice , xslice # note that integer indices are converted to slices n:n+1 if not isinstance ( yslice , slice ) : yslice = slice ( yslice , yslice + 1 ) if not isinstance ( xslice , slice ) : xslice = slice ( xslice , xslice + 1 ) assert yslice . step is None assert xslice . step is None y0 , y1 = yslice . start , yslice . stop x0 , x1 = xslice . start , xslice . stop if x0 is None : x0 = xmin if y0 is None : y0 = ymin if x1 is None : x1 = xmax if y1 is None : y1 = ymax # clip to bounds x0 = max ( x0 , xmin ) y0 = max ( y0 , ymin ) x1 = min ( x1 , xmax + 1 ) y1 = min ( y1 , ymax + 1 ) # convert top-left and bottom-right coordinates x0 , y0 = self . _convert_coords ( x0 , y0 ) x1 , y1 = self . _convert_coords ( x1 , y1 ) # rebuild slices yslice = slice ( y0 , y1 ) xslice = slice ( x0 , x1 ) return yslice , xslice