Get the DPI when nonsquare DPI is tolerable
6509
def get_page_dpi(pageinfo, options):
    ""
    xres = max(
        pageinfo.xres or VECTOR_PAGE_DPI,
        options.oversample or 0,
        VECTOR_PAGE_DPI if pageinfo.has_vector else 0,
    )
    yres = max(
        pageinfo.yres or VECTOR_PAGE_DPI,
        options.oversample or 0,
        VECTOR_PAGE_DPI if pageinfo.has_vector else 0,
    )
    return (float(xres), float(yres))
588546
def get_dpi_group(dpi):
    # type: (int) -> Density
    
    if dpi in range(0, 121):
        return Density.XLOW
    elif dpi in range(121, 161):
        return Density.LOW
    elif dpi in range(161, 241):
        return Density.MEDIUM
    elif dpi in range(241, 321):
        return Density.HIGH
    elif dpi in range(321, 481):
        return Density.XHIGH
    elif dpi >= 481:
        return Density.XXHIGH

    raise AskSdkException("Unknown dpi group value: {}".format(dpi))
1086315
def pixels(self, value: float) -> 'Size':
        """"""
        raise_not_number(value)
        self.maximum = '{}px'.format(value)
        return self
1265497
def getDimensionForImage(filename, maxsize):
    """"""
    try:
        from PIL import Image
    except ImportError:
        return None
    img = Image.open(filename)
    width, height = img.size
    if width > maxsize[0] or height > maxsize[1]:
        img.thumbnail(maxsize)
        out.info("Downscaled display size from %s to %s" % ((width, height), img.size))
    return img.size
114034
def mem_ds(res, extent, srs=None, dtype=gdal.GDT_Float32):
    
    #These round down to int
    #dst_ns = int((extent[2] - extent[0])/res)
    #dst_nl = int((extent[3] - extent[1])/res)
    #This should pad by 1 pixel, but not if extent and res were calculated together to give whole int
    dst_ns = int((extent[2] - extent[0])/res + 0.99)
    dst_nl = int((extent[3] - extent[1])/res + 0.99)
    m_ds = gdal.GetDriverByName('MEM').Create('', dst_ns, dst_nl, 1, dtype)
    m_gt = [extent[0], res, 0, extent[3], 0, -res]
    m_ds.SetGeoTransform(m_gt)
    if srs is not None:
        m_ds.SetProjection(srs.ExportToWkt())
    return m_ds
244679
def finite_pixels(self):
        
        finite_px = np.where(np.isfinite(self.data))
        finite_px = np.c_[finite_px[0], finite_px[1]]
        return finite_px
260116
def pixels_to_ndc(pos, size=None):
    """"""
    pos = np.asarray(pos, dtype=np.float64)
    size = np.asarray(size, dtype=np.float64)
    pos = pos / (size / 2.) - 1
    # Flip y, because the origin in pixels is at the top left corner of the
    # window.
    pos[1] = -pos[1]
    return pos
494167
public static int convertToDip(DisplayMetrics displayMetrics, int sizeInPixels) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, sizeInPixels, displayMetrics);
    }
1203874
def _get_dst_resolution(self, dst_res=None):
        """"""
        if dst_res is None:
            dst_res = min(self._res_indices.keys())
        return dst_res
1263278
def get_as(self, key, units='pt'):
        
        dpi = 72
        size = self.element.properties.get('size', 0)
        value = self[key]

        functions = {
            'pt-lines': lambda x: x/size,
            'pt-in': lambda x: x/dpi,
            'lines-pt': lambda x: x*size,
            'lines-in': lambda x: x*size/dpi,
            'in-pt': lambda x: x*dpi,
            'in-lines': lambda x: x*dpi/size
        }

        if self['units'] != units:
            conversion = '{}-{}'.format(self['units'], units)
            try:
                value = functions[conversion](value)
            except ZeroDivisionError:
                value = 0

        return value
640786
def getEyeOutputViewport(self, eEye):
        """"""

        fn = self.function_table.getEyeOutputViewport
        pnX = c_uint32()
        pnY = c_uint32()
        pnWidth = c_uint32()
        pnHeight = c_uint32()
        fn(eEye, byref(pnX), byref(pnY), byref(pnWidth), byref(pnHeight))
        return pnX.value, pnY.value, pnWidth.value, pnHeight.value
141727
def get_neg_infinity(dtype):
    
    if issubclass(dtype.type, (np.floating, np.integer)):
        return -np.inf

    if issubclass(dtype.type, np.complexfloating):
        return -np.inf - 1j * np.inf

    return NINF
588321
def pixels(self, zoom=None):
        """"""
        meter_x, meter_y = self.meters
        pixel_x = (meter_x + ORIGIN_SHIFT) / resolution(zoom=zoom)
        pixel_y = (meter_y - ORIGIN_SHIFT) / resolution(zoom=zoom)
        return abs(round(pixel_x)), abs(round(pixel_y))
388161
def get_pixel(framebuf, x, y):
        """"""
        index = (y >> 3) * framebuf.stride + x
        offset = y & 0x07
        return (framebuf.buf[index] >> offset) & 0x01
83778
def pixel(self, x, y, size=None):
        """"""
        if (size is None):
            size = self.sz
        # Have we go to the smallest element?
        if (size <= 3):
            if (_middle(x, y)):
                return (None)
            else:
                return (0, 0, 0)
        divisor = size // 3
        if (_middle(x // divisor, y // divisor)):
            return None
        return self.pixel(x % divisor, y % divisor, divisor)
27555
function(index, includeOffset) {
			var me = this;
			if (me.isHorizontal()) {
				var innerWidth = me.width - (me.paddingLeft + me.paddingRight);
				var tickWidth = innerWidth / Math.max((me.ticks.length - ((me.options.gridLines.offsetGridLines) ? 0 : 1)), 1);
				var pixel = (tickWidth * index) + me.paddingLeft;

				if (includeOffset) {
					pixel += tickWidth / 2;
				}

				var finalVal = me.left + Math.round(pixel);
				finalVal += me.isFullWidth() ? me.margins.left : 0;
				return finalVal;
			}
			var innerHeight = me.height - (me.paddingTop + me.paddingBottom);
			return me.top + (index * (innerHeight / (me.ticks.length - 1)));
		}
1080913
def checkReszie(self):
        ''''''
        if not self.resized:
            oldypx = self.ypx
            oldxpx = self.xpx
            self.ypx = self.figure.get_size_inches()[1]*self.figure.dpi
            self.xpx = self.figure.get_size_inches()[0]*self.figure.dpi
            if (oldypx != self.ypx) or (oldxpx != self.xpx):
                self.resized = True
            else:
                self.resized = False