prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Vispy Linux Error ( division by zero)
  When I try to tun the vispy on linux I get the following error:
  
  ```
  from vispy.plot import Fig
  f = Fig()
  
  /lib/python2.7/site-packages/vispy/util/dpi/_linux.pyc in <lambda>(x_px, y_px, x_mm, y_mm)
       49     from_xrandr = _get_dpi_from(
       50         'xrandr', r'(\d+)x(\d+).*?(\d+)mm x (\d+)mm',
  ---> 51         lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)
       52     if from_xrandr is not None:
       53         return from_xrandr
  ```
  
  ZeroDivisionError: float division by zero
  
  
  </issue>
  <code>
  [start of vispy/util/dpi/_linux.py]
  1 # -*- coding: utf-8 -*-
  2 # -----------------------------------------------------------------------------
  3 # Copyright (c) Vispy Development Team. All Rights Reserved.
  4 # Distributed under the (new) BSD License. See LICENSE.txt for more info.
  5 # -----------------------------------------------------------------------------
  6 
  7 import os
  8 import re
  9 from subprocess import CalledProcessError
  10 
  11 from ..logs import logger
  12 from ..wrappers import run_subprocess
  13 
  14 
  15 def _get_dpi_from(cmd, pattern, func):
  16     """Match pattern against the output of func, passing the results as
  17     floats to func.  If anything fails, return None.
  18     """
  19     try:
  20         out, _ = run_subprocess([cmd])
  21     except (OSError, CalledProcessError):
  22         pass
  23     else:
  24         match = re.search(pattern, out)
  25         if match:
  26             return func(*map(float, match.groups()))
  27 
  28 
  29 def get_dpi(raise_error=True):
  30     """Get screen DPI from the OS
  31 
  32     Parameters
  33     ----------
  34     raise_error : bool
  35         If True, raise an error if DPI could not be determined.
  36 
  37     Returns
  38     -------
  39     dpi : float
  40         Dots per inch of the primary screen.
  41     """
  42     # If we are running without an X server (e.g. OSMesa), use a fixed DPI
  43     if 'DISPLAY' not in os.environ:
  44         return 96.
  45 
  46     from_xdpyinfo = _get_dpi_from(
  47         'xdpyinfo', r'(\d+)x(\d+) dots per inch',
  48         lambda x_dpi, y_dpi: (x_dpi + y_dpi) / 2)
  49     if from_xdpyinfo is not None:
  50         return from_xdpyinfo
  51 
  52     from_xrandr = _get_dpi_from(
  53         'xrandr', r'(\d+)x(\d+).*?(\d+)mm x (\d+)mm',
  54         lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)
  55     if from_xrandr is not None:
  56         return from_xrandr
  57     if raise_error:
  58         raise RuntimeError('could not determine DPI')
  59     else:
  60         logger.warning('could not determine DPI')
  61     return 96
  62
  [end of vispy/util/dpi/_linux.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/vispy/util/dpi/_linux.py b/vispy/util/dpi/_linux.py
  --- a/vispy/util/dpi/_linux.py
  +++ b/vispy/util/dpi/_linux.py
  @@ -26,6 +26,14 @@
               return func(*map(float, match.groups()))
   
   
  +def _xrandr_calc(x_px, y_px, x_mm, y_mm):
  +    if x_mm == 0 or y_mm == 0:
  +        logger.warning("'xrandr' output has screen dimension of 0mm, " +
  +                       "can't compute proper DPI")
  +        return 96.
  +    return 25.4 * (x_px / x_mm + y_px / y_mm) / 2
  +
  +
   def get_dpi(raise_error=True):
       """Get screen DPI from the OS
   
  @@ -51,7 +59,7 @@
   
       from_xrandr = _get_dpi_from(
           'xrandr', r'(\d+)x(\d+).*?(\d+)mm x (\d+)mm',
  -        lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)
  +        _xrandr_calc)
       if from_xrandr is not None:
           return from_xrandr
       if raise_error:
  
verification_info: {"golden_diff": "diff --git a/vispy/util/dpi/_linux.py b/vispy/util/dpi/_linux.py\n--- a/vispy/util/dpi/_linux.py\n+++ b/vispy/util/dpi/_linux.py\n@@ -26,6 +26,14 @@\n             return func(*map(float, match.groups()))\n \n \n+def _xrandr_calc(x_px, y_px, x_mm, y_mm):\n+    if x_mm == 0 or y_mm == 0:\n+        logger.warning(\"'xrandr' output has screen dimension of 0mm, \" +\n+                       \"can't compute proper DPI\")\n+        return 96.\n+    return 25.4 * (x_px / x_mm + y_px / y_mm) / 2\n+\n+\n def get_dpi(raise_error=True):\n     \"\"\"Get screen DPI from the OS\n \n@@ -51,7 +59,7 @@\n \n     from_xrandr = _get_dpi_from(\n         'xrandr', r'(\\d+)x(\\d+).*?(\\d+)mm x (\\d+)mm',\n-        lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)\n+        _xrandr_calc)\n     if from_xrandr is not None:\n         return from_xrandr\n     if raise_error:\n", "issue": "Vispy Linux Error ( division by zero)\nWhen I try to tun the vispy on linux I get the following error:\n\n```\nfrom vispy.plot import Fig\nf = Fig()\n\n/lib/python2.7/site-packages/vispy/util/dpi/_linux.pyc in <lambda>(x_px, y_px, x_mm, y_mm)\n     49     from_xrandr = _get_dpi_from(\n     50         'xrandr', r'(\\d+)x(\\d+).*?(\\d+)mm x (\\d+)mm',\n---> 51         lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)\n     52     if from_xrandr is not None:\n     53         return from_xrandr\n```\n\nZeroDivisionError: float division by zero\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n# -----------------------------------------------------------------------------\n# Copyright (c) Vispy Development Team. All Rights Reserved.\n# Distributed under the (new) BSD License. See LICENSE.txt for more info.\n# -----------------------------------------------------------------------------\n\nimport os\nimport re\nfrom subprocess import CalledProcessError\n\nfrom ..logs import logger\nfrom ..wrappers import run_subprocess\n\n\ndef _get_dpi_from(cmd, pattern, func):\n    \"\"\"Match pattern against the output of func, passing the results as\n    floats to func.  If anything fails, return None.\n    \"\"\"\n    try:\n        out, _ = run_subprocess([cmd])\n    except (OSError, CalledProcessError):\n        pass\n    else:\n        match = re.search(pattern, out)\n        if match:\n            return func(*map(float, match.groups()))\n\n\ndef get_dpi(raise_error=True):\n    \"\"\"Get screen DPI from the OS\n\n    Parameters\n    ----------\n    raise_error : bool\n        If True, raise an error if DPI could not be determined.\n\n    Returns\n    -------\n    dpi : float\n        Dots per inch of the primary screen.\n    \"\"\"\n    # If we are running without an X server (e.g. OSMesa), use a fixed DPI\n    if 'DISPLAY' not in os.environ:\n        return 96.\n\n    from_xdpyinfo = _get_dpi_from(\n        'xdpyinfo', r'(\\d+)x(\\d+) dots per inch',\n        lambda x_dpi, y_dpi: (x_dpi + y_dpi) / 2)\n    if from_xdpyinfo is not None:\n        return from_xdpyinfo\n\n    from_xrandr = _get_dpi_from(\n        'xrandr', r'(\\d+)x(\\d+).*?(\\d+)mm x (\\d+)mm',\n        lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)\n    if from_xrandr is not None:\n        return from_xrandr\n    if raise_error:\n        raise RuntimeError('could not determine DPI')\n    else:\n        logger.warning('could not determine DPI')\n    return 96\n", "path": "vispy/util/dpi/_linux.py"}]}