t | class Square: | t | class Square: |
| __match_args__ = ('x', 'y', 'w') | | __match_args__ = ('x', 'y', 'w') |
| | | |
| def __init__(self, x, y, w): | | def __init__(self, x, y, w): |
| self._x = x | | self._x = x |
| self._y = y | | self._y = y |
| self._w = w | | self._w = w |
| | | |
| @property | | @property |
| def x(self): | | def x(self): |
| return self._x | | return self._x |
| | | |
| @x.setter | | @x.setter |
| def x(self, value): | | def x(self, value): |
| self._x = value | | self._x = value |
| | | |
| @property | | @property |
| def y(self): | | def y(self): |
| return self._y | | return self._y |
| | | |
| @y.setter | | @y.setter |
| def y(self, value): | | def y(self, value): |
| self._y = value | | self._y = value |
| | | |
| @property | | @property |
| def w(self): | | def w(self): |
| return self._w | | return self._w |
| | | |
| @w.setter | | @w.setter |
| def w(self, value): | | def w(self, value): |
| self._w = value | | self._w = value |
| | | |
| @property | | @property |
| def h(self): | | def h(self): |
| return self._w | | return self._w |
| | | |
| @h.setter | | @h.setter |
| def h(self, value): | | def h(self, value): |
| self._w = value | | self._w = value |
| | | |
| @property | | @property |
| def s(self): | | def s(self): |
| return self._w * self._w | | return self._w * self._w |
| | | |
| @s.setter | | @s.setter |
| def s(self, value): | | def s(self, value): |
| pass | | pass |
| | | |
| @property | | @property |
| def center(self): | | def center(self): |
| cx = self._x + self._w / 2 | | cx = self._x + self._w / 2 |
| cy = self._y + self._w / 2 | | cy = self._y + self._w / 2 |
| return (cx, cy) | | return (cx, cy) |
| | | |
| @center.setter | | @center.setter |
| def center(self, value): | | def center(self, value): |
| if len(value) == 2: | | if len(value) == 2: |
| cx, cy = value | | cx, cy = value |
| else: | | else: |
| cx, cy, dx, dy = value | | cx, cy, dx, dy = value |
| cx += dx | | cx += dx |
| cy += dy | | cy += dy |
| old_cx, old_cy = self.center | | old_cx, old_cy = self.center |
| dx = cx - old_cx | | dx = cx - old_cx |
| dy = cy - old_cy | | dy = cy - old_cy |
| self._x += dx | | self._x += dx |
| self._y += dy | | self._y += dy |