| 202 | } |
| 203 | |
| 204 | AddressEnricher::FoundT AddressEnricher::Match(Entry & e) const |
| 205 | { |
| 206 | // Calc query rect with the threshold. |
| 207 | m2::RectD rect; |
| 208 | for (auto const & p : e.m_points) |
| 209 | rect.Add(p); |
| 210 | m2::RectD const inflation = mercator::RectByCenterXYAndSizeInMeters(rect.Center(), kDistanceThresholdM); |
| 211 | rect.Inflate(inflation.SizeX(), inflation.SizeY()); |
| 212 | |
| 213 | // Tiger usually has short (St) names, while OSM has full (Street) names. |
| 214 | auto const streetKey = search::GetNormalizedStreetName(e.m_street); |
| 215 | |
| 216 | // Get HN range for the entry. |
| 217 | auto const range = e.GetHNRange(); |
| 218 | CHECK(range != Entry::kInvalidRange, ()); |
| 219 | CHECK(range.first <= range.second, (range)); |
| 220 | |
| 221 | // Prepare distance calculator for the entry. |
| 222 | std::vector<m2::ParametrizedSegment<m2::PointD>> eSegs; |
| 223 | eSegs.reserve(e.m_points.size() - 1); |
| 224 | for (size_t i = 1; i < e.m_points.size(); ++i) |
| 225 | eSegs.emplace_back(e.m_points[i - 1], e.m_points[i]); |
| 226 | |
| 227 | /// @todo Check nodes distance for now. Should make more honest algo. |
| 228 | auto const isClose = [&e, &eSegs](feature::FeatureBuilder const & fb) |
| 229 | { |
| 230 | bool res = false; |
| 231 | |
| 232 | fb.ForEachPoint([&](m2::PointD const & p) |
| 233 | { |
| 234 | if (res) |
| 235 | return; |
| 236 | |
| 237 | auto const ll = mercator::ToLatLon(p); |
| 238 | auto const check = [&ll](m2::PointD const & p) |
| 239 | { return ms::DistanceOnEarth(ll, mercator::ToLatLon(p)) < kDistanceThresholdM; }; |
| 240 | |
| 241 | if (!eSegs.empty()) |
| 242 | { |
| 243 | for (auto const & seg : eSegs) |
| 244 | if (check(seg.ClosestPointTo(p))) |
| 245 | { |
| 246 | res = true; |
| 247 | return; |
| 248 | } |
| 249 | } |
| 250 | else |
| 251 | res = check(e.m_points.front()); |
| 252 | }); |
| 253 | |
| 254 | return res; |
| 255 | }; |
| 256 | |
| 257 | FoundT res; |
| 258 | |
| 259 | m_srcTree.ForEachInRect(rect, [&](feature::FeatureBuilder const & fb) |
| 260 | { |
| 261 | auto const osmID = fb.GetMostGenericOsmId(); |
nothing calls this directly
no test coverage detected