这会检查某些点是否在矩形内,并且无论何时运行它都会大大降低我的程序速度。我们如何改变它以提高效率?
def draw_grid(self, box):
for element in self.map_layout.all_map_objects:
if element not in self.build_grid and box.area.collidepoint(element.checkpoint):
self.build_grid.append(element)
elif not box.area.collidepoint(element.checkpoint):
if element in self.build_grid:
self.build_grid.remove(element)