-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.py
59 lines (47 loc) · 1.81 KB
/
domain.py
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from point import Point
class Domain(object):
"""Creates Class Domain."""
def __init__(self, cx=0.0, cy=0.0, length=0.0):
self._center_x = cx
self._center_y = cy
self._size = length
def from_domain(self, quadrant: int):
new_length = self.length/2
# y
if quadrant <= 1: # quadrant 0 and 1
new_cy = self.cy + new_length/2
else: # quadrant 2 and 3
new_cy = self.cy - new_length/2
# x
if quadrant % 3 == 0: # quadrant 0 and 3
new_cx = self.cx + new_length/2
else: # quadrant 1 and 2
new_cx = self.cx - new_length / 2
return Domain(new_cx, new_cy, new_length)
def subdivide(self) -> list:
domain_list = []
for x in range(4):
domain_list.append(self.from_domain(x))
return domain_list
def point_in_boundary(self, insert_point: Point):
return self.in_horizontal_bound(insert_point) and self.in_vertical_bound(insert_point)
def in_horizontal_bound(self, insert_point: Point):
left_bound = self.cx - self.length / 2
right_bound = self.cx + self.length / 2
return left_bound <= insert_point.x < right_bound
def in_vertical_bound(self, insert_point: Point):
bottom_bound = self.cy - self.length / 2
top_bound = self.cy + self.length / 2
return bottom_bound <= insert_point.y < top_bound
@property
def cx(self) -> float:
return self._center_x
@property
def cy(self) -> float:
return self._center_y
@property
def length(self) -> float:
return self._size
@property
def center(self):
return Point(self._center_x, self._center_y)