code: def distance_to(self, *args):
          
          if not len(args) > 0:
              raise ValueError("at least one parameter must be given")
  
          x = args[0]
          if len(args) > 1:
              unit = args[1]
          else:
              unit = "px"
          u = {"px": (1.,1.), "in": (1.,72.), "cm": (2.54, 72.),
               "mm": (25.4, 72.)}
          f = u[unit][0] / u[unit][1]
          if type(x) is Point:
              return abs(self - x) * f
  
  # from here on, x is a rectangle
  # as a safeguard, make a finite copy of it
          r = Rect(x.top_left, x.top_left)
          r = r | x.bottom_right
          if self in r:
              return 0.0
          if self.x > r.x1:
              if self.y >= r.y1:
                  return self.distance_to(r.bottom_right, unit)
              elif self.y <= r.y0:
                  return self.distance_to(r.top_right, unit)
              else:
                  return (self.x - r.x1) * f
          elif r.x0 <= self.x <= r.x1:
              if self.y >= r.y1:
                  return (self.y - r.y1) * f
              else:
                  return (r.y0 - self.y) * f
          else:
              if self.y >= r.y1:
                  return self.distance_to(r.bottom_left, unit)
              elif self.y <= r.y0:
                  return self.distance_to(r.top_left, unit)
              else:
                  return (r.x0 - self.x) * f
docs: Return the distance to a rectangle or another point.