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): |
| half_w = self._w / 2 | | half_w = self._w / 2 |
| return (self._x + half_w, self._y + half_w) | | return (self._x + half_w, self._y + half_w) |
| | | |
| @center.setter | | @center.setter |
| def center(self, center): | | def center(self, center): |
| x, y = center[:2] | | x, y = center[:2] |
| half_w = self._w / 2 | | half_w = self._w / 2 |
| if len(center) > 2: | | if len(center) > 2: |
| x, y = (x + center[2], y + center[3]) | | x, y = (x + center[2], y + center[3]) |
| self._x, self._y = (x - half_w, y - half_w) | | self._x, self._y = (x - half_w, y - half_w) |
| | | |
| def __str__(self): | | def __str__(self): |
| return '{}:{}×{}'.format(self._x, self._y, self._w) | | return '{}:{}×{}'.format(self._x, self._y, self._w) |