From 8c378191df64cc9986caecbe25ed664304eaaf64 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Wed, 15 Jun 2016 00:23:21 +0200 Subject: [PATCH] Fix omitting the last point's coordinates in the geometry field --- features/step_definitions/matching.js | 14 ++++++++++++++ features/testbot/matching.feature | 18 ++++++++++++++++++ package.json | 3 ++- src/engine/guidance/assemble_overview.cpp | 4 ++-- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/features/step_definitions/matching.js b/features/step_definitions/matching.js index 4ca378f6d..0d85f096c 100644 --- a/features/step_definitions/matching.js +++ b/features/step_definitions/matching.js @@ -1,5 +1,6 @@ var util = require('util'); var d3 = require('d3-queue'); +var polyline = require('polyline'); module.exports = function () { this.When(/^I match I should get$/, (table, callback) => { @@ -35,6 +36,7 @@ module.exports = function () { route = '', duration = '', annotation = '', + geometry = '', OSMIDs = ''; @@ -63,6 +65,11 @@ module.exports = function () { annotation = this.annotationList(json.matchings[0]); } + if (headers.has('geometry')) { + if (json.matchings.length != 1) throw new Error('*** Checking geometry only supported for matchings with one subtrace'); + geometry = json.matchings[0].geometry; + } + if (headers.has('OSM IDs')) { if (json.matchings.length != 1) throw new Error('*** CHecking annotation only supported for matchings with one subtrace'); OSMIDs = this.OSMIDList(json.matchings[0]); @@ -85,6 +92,13 @@ module.exports = function () { got.annotation = annotation.toString(); } + if (headers.has('geometry')) { + if (this.queryParams['geometries'] === 'polyline') + got.geometry = polyline.decode(geometry).toString(); + else + got.geometry = geometry; + } + if (headers.has('OSM IDs')) { got['OSM IDs'] = OSMIDs; } diff --git a/features/testbot/matching.feature b/features/testbot/matching.feature index f105a7200..2de39f5ad 100644 --- a/features/testbot/matching.feature +++ b/features/testbot/matching.feature @@ -128,3 +128,21 @@ Feature: Basic Map Matching | trace | matchings | OSM IDs | | abeh | abcedgh | 1,2,3,2,3,4,5,4,5,6,7 | | abci | abc,ci | 1,2,3,2,3,8,3,8 | + + Scenario: Testbot - Geometry details + Given the query options + | overview | full | + | geometries | polyline | + + Given the node map + | a | b | c | + | | d | | + + And the ways + | nodes | oneway | + | abc | no | + | bd | no | + + When I match I should get + | trace | matchings | geometry | + | abd | abd | 1,1,1,1.00009,1,1.00009,0.99991,1.00009 | diff --git a/package.json b/package.json index 46c0bb70c..f03a47b05 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "node-timeout": "0.0.4", "request": "^2.69.0", "xmlbuilder": "^4.2.1", - "chalk": "^1.1.3" + "chalk": "^1.1.3", + "polyline": "^0.2.0" }, "bin": { "cucumber": "./node_modules/cucumber/bin/cucumber.js" diff --git a/src/engine/guidance/assemble_overview.cpp b/src/engine/guidance/assemble_overview.cpp index a53ff4cc1..70704351e 100644 --- a/src/engine/guidance/assemble_overview.cpp +++ b/src/engine/guidance/assemble_overview.cpp @@ -85,12 +85,12 @@ std::vector assembleOverview(const std::vector &l std::vector overview_geometry; overview_geometry.reserve(overview_size); - auto leg_index = 0UL; + auto leg_reverse_index = leg_geometries.size(); for (const auto &geometry : leg_geometries) { auto begin = geometry.locations.begin(); auto end = geometry.locations.end(); - if (leg_index < leg_geometries.size() - 1) + if (--leg_reverse_index > 0) { end = std::prev(end); }