-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRectangle.py
More file actions
34 lines (25 loc) · 852 Bytes
/
Rectangle.py
File metadata and controls
34 lines (25 loc) · 852 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
from src_08.Parallelogram import Parallelogram
from typing import *
from PyQt5.QtCore import QPoint, QLineF
class Rectangle(Parallelogram):
def __init__(self, points: List[QPoint]):
super().__init__(points)
a, b, c, d = [x.length() for x in self.edges]
if a != c or b != d:
raise Exception('Opposite sides are not equal')
def area(self) -> float:
a, b = [x.length() for x in self.edges[0:2]]
return a*b
def perimeter(self) -> float:
a, b = [x.length() for x in self.edges[0:2]]
return 2*a + 2*b
if __name__ == "__main__":
points = [
QPoint( 0, 0),
QPoint( 0, 30),
QPoint(40, 30),
QPoint(40, 0),
]
a = Rectangle(points)
print('Периметр: ', a.perimeter())
print('Площадь: ', a.area())