matchTags - don't calculcate valid locations unless needed

mismatched_geometry - small optimization
This commit is contained in:
Milos Brzakovic (E-Search)
2021-10-20 09:49:00 +02:00
parent 49f5d03e55
commit 599d2df19b
2 changed files with 22 additions and 11 deletions
+20 -10
View File
@@ -208,11 +208,8 @@ export function presetIndex() {
let address;
let best = -1;
let match;
let matchCandidates = [];
let validLocations;
if (Array.isArray(loc)) {
validLocations = locationManager.locationsAt(loc);
}
for (let k in tags) {
// If any part of an address is present, allow fallback to "Address" preset - #4353
@@ -225,13 +222,11 @@ export function presetIndex() {
for (let i = 0; i < keyMatches.length; i++) {
const candidate = keyMatches[i];
// discard candidate preset if location is not valid at `loc`
if (validLocations && candidate.locationSetID) {
if (!validLocations[candidate.locationSetID]) continue;
}
const score = candidate.matchScore(tags);
if (score === -1){
continue;
}
matchCandidates.push({score, candidate});
if (score > best) {
best = score;
match = candidate;
@@ -239,6 +234,21 @@ export function presetIndex() {
}
}
if (match && match.locationSetID && Array.isArray(loc)){
validLocations = locationManager.locationsAt(loc);
if (!validLocations[match.locationSetID]){
matchCandidates.sort((a, b) => (a.score < b.score) ? 1 : -1);
for (let i = 0; i < matchCandidates.length; i++){
const candidateScore = matchCandidates[i];
if (!candidateScore.candidate.locationSetID || validLocations[candidateScore.candidate.locationSetID]){
match = candidateScore.candidate;
best = candidateScore.score;
break;
}
}
}
}
if (address && (!match || match.isFallback())) {
match = address;
}
+2 -1
View File
@@ -220,8 +220,9 @@ export function validationMismatchedGeometry() {
if (sourceGeom === 'area') targetGeoms.unshift('line');
var asSource = presetManager.match(entity, graph);
var targetGeom = targetGeoms.find(nodeGeom => {
var asSource = presetManager.matchTags(entity.tags, sourceGeom);
var asTarget = presetManager.matchTags(entity.tags, nodeGeom);
if (!asSource || !asTarget ||
asSource === asTarget ||