Skip to content

Commit

Permalink
Fix failing tests - new edges in rtree need to be filtered out for no…
Browse files Browse the repository at this point in the history
…n-matching plugins.
  • Loading branch information
danpat committed Dec 13, 2018
1 parent d9fb5d4 commit 850b4b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ Vector tiles contain two layers:
| `weight ` | `integer` | how long this segment takes to traverse, in units (may differ from `duration` when artificial biasing is applied in the Lua profiles). ACTUAL ROUTING USES THIS VALUE. |
| `name` | `string` | the name of the road this segment belongs to |
| `rate` | `float` | the value of `length/weight` - analagous to `speed`, but using the `weight` value rather than `duration`, rounded to the nearest integer |
| `is_startpoint` | `boolean` | whether this segment can be used as a start/endpoint for routes |

`turns` layer:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const float max_distance,
const Approach approach,
const bool use_all_edges = false) const override final
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());

Expand All @@ -327,7 +327,7 @@ class ContiguousInternalMemoryDataFacadeBase : public BaseDataFacade
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges = false) const override final
const bool use_all_edges) const override final
{
BOOST_ASSERT(m_geospatial_query.get());

Expand Down
40 changes: 13 additions & 27 deletions include/engine/geospatial_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ inline std::pair<bool, bool> boolPairAnd(const std::pair<bool, bool> &A,
{
return std::make_pair(A.first && B.first, A.second && B.second);
}
inline std::pair<bool, bool> boolPairAnd(const std::pair<bool, bool> &A,
const std::pair<bool, bool> &B,
const std::pair<bool, bool> &C)
{
return std::make_pair(A.first && B.first && C.first, A.second && B.second && C.second);
}

// Implements complex queries on top of an RTree and builds PhantomNodes from it.
//
Expand Down Expand Up @@ -60,14 +54,14 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
NearestPhantomNodesInRange(const util::Coordinate input_coordinate,
const double max_distance,
const Approach approach,
const bool use_all_edges = false) const
const bool use_all_edges) const
{
auto results = rtree.Nearest(
input_coordinate,
[this, approach, &input_coordinate, use_all_edges](const CandidateSegment &segment) {
return boolPairAnd(boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)),
boolPairAnd(CheckSnappable(segment, use_all_edges),
CheckApproach(input_coordinate, segment, approach)));
return boolPairAnd(
boolPairAnd(HasValidEdge(segment, use_all_edges), CheckSegmentExclude(segment)),
CheckApproach(input_coordinate, segment, approach));
},
[this, max_distance, input_coordinate](const std::size_t,
const CandidateSegment &segment) {
Expand All @@ -85,16 +79,16 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
const int bearing,
const int bearing_range,
const Approach approach,
const bool use_all_edges = false) const
const bool use_all_edges) const
{
auto results = rtree.Nearest(
input_coordinate,
[this, approach, &input_coordinate, bearing, bearing_range, use_all_edges](
const CandidateSegment &segment) {
auto use_direction =
boolPairAnd(boolPairAnd(CheckSnappable(segment, use_all_edges),
CheckSegmentBearing(segment, bearing, bearing_range)),
boolPairAnd(HasValidEdge(segment), CheckSegmentExclude(segment)));
boolPairAnd(CheckSegmentBearing(segment, bearing, bearing_range),
boolPairAnd(HasValidEdge(segment, use_all_edges),
CheckSegmentExclude(segment)));
use_direction =
boolPairAnd(use_direction, CheckApproach(input_coordinate, segment, approach));
return use_direction;
Expand Down Expand Up @@ -632,25 +626,14 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
return std::make_pair(forward_bearing_valid, backward_bearing_valid);
}

std::pair<bool, bool> CheckSnappable(const CandidateSegment &segment,
const bool use_all_edges) const
{

const bool forward_segment_snappable = segment.data.forward_segment_id.enabled &&
(segment.data.is_startpoint || use_all_edges);
const bool reverse_segment_snappable = segment.data.reverse_segment_id.enabled &&
(segment.data.is_startpoint || use_all_edges);

return std::make_pair(forward_segment_snappable, reverse_segment_snappable);
}

/**
* Checks to see if the edge weights are valid. We might have an edge,
* but a traffic update might set the speed to 0 (weight == INVALID_SEGMENT_WEIGHT).
* which means that this edge is not currently traversible. If this is the case,
* then we shouldn't snap to this edge.
*/
std::pair<bool, bool> HasValidEdge(const CandidateSegment &segment) const
std::pair<bool, bool> HasValidEdge(const CandidateSegment &segment,
const bool use_all_edges = false) const
{

bool forward_edge_valid = false;
Expand All @@ -674,6 +657,9 @@ template <typename RTreeT, typename DataFacadeT> class GeospatialQuery
reverse_edge_valid = data.reverse_segment_id.enabled;
}

forward_edge_valid = forward_edge_valid && (data.is_startpoint || use_all_edges);
reverse_edge_valid = reverse_edge_valid && (data.is_startpoint || use_all_edges);

return std::make_pair(forward_edge_valid, reverse_edge_valid);
}

Expand Down
12 changes: 11 additions & 1 deletion src/engine/plugins/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ struct SpeedLayer : public vtzero::layer_builder
vtzero::index_value key_duration;
vtzero::index_value key_name;
vtzero::index_value key_rate;
vtzero::index_value key_is_startpoint;

SpeedLayer(vtzero::tile_builder &tile)
: layer_builder(tile, "speeds"), uint_index(*this), double_index(*this),
Expand All @@ -302,7 +303,8 @@ struct SpeedLayer : public vtzero::layer_builder
key_datasource(add_key_without_dup_check("datasource")),
key_weight(add_key_without_dup_check("weight")),
key_duration(add_key_without_dup_check("duration")),
key_name(add_key_without_dup_check("name")), key_rate(add_key_without_dup_check("rate"))
key_name(add_key_without_dup_check("name")), key_rate(add_key_without_dup_check("rate")),
key_is_startpoint(add_key_without_dup_check("is_startpoint"))
{
}

Expand Down Expand Up @@ -349,6 +351,11 @@ class SpeedLayerFeatureBuilder : public vtzero::linestring_feature_builder

void set_rate(double value) { add_property(m_layer.key_rate, m_layer.double_index(value)); }

void set_is_startpoint(bool value)
{
add_property(m_layer.key_is_startpoint, m_layer.bool_index(value));
}

}; // class SpeedLayerFeatureBuilder

struct TurnsLayer : public vtzero::layer_builder
Expand Down Expand Up @@ -485,6 +492,8 @@ void encodeVectorTile(const DataFacadeBase &facade,
const auto reverse_datasource_idx = reverse_datasource_range(
reverse_datasource_range.size() - edge.fwd_segment_position - 1);

const auto is_startpoint = edge.is_startpoint;

const auto component_id = facade.GetComponentID(edge.forward_segment_id.id);
const auto name_id = facade.GetNameIndex(edge.forward_segment_id.id);
auto name = facade.GetNameForID(name_id);
Expand Down Expand Up @@ -516,6 +525,7 @@ void encodeVectorTile(const DataFacadeBase &facade,
fbuilder.set_duration(forward_duration / 10.0);
fbuilder.set_name(name);
fbuilder.set_rate(forward_rate / 10.0);
fbuilder.set_is_startpoint(is_startpoint);

fbuilder.commit();
}
Expand Down

0 comments on commit 850b4b8

Please sign in to comment.