20 NON_DEFAULT_CONSTRUCTIBLE(TargetNearest)
21 COPYABLE(TargetNearest)
22 MOVEABLE(TargetNearest)
26 std::optional<TargetModifier> modifier;
28 explicit TargetNearest(
Ptype type,
bool allPeds =
false,
29 std::optional<TargetModifier> modifier = std::nullopt)
30 : type(type), allPeds(allPeds), modifier(std::move(modifier))
44 auto curr = nearest_in_group(pack, self.target.targetIdx, pack.groups.get_group(0));
45 if ( curr.second == VIPRA::INVALID_IDX )
return Target{TargetType::INVALID, 0};
46 return {TargetType::PEDESTRIAN, curr.second};
49 VIPRA::f_pnt shortest = std::numeric_limits<VIPRA::f_pnt>::max();
50 VIPRA::idx nearest = VIPRA::INVALID_IDX;
52 type.for_each_type([&](typeUID type) {
55 nearest_in_group(pack, self.target.targetIdx, pack.groups.get_group(groupIdx));
56 if ( curr.first < shortest ) {
57 shortest = curr.first;
58 nearest = curr.second;
62 if ( nearest == VIPRA::INVALID_IDX ) {
63 return Target{TargetType::INVALID, 0};
66 return Target{TargetType::PEDESTRIAN, nearest};
78 [[nodiscard]]
inline auto nearest_in_group(
Simpack pack, VIPRA::idx self,
79 VIPRA::idxVec
const& idxs)
const
80 -> std::pair<VIPRA::f_pnt, VIPRA::idx>
82 VIPRA::f_pnt shortest = std::numeric_limits<VIPRA::f_pnt>::max();
83 VIPRA::idx nearest = VIPRA::INVALID_IDX;
85 auto const& coords = pack.pedset.all_coords();
88 nearest = pack.pedset.conditional_closest_ped(self, [&](VIPRA::idx other) {
89 if ( std::find(idxs.begin(), idxs.end(), other) == idxs.end() )
return false;
92 if ( ! modifier->check(pack, self, other) )
return false;
95 if ( pack.map.ray_hit(currCoords, coords[other]) != -1 )
return false;
100 return {currCoords.distance_to(coords[nearest]), nearest};
auto operator()(Simpack pack, Self self) const -> Target
Returns the nearest pedestrian that has any of the target types.
Definition target_nearest.hpp:41