Skip to content

Commit ca58e87

Browse files
committed
adding a geometry module
1 parent 5fb6496 commit ca58e87

File tree

19 files changed

+376
-0
lines changed

19 files changed

+376
-0
lines changed

geometry/__init__.py

Whitespace-only changes.

geometry/angles/__init__.py

Whitespace-only changes.

geometry/angles/angle.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass
5+
class Angle:
6+
"""
7+
representation of an Angle in degrees (unit of measurement)
8+
"""
9+
10+
degrees: float

geometry/coordinate_plane/__init__.py

Whitespace-only changes.

geometry/lines/__init__.py

Whitespace-only changes.

geometry/shapes/__init__.py

Whitespace-only changes.

geometry/shapes/ellipses/__init__.py

Whitespace-only changes.

geometry/shapes/ellipses/circle.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import math
2+
3+
from geometry.shapes.shape_types.closed_shapes import ClosedShape
4+
5+
6+
class Circle(ClosedShape):
7+
8+
"""
9+
a structure which represents a
10+
geometrical circle on a 2D surface
11+
12+
>>> circle_one = Circle(5)
13+
>>> circle_one.get_diameter()
14+
10
15+
>>> circle_one.perimeter()
16+
31.41592653589793
17+
>>> circle_one.is_similar(None)
18+
Traceback (most recent call last):
19+
NotImplementedError: Not Implemented
20+
>>> circle_one.split()
21+
Traceback (most recent call last):
22+
NotImplementedError: Not Implemented
23+
>>> circle_one.max_parts(54)
24+
1486.0
25+
>>> circle_one.max_parts(7)
26+
29.0
27+
>>> circle_one.max_parts(22.5)
28+
265.375
29+
>>> circle_one.max_parts(-222)
30+
-1
31+
>>> circle_one.max_parts("-222")
32+
Traceback (most recent call last):
33+
TypeError: num_cuts must be a numeric value.
34+
"""
35+
36+
def __init__(self, radius):
37+
self.radius = radius
38+
self.origin = 0
39+
40+
def get_diameter(self):
41+
return self.radius * 2
42+
43+
def perimeter(self):
44+
return 2 * math.pi * self.radius
45+
46+
def area(self):
47+
return math.pi * (self.radius**2)
48+
49+
def is_similar(self, compared_shape):
50+
raise NotImplementedError("Not Implemented")
51+
52+
def split(self):
53+
raise NotImplementedError("Not Implemented")
54+
55+
def max_parts(self, num_cuts: float) -> float:
56+
"""
57+
returns the maximum amount of
58+
parts a circle can be divided
59+
by if cut 'num_cuts' times
60+
"""
61+
62+
if not isinstance(num_cuts, (int, float)):
63+
raise TypeError("num_cuts must be a numeric value.")
64+
return ((num_cuts + 2 + num_cuts**2) * 0.5) if num_cuts >= 0 else -1

geometry/shapes/ellipses/ellipse.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import math
2+
3+
from geometry.shapes.shape_types.closed_shapes import ClosedShape
4+
5+
6+
class Ellipse(ClosedShape):
7+
8+
"""
9+
a structure which represents a
10+
geometrical ellipse on a 2D surface
11+
12+
>>> ellipse_one = Ellipse(5, 10)
13+
>>> ellipse_one.perimeter()
14+
47.12388980384689
15+
>>> ellipse_one.is_similar(None)
16+
Traceback (most recent call last):
17+
NotImplementedError: Not Implemented
18+
>>> ellipse_one.split()
19+
Traceback (most recent call last):
20+
NotImplementedError: Not Implemented
21+
"""
22+
23+
def __init__(self, major_radius, minor_radius):
24+
self.major_radius: float = major_radius
25+
self.minor_radius: float = minor_radius
26+
27+
def perimeter(self):
28+
return math.pi * (self.major_radius + self.minor_radius)
29+
30+
def area(self):
31+
return math.pi * self.major_radius * self.minor_radius
32+
33+
def is_similar(self, compared_shape):
34+
raise NotImplementedError("Not Implemented")
35+
36+
def split(self):
37+
raise NotImplementedError("Not Implemented")

geometry/shapes/polygon/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)