def __init__(self, *args): if len(args) == 4: l,t,r,b = args elif len(args) == 2: if hasattr(args[0], "__int__"): l,t = 0,0 r,b = args[0], args[1] l,t = xy.extract(args[0]) r,b = xy.extract(args[1]) elif len(args) == 1: other = args[0] if hasattr(other, "ltrb"): l,t,r,b = other.ltrb() elif hasattr(other, 'left'): l,t,r,b = (other.left(), other.top(), other.right(), other.bottom()) else: self.__init__(*other) return else: l,t, r,b = 0,0, 20,20 self.left_, self.top_, self.right_, self.bottom_ = l,t,r,b self.fill_color = (255, 255, 255) self.border_color = (0,0,0)
def set2(self, attr_name, *args): attrs_to_funcs = {"top_left":[self.set_left, self.set_top], "bottom_right":[self.set_right, self.set_bottom], "center":[self.set_x_center, self.set_y_center], "move":[lambda x:self.set_left(self.left() + x), lambda y:self.set_top(self.top() + y)]} x_func, y_func = attrs_to_funcs[attr_name] x_val, y_val = xy.extract(*args) x_func(x_val) y_func(y_val) return self
def square_dist(p1, p2): x1, y1 = xy.extract(p1) x2, y2 = xy.extract(p2) val = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2) return abs(val)
def is_point_in(self, *args): x,y = xy.extract(*args) return (x > self.left() and x < self.right() and y > self.top() and y < self.bottom())