def distance_to(self, *args):
if not len(args) > <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>x = args[<NUM_LIT:0>]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>unit = args[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>unit = "<STR_LIT>"<EOL><DEDENT>u = {"<STR_LIT>": (<NUM_LIT:1.>,<NUM_LIT:1.>), "<STR_LIT>": (<NUM_LIT:1.>,<NUM_LIT>), "<STR_LIT>": (<NUM_LIT>, <NUM_LIT>),<EOL>"<STR_LIT>": (<NUM_LIT>, <NUM_LIT>)}<EOL>f = u[unit][<NUM_LIT:0>] / u[unit][<NUM_LIT:1>]<EOL>if type(x) is Point:<EOL><INDENT>return abs(self - x) * f<EOL><DEDENT>ere on, x is a rectangle<EOL>afeguard, make a finite copy of it<EOL>r = Rect(x.top_left, x.top_left)<EOL>r = r | x.bottom_right<EOL>if self in r:<EOL><INDENT>return <NUM_LIT:0.0><EOL><DEDENT>if self.x > r.x1:<EOL><INDENT>if self.y >= r.y1:<EOL><INDENT>return self.distance_to(r.bottom_right, unit)<EOL><DEDENT>elif self.y <= r.y0:<EOL><INDENT>return self.distance_to(r.top_right, unit)<EOL><DEDENT>else:<EOL><INDENT>return (self.x - r.x1) * f<EOL><DEDENT><DEDENT>elif r.x0 <= self.x <= r.x1:<EOL><INDENT>if self.y >= r.y1:<EOL><INDENT>return (self.y - r.y1) * f<EOL><DEDENT>else:<EOL><INDENT>return (r.y0 - self.y) * f<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if self.y >= r.y1:<EOL><INDENT>return self.distance_to(r.bottom_left, unit)<EOL><DEDENT>elif self.y <= r.y0:<EOL><INDENT>return self.distance_to(r.top_left, unit)<EOL><DEDENT>else:<EOL><INDENT>return (r.x0 - self.x) * f<EOL><DEDENT><DEDENT>
Return the distance to a rectangle or another point.