:tocdepth: 3 :py:mod:`gws.lib.uom` ===================== .. py:module:: gws.lib.uom **Source code:** :source:`gws.lib.uom` Package Contents ---------------- .. py:data:: DEFAULT_PRECISION .. py:data:: MM_PER_IN :value: 25.4 Conversion factor from inch to millimetre .. py:function:: mm_to_px(x: _number, ppi: int) -> float Converts millimetres to pixel. :param x: Millimetres. :param ppi: Pixels per inch. :returns: Amount of pixels. .. py:data:: OGC_M_PER_PX :value: 0.00028 1px = 0.28mm). :type: OGC meter per pixel (OGC 06-042, 7.2.4.6.9 .. py:data:: OGC_SCREEN_PPI :value: 90.71428571428572 Pixel per inch on screen using the Open Geospatial Consortium standard .. py:function:: parse(s: str | int | float, default_unit: gws.Uom = None) -> gws.UomValue Parse a measurement in the string or numeric form. :param s: A measurement to parse. :param default_unit: Default unit. :returns: A measurement. :raises ``ValueError``: if the unit is missing, if the formatting is wrong or if the unit is invalid. .. py:data:: PDF_DPI :value: 96 Dots per inch in a pdf file .. py:data:: PT_PER_IN :value: 72 Conversion factor from inch to points .. py:function:: px_to_mm(x: _number, ppi: int) -> float Converts pixel to millimetres. :param x: Amount of pixels. :param ppi: Pixel per inch. :returns: Amount of millimetres. .. py:function:: res_to_scale(x: _number) -> int Converts the user's resolution to the scale. :param x: Resolution in pixel per inch. :returns: Scale. .. py:function:: scale_to_res(x: _number) -> float Converts the scale to the user's resolution. :param x: Scale. :returns: Resolution in pixel. .. py:function:: size_mm_to_px(xy: gws.Size, ppi: int) -> gws.Size Converts a rectangle description in millimetres to pixels. :param xy: A rectangle measurements in mm. :param ppi: Pixels per inch. :returns: A rectangle in pixel. .. py:function:: size_px_to_mm(xy: gws.Size, ppi: int) -> gws.Size Converts a rectangle description in pixel to millimetres. :param xy: A rectangle measurements in pixels. :param ppi: Pixel per inch :returns: The rectangle measurements in millimetres. .. py:function:: size_to_mm(xyu: gws.UomSize, ppi: int) -> gws.UomSize Converts a rectangle description of any unit to millimetres. :param xyu: A rectangle measurements with its unit. :param ppi: Pixels per inch. :returns: The rectangle measurements in millimetres. :raises ``ValueError``: if the unit is invalid. .. py:function:: size_to_px(xyu: gws.UomSize, ppi: int) -> gws.UomSize Converts a rectangle description of any unit to pixels. :param xyu: A rectangle measurements with its unit. :param ppi: Pixels per inch. :returns: The rectangle measurements in pixels. .. py:function:: to_mm(xu: gws.UomValue, ppi: int) -> gws.UomValue Converts a measurement of any unit to millimetres. :param xu: A measurement to convert. :param ppi: Pixels per inch. :returns: A measurement. .. py:function:: to_px(xu: gws.UomValue, ppi: int) -> gws.UomValue Converts a measurement to amount of pixels. :param xu: A measurement to convert to pixels. :param ppi: Pixels per inch. :returns: A measurement. .. py:function:: to_str(xu: gws.UomValue) -> str Converts a to a string. :param xu: A measurement to convert. :returns: The input tuple as a string, like '5mm'.