Skip to content

Commit cd409dc

Browse files
Merge branch 'master' of github.com:motis-project/osr
# Conflicts: # include/osr/lookup.h
2 parents f61d321 + c12b001 commit cd409dc

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

include/osr/lookup.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,7 @@ struct lookup {
200200

201201
template <typename Fn>
202202
void find(geo::latlng const& x, Fn&& fn) const {
203-
find(geo::box{{x.lat() - 0.01, x.lng() - 0.01},
204-
{x.lat() + 0.01, x.lng() + 0.01}},
203+
find({{x.lat() - 0.01, x.lng() - 0.01}, {x.lat() + 0.01, x.lng() + 0.01}},
205204
std::forward<Fn>(fn));
206205
}
207206

src/route.cc

+27
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,8 @@ path reconstruct(ways const& w,
153153
auto segments = std::vector<path::segment>{{.polyline_ = dest.path_,
154154
.from_level_ = dest.lvl_,
155155
.to_level_ = dest.lvl_,
156+
.from_ = node_idx_t::invalid(),
157+
.to_ = node_idx_t::invalid(),
156158
.way_ = way_idx_t::invalid()}};
157159
auto dist = 0.0;
158160
while (true) {
@@ -248,6 +250,25 @@ best_candidate(ways const& w,
248250
return std::nullopt;
249251
}
250252

253+
std::optional<path> try_direct(osr::location const& from,
254+
osr::location const& to) {
255+
auto const dist = geo::distance(from.pos_, to.pos_);
256+
return dist < 5.0
257+
? std::optional{path{.cost_ = 60U,
258+
.dist_ = dist,
259+
.segments_ = {path::segment{
260+
.polyline_ = {from.pos_, to.pos_},
261+
.from_level_ = from.lvl_,
262+
.to_level_ = to.lvl_,
263+
.from_ = node_idx_t::invalid(),
264+
.to_ = node_idx_t::invalid(),
265+
.way_ = way_idx_t::invalid(),
266+
.cost_ = 60U,
267+
.dist_ = static_cast<distance_t>(dist)}},
268+
.uses_elevator_ = false}}
269+
: std::nullopt;
270+
}
271+
251272
template <typename Profile>
252273
std::optional<path> route(ways const& w,
253274
lookup const& l,
@@ -267,6 +288,10 @@ std::optional<path> route(ways const& w,
267288
return std::nullopt;
268289
}
269290

291+
if (auto const direct = try_direct(from, to); direct.has_value()) {
292+
return *direct;
293+
}
294+
270295
d.reset(max);
271296

272297
for (auto const& start : from_match) {
@@ -339,6 +364,8 @@ std::vector<std::optional<path>> route(
339364
for (auto const [m, t, r] : utl::zip(to_match, to, result)) {
340365
if (r.has_value()) {
341366
++found;
367+
} else if (auto const direct = try_direct(from, t); direct.has_value()) {
368+
r = direct;
342369
} else {
343370
auto const c = best_candidate(w, d, t.lvl_, m, max, dir);
344371
if (c.has_value()) {

web/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@
504504
}
505505

506506
const getRoute = async () => {
507-
const response = await fetch(`${window.origin}/api/route`, {
507+
const response = await fetch('api/route', {
508508
method: 'POST',
509509
mode: 'cors',
510510
headers: {
@@ -544,7 +544,7 @@
544544
};
545545

546546
const getGraph = async (bounds) => {
547-
const response = await fetch(`${window.origin}/api/graph`, {
547+
const response = await fetch('api/graph', {
548548
method: 'POST',
549549
mode: 'cors',
550550
headers: {
@@ -560,7 +560,7 @@
560560
};
561561

562562
const getLevels = async (bounds) => {
563-
const response = await fetch(`${window.origin}/api/levels`, {
563+
const response = await fetch('api/levels', {
564564
method: 'POST',
565565
mode: 'cors',
566566
headers: {

0 commit comments

Comments
 (0)