Skip to content

Commit

Permalink
attempt to fix infinite loop in isochrones generation (valhalla#4547)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinkreiser authored Feb 9, 2024
1 parent 1c2ff98 commit 129c55b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: syntax
name: lint
on: [pull_request]

jobs:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* FIXED: Config singleton multiple instantiation issue [#4521](https://github.com/valhalla/valhalla/pull/4521)
* FIXED: Prevent GetShortcut to run into an infinite loop [#4532](https://github.com/valhalla/valhalla/pull/4532)
* FIXED: fix config generator with thor.costmatrix_allow_second_pass [#4567](https://github.com/valhalla/valhalla/pull/4567)
* FIXED: infinite loop or other random corruption in isochrones when retrieving partial shape of an edge [#4547](https://github.com/valhalla/valhalla/pull/4547)
* **Enhancement**
* UPDATED: French translations, thanks to @xlqian [#4159](https://github.com/valhalla/valhalla/pull/4159)
* CHANGED: -j flag for multithreaded executables to override mjolnir.concurrency [#4168](https://github.com/valhalla/valhalla/pull/4168)
Expand Down
10 changes: 10 additions & 0 deletions src/thor/isochrone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,18 @@ constexpr float METRIC_PADDING = 10.f;
template <typename PrecisionT>
std::vector<GeoPoint<PrecisionT>> OriginEdgeShape(const std::vector<GeoPoint<PrecisionT>>& pts,
double distance_along) {
// just the endpoint really
if (distance_along == 0)
return {pts.back(), pts.back()};

// consume shape until we reach the desired distance
double suffix_len = 0;
for (auto from = std::next(pts.rbegin()), to = pts.rbegin(); from != pts.rend(); ++from, ++to) {
// add whatever this segment of shape contributes to the overall distance
PrecisionT len = from->Distance(*to);
suffix_len += len;

// we have enough distance now, lets find the exact stopping point along the geom
if (suffix_len >= distance_along) {
auto interpolated = from->PointAlongSegment(*to, (suffix_len - distance_along) / len);
std::vector<GeoPoint<PrecisionT>> res(pts.rbegin(), from);
Expand All @@ -29,6 +37,8 @@ std::vector<GeoPoint<PrecisionT>> OriginEdgeShape(const std::vector<GeoPoint<Pre
return res;
}
}

// we got through the whole shape didnt reach the distance, floating point noise probably
return pts;
}

Expand Down

0 comments on commit 129c55b

Please sign in to comment.