def get_closest_region(self, pt):
""" Returns the start and end of the closest region, and whether the region contains the point
"""
containining_region = self.get_region_containing_point(pt)
if not(containining_region is None):
(start, end) = containining_region
return (start, end, True)
right_index = bisect.bisect(self.starts, pt)
left_index = right_index - 1
if right_index == 0:
return (self.starts[right_index], self.ends[right_index], False)
elif right_index == len(self.starts):
return (self.starts[left_index], self.ends[left_index], False)
else:
left_dist = pt - self.ends[left_index]
right_dist = self.starts[right_index] - pt
if left_dist < right_dist:
return (self.starts[left_index], self.ends[left_index], False)
else:
return (self.starts[right_index], self.ends[right_index], False)
评论列表
文章目录