f | class Square: | f | class Square: |
| __match_args__ = ('x', 'y', 'w') | | __match_args__ = ('x', 'y', 'w') |
| | | |
n | def __init__(self, x_coord, y_coord, side): | n | def __init__(self, x, y, w): |
| self._position = (x_coord, y_coord) | | self._coordinates = (x, y) |
| self._length = side | | self._side_length = w |
| | | |
| @property | | @property |
| def y(self): | | def y(self): |
n | return self._position[1] | n | return self._coordinates[1] |
| | | |
| @y.setter | | @y.setter |
n | def y(self, new_y): | n | def y(self, value): |
| self._position = (self._position[0], new_y) | | self._coordinates = (self._coordinates[0], value) |
| | | |
| @property | | @property |
| def x(self): | | def x(self): |
n | return self._position[0] | n | return self._coordinates[0] |
| | | |
| @x.setter | | @x.setter |
n | def x(self, new_x): | n | def x(self, value): |
| self._position = (new_x, self._position[1]) | | self._coordinates = (value, self._coordinates[1]) |
| | | |
| @property | | @property |
| def w(self): | | def w(self): |
n | return self._length | n | return self._side_length |
| | | |
| @w.setter | | @w.setter |
n | def w(self, new_length): | n | def w(self, value): |
| self._length = new_length | | self._side_length = value |
| | | |
| @property | | @property |
| def h(self): | | def h(self): |
n | return self._length | n | return self._side_length |
| | | |
| @h.setter | | @h.setter |
n | def h(self, new_length): | n | def h(self, value): |
| self._length = new_length | | self._side_length = value |
| | | |
| @property | | @property |
| def s(self): | | def s(self): |
n | return self._length ** 2 | n | return self._side_length ** 2 |
| | | |
| @s.setter | | @s.setter |
n | def s(self, _): | n | def s(self, value): |
| pass | | pass |
| | | |
| @property | | @property |
| def center(self): | | def center(self): |
n | x_coord, y_coord = self._position | n | x, y = self._coordinates |
| return (x_coord + self._length / 2, y_coord + self._length / 2) | | return (x + self._side_length / 2, y + self._side_length / 2) |
| | | |
| @center.setter | | @center.setter |
n | def center(self, new_center): | n | def center(self, value): |
| if isinstance(new_center, tuple) and len(new_center) == 2: | | if isinstance(value, tuple) and len(value) == 2: |
| new_x, new_y = new_center | | cx, cy = value |
| else: | | else: |
n | new_x, new_y, offset_x, offset_y = new_center | n | cx, cy, dx, dy = value |
| new_x, new_y = (new_x + offset_x, new_y + offset_y) | | cx, cy = (cx + dx, cy + dy) |
| current_center = self.center | | current_center = self.center |
t | x_shift = new_x - current_center[0] | t | dx_shift = cx - current_center[0] |
| y_shift = new_y - current_center[1] | | dy_shift = cy - current_center[1] |
| self._position = (self._position[0] + x_shift, self._position[1] | | self._coordinates = (self._coordinates[0] + dx_shift, self._coor |
| + y_shift) | | dinates[1] + dy_shift) |