| 496 | return np.rad2deg(math.atan2(next_pos.y - pos.y, next_pos.x - pos.x)) |
| 497 | |
| 498 | class SidewalkAgentPath: |
| 499 | def __init__(self, route_points, route_orientations, min_points, interval): |
| 500 | self.min_points = min_points |
| 501 | self.interval = interval |
| 502 | self.route_points = route_points |
| 503 | self.route_orientations = route_orientations |
| 504 | |
| 505 | @staticmethod |
| 506 | def rand_path(sidewalk, min_points, interval, cross_probability, segment_map, rng=None): |
| 507 | if rng is None: |
| 508 | rng = random |
| 509 | |
| 510 | spawn_point = sidewalk.get_nearest_route_point(segment_map.rand_point()) |
| 511 | |
| 512 | path = SidewalkAgentPath([spawn_point], [rng.choice([True, False])], min_points, interval) |
| 513 | path.resize(sidewalk, cross_probability) |
| 514 | return path |
| 515 | |
| 516 | def resize(self, sidewalk, cross_probability, rng=None): |
| 517 | if rng is None: |
| 518 | rng = random |
| 519 | |
| 520 | while len(self.route_points) < self.min_points: |
| 521 | if rng.random() <= cross_probability: |
| 522 | adjacent_route_point = sidewalk.get_adjacent_route_point(self.route_points[-1], 50.0) |
| 523 | if adjacent_route_point is not None: |
| 524 | self.route_points.append(adjacent_route_point) |
| 525 | self.route_orientations.append(rng.randint(0, 1) == 1) |
| 526 | continue |
| 527 | |
| 528 | if self.route_orientations[-1]: |
| 529 | self.route_points.append( |
| 530 | sidewalk.get_next_route_point(self.route_points[-1], self.interval)) |
| 531 | self.route_orientations.append(True) |
| 532 | else: |
| 533 | self.route_points.append( |
| 534 | sidewalk.get_previous_route_point(self.route_points[-1], self.interval)) |
| 535 | self.route_orientations.append(False) |
| 536 | |
| 537 | return True |
| 538 | |
| 539 | def cut(self, sidewalk, position): |
| 540 | cut_index = 0 |
| 541 | min_offset = None |
| 542 | min_offset_index = None |
| 543 | for i in range(int(len(self.route_points) / 2)): |
| 544 | route_point = self.route_points[i] |
| 545 | offset = position - sidewalk.get_route_point_position(route_point) |
| 546 | offset = offset.length() |
| 547 | if min_offset is None or offset < min_offset: |
| 548 | min_offset = offset |
| 549 | min_offset_index = i |
| 550 | if offset <= 1.0: |
| 551 | cut_index = i + 1 |
| 552 | |
| 553 | # Invalid path because too far away. |
| 554 | if min_offset > 1.0: |
| 555 | self.route_points = self.route_points[min_offset_index:] |
no outgoing calls
no test coverage detected