-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshapes.py
More file actions
42 lines (30 loc) · 982 Bytes
/
shapes.py
File metadata and controls
42 lines (30 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
"""
Geometric shapes that can be used as obstacles.
N.B.:
- Must closely follow `matplotlib.patches` API.
- Must have all of, and only the attributes of corresponding `matplotlib.patches`.
"""
class Body:
def get_attrs(self) -> list:
return [value for value in self.__dict__.values() if not callable(value)]
class Circle(Body):
radius: float
def __init__(self, radius: float) -> None:
super().__init__()
self.radius = radius
def __str__(self) -> str:
return f"Circle(r={self.radius})"
def __repr__(self) -> str:
return self.__str__()
class Rectangle(Body):
width: float
height: float
def __init__(self, width: float, height: float) -> None:
super().__init__()
self.width = width
self.height = height
return
def __str__(self) -> str:
return f"Rectangle(w={self.width}),h={self.height}"
def __repr__(self) -> str:
return self.__str__()