summaryrefslogtreecommitdiff
path: root/interval_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'interval_utils.py')
-rw-r--r--interval_utils.py30
1 files changed, 27 insertions, 3 deletions
diff --git a/interval_utils.py b/interval_utils.py
index 0095c06..7123893 100644
--- a/interval_utils.py
+++ b/interval_utils.py
@@ -70,13 +70,37 @@ def intervals_intersect(int1_, int2_):
return False
-def check_cell_in_interval(origin, cell, interval):
+def intersection(int1s, int2s):
+ #expects merged, canonicalized intervals, returns overlap-free canonicalized intervals
+
+ result = []
+
+ for int1 in int1s:
+ for int2 in int2s:
+ if (max(int1[0],int2[0]) <= min(int1[1],int2[1])):
+ result += [(max(int1[0],int2[0]), min(int1[1],int2[1]))]
+
+ return result
+
+def interval_area(ints):
+ result = 0
+ for i in merge_intervals(ints):
+ result += i[1]-i[0]
+ return result
+
+def interval_occupied_by_cell(origin, cell):
ang = get_point_angle(origin, cell.pos)
dist = math.sqrt( (cell.pos[0]-origin[0])**2 + (cell.pos[1]-origin[1])**2 )
- corridor_halfwidth = math.asin(cell.size / dist)
+ if cell.size >= dist:
+ corridor_halfwidth = math.pi/2
+ else:
+ corridor_halfwidth = math.asin(cell.size / dist)
+
+ return (ang-corridor_halfwidth, ang+corridor_halfwidth)
- return intervals_intersect(interval, (ang-corridor_halfwidth, ang+corridor_halfwidth))
+def check_cell_in_interval(origin, cell, interval):
+ return intervals_intersect(interval, interval_occupied_by_cell(origin,cell))
def get_cells_in_interval(origin, interval, cells):
return list(filter(lambda x: check_point_in_interval(origin, x.pos, interval), cells))