Skip to content

Commit 4f0ec78

Browse files
authored
Configurable snapping behaviour (#5361)
1 parent 02b5045 commit 4f0ec78

File tree

15 files changed

+191
-56
lines changed

15 files changed

+191
-56
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Features:
66
- ADDED: new waypoints parameter to the `route` plugin, enabling silent waypoints [#5345](https://github.com/Project-OSRM/osrm-backend/pull/5345)
77
- ADDED: data timestamp information in the response (saved in new file `.osrm.timestamp`). [#5115](https://github.com/Project-OSRM/osrm-backend/issues/5115)
8+
- ADDED: new API parameter - `snapping=any|default` to allow snapping to previously unsnappable edges [#5361](https://github.com/Project-OSRM/osrm-backend/pull/5361)
89
- Routing:
910
- CHANGED: allow routing past `barrier=arch` [#5352](https://github.com/Project-OSRM/osrm-backend/pull/5352)
1011

docs/http.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ To pass parameters to each location some options support an array like encoding:
3232
|hints |`{hint};{hint}[;{hint} ...]` |Hint from previous request to derive position in street network. |
3333
|approaches |`{approach};{approach}[;{approach} ...]` |Keep waypoints on curb side. |
3434
|exclude |`{class}[,{class}]` |Additive list of classes to avoid, order does not matter. |
35+
|snapping |`default` (default), `any` |Default snapping avoids is_startpoint (see profile) edges, `any` will snap to any edge in the graph |
3536

3637
Where the elements follow the following format:
3738

docs/nodejs/api.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ Returns the fastest route between two or more coordinates while visiting the way
5959
- `options.approaches` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`.
6060
- `options.waypoints` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Indices to coordinates to treat as waypoints. If not supplied, all coordinates are waypoints. Must include first and last coordinate index.
6161
`null`/`true`/`false`
62+
- `options.snapping` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
6263
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
6364

6465
**Examples**
@@ -91,6 +92,7 @@ Note: `coordinates` in the general options only supports a single `{longitude},{
9192
- `options.number` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)** Number of nearest segments that should be returned.
9293
Must be an integer greater than or equal to `1`. (optional, default `1`)
9394
- `options.approaches` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`.
95+
- `options.snapping` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
9496
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
9597

9698
**Examples**
@@ -133,6 +135,7 @@ tables. Optionally returns distance table.
133135
- `options.fallback_speed` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Replace `null` responses in result with as-the-crow-flies estimates based on `fallback_speed`. Value is in metres/second.
134136
- `options.fallback_coordinate` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Either `input` (default) or `snapped`. If using a `fallback_speed`, use either the user-supplied coordinate (`input`), or the snapped coordinate (`snapped`) for calculating the as-the-crow-flies diestance between two points.
135137
- `options.scale_factor` **[Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** Multiply the table duration values in the table by this number for more controlled input into a route optimization solver.
138+
- `options.snapping` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
136139
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
137140

138141
**Examples**
@@ -212,6 +215,7 @@ if they can not be matched successfully.
212215
- `options.gaps` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Allows the input track splitting based on huge timestamp gaps between points. Either `split` or `ignore` (optional, default `split`).
213216
- `options.tidy` **[Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)?** Allows the input track modification to obtain better matching quality for noisy tracks (optional, default `false`).
214217
- `options.waypoints` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Indices to coordinates to treat as waypoints. If not supplied, all coordinates are waypoints. Must include first and last coordinate index.
218+
- `options.snapping` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
215219
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
216220

217221
**Examples**
@@ -276,6 +280,7 @@ Right now, the following combinations are possible:
276280
- `options.source` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Return route starts at `any` or `first` coordinate. (optional, default `any`)
277281
- `options.destination` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** Return route ends at `any` or `last` coordinate. (optional, default `any`)
278282
- `options.approaches` **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)?** Keep waypoints on curb side. Can be `null` (unrestricted, default) or `curb`.
283+
- `options.snapping` **[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** Which edges can be snapped to, either `default`, or `any`. `default` only snaps to edges marked by the profile as `is_startpoint`, `any` will allow snapping to any edge in the routing graph.
279284
- `callback` **[Function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/function)**
280285

281286
**Examples**

features/car/startpoint.feature

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,28 @@ Feature: Car - Allowed start/end modes
3535
| from | to | route | modes |
3636
| 1 | 2 | ab,ab | driving,driving |
3737
| 2 | 1 | ab,ab | driving,driving |
38+
39+
Scenario: Car - URL override of non-startpoints
40+
Given the node map
41+
"""
42+
a 1 b c 2 d
43+
"""
44+
45+
Given the query options
46+
| snapping | any |
47+
48+
And the ways
49+
| nodes | highway | access |
50+
| ab | service | private |
51+
| bc | primary | |
52+
| cd | service | private |
53+
54+
When I request a travel time matrix I should get
55+
| | 2 | c |
56+
| 1 | 59.1 | 35.1 |
57+
| b | 35.1 | 11.1 |
58+
59+
When I route I should get
60+
| from | to | route |
61+
| 1 | 2 | ab,bc,cd |
62+
| 2 | 1 | cd,bc,ab |

include/engine/api/base_parameters.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ namespace api
6363
*/
6464
struct BaseParameters
6565
{
66+
67+
enum class SnappingType
68+
{
69+
Default,
70+
Any
71+
};
72+
6673
std::vector<util::Coordinate> coordinates;
6774
std::vector<boost::optional<Hint>> hints;
6875
std::vector<boost::optional<double>> radiuses;
@@ -73,15 +80,19 @@ struct BaseParameters
7380
// Adds hints to response which can be included in subsequent requests, see `hints` above.
7481
bool generate_hints = true;
7582

83+
SnappingType snapping = SnappingType::Default;
84+
7685
BaseParameters(const std::vector<util::Coordinate> coordinates_ = {},
7786
const std::vector<boost::optional<Hint>> hints_ = {},
7887
std::vector<boost::optional<double>> radiuses_ = {},
7988
std::vector<boost::optional<Bearing>> bearings_ = {},
8089
std::vector<boost::optional<Approach>> approaches_ = {},
8190
bool generate_hints_ = true,
82-
std::vector<std::string> exclude = {})
91+
std::vector<std::string> exclude = {},
92+
const SnappingType snapping_ = SnappingType::Default)
8393
: coordinates(coordinates_), hints(hints_), radiuses(radiuses_), bearings(bearings_),
84-
approaches(approaches_), exclude(std::move(exclude)), generate_hints(generate_hints_)
94+
approaches(approaches_), exclude(std::move(exclude)), generate_hints(generate_hints_),
95+
snapping(snapping_)
8596
{
8697
}
8798

include/engine/datafacade/contiguous_internalmem_datafacade.hpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,48 +389,52 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
389389

390390
std::pair<PhantomNode, PhantomNode>
391391
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
392-
const Approach approach) const override final
392+
const Approach approach,
393+
const bool use_all_edges) const override final
393394
{
394395
BOOST_ASSERT(m_geospatial_query.get());
395396

396397
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
397-
input_coordinate, approach);
398+
input_coordinate, approach, use_all_edges);
398399
}
399400

400401
std::pair<PhantomNode, PhantomNode>
401402
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
402403
const double max_distance,
403-
const Approach approach) const override final
404+
const Approach approach,
405+
const bool use_all_edges) const override final
404406
{
405407
BOOST_ASSERT(m_geospatial_query.get());
406408

407409
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
408-
input_coordinate, max_distance, approach);
410+
input_coordinate, max_distance, approach, use_all_edges);
409411
}
410412

411413
std::pair<PhantomNode, PhantomNode>
412414
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
413415
const double max_distance,
414416
const int bearing,
415417
const int bearing_range,
416-
const Approach approach) const override final
418+
const Approach approach,
419+
const bool use_all_edges) const override final
417420
{
418421
BOOST_ASSERT(m_geospatial_query.get());
419422

420423
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
421-
input_coordinate, max_distance, bearing, bearing_range, approach);
424+
input_coordinate, max_distance, bearing, bearing_range, approach, use_all_edges);
422425
}
423426

424427
std::pair<PhantomNode, PhantomNode>
425428
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
426429
const int bearing,
427430
const int bearing_range,
428-
const Approach approach) const override final
431+
const Approach approach,
432+
const bool use_all_edges) const override final
429433
{
430434
BOOST_ASSERT(m_geospatial_query.get());
431435

432436
return m_geospatial_query->NearestPhantomNodeWithAlternativeFromBigComponent(
433-
input_coordinate, bearing, bearing_range, approach);
437+
input_coordinate, bearing, bearing_range, approach, use_all_edges);
434438
}
435439

436440
std::uint32_t GetCheckSum() const override final { return m_check_sum; }

include/engine/datafacade/datafacade_base.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,22 +161,26 @@ class BaseDataFacade
161161

162162
virtual std::pair<PhantomNode, PhantomNode>
163163
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
164-
const Approach approach) const = 0;
164+
const Approach approach,
165+
const bool use_all_edges) const = 0;
165166
virtual std::pair<PhantomNode, PhantomNode>
166167
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
167168
const double max_distance,
168-
const Approach approach) const = 0;
169+
const Approach approach,
170+
const bool use_all_edges) const = 0;
169171
virtual std::pair<PhantomNode, PhantomNode>
170172
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
171173
const double max_distance,
172174
const int bearing,
173175
const int bearing_range,
174-
const Approach approach) const = 0;
176+
const Approach approach,
177+
const bool use_all_edges) const = 0;
175178
virtual std::pair<PhantomNode, PhantomNode>
176179
NearestPhantomNodeWithAlternativeFromBigComponent(const util::Coordinate input_coordinate,
177180
const int bearing,
178181
const int bearing_range,
179-
const Approach approach) const = 0;
182+
const Approach approach,
183+
const bool use_all_edges = false) const = 0;
180184

181185
virtual bool HasLaneData(const EdgeID id) const = 0;
182186
virtual util::guidance::LaneTupleIdPair GetLaneData(const EdgeID id) const = 0;

0 commit comments

Comments
 (0)