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 ** 2 | | return self._w ** 2 |
| | | |
| @s.setter | | @s.setter |
| def s(self, value): | | def s(self, value): |
| pass | | pass |
| | | |
| @property | | @property |
| def center(self): | | def center(self): |
| return (self._x + self._w / 2, self._y + self._w / 2) | | return (self._x + self._w / 2, self._y + self._w / 2) |
| | | |
| @center.setter | | @center.setter |
| def center(self, value): | | def center(self, value): |
| if isinstance(value, tuple) and len(value) == 2: | | if isinstance(value, tuple) and len(value) == 2: |
| cx, cy = value | | cx, cy = value |
| self._x = cx - self._w / 2 | | self._x = cx - self._w / 2 |
| self._y = cy - self._w / 2 | | self._y = cy - self._w / 2 |
| elif isinstance(value, tuple) and len(value) == 4: | | elif isinstance(value, tuple) and len(value) == 4: |
| cx, cy, dx, dy = value | | cx, cy, dx, dy = value |
| self._x = cx + dx - self._w / 2 | | self._x = cx + dx - self._w / 2 |
| self._y = cy + dy - self._w / 2 | | self._y = cy + dy - self._w / 2 |