Skip to content

Commit

Permalink
Make building crossing validation only create one issue per feature p…
Browse files Browse the repository at this point in the history
…air (re: #5891)
  • Loading branch information
quincylvania committed Feb 18, 2019
1 parent 94cb9fa commit 66db6f3
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions modules/validations/crossing_ways.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function validationCrossingWays() {

// Check if the edge going from n1 to n2 crosses (without a connection node)
// any edge on way. Return the cross point if so.
function findEdgeToWayCrossCoords(n1, n2, way, graph) {
function findEdgeToWayCrossCoords(n1, n2, way, graph, oneOnly) {
var crossCoords = [];
var nA, nB;
var segment1 = [n1.loc, n2.loc];
Expand All @@ -35,6 +35,9 @@ export function validationCrossingWays() {
var point = geoLineIntersection(segment1, segment2);
if (point) {
crossCoords.push({ edge: [nA.id, nB.id], point: point });
if (oneOnly) {
break;
}
}
}
return crossCoords;
Expand Down Expand Up @@ -229,6 +232,8 @@ export function validationCrossingWays() {
var primaryFeatureType = getFeatureTypeForCrossingCheck(primaryWay, graph);
if (primaryFeatureType === null) return edgeCrossInfos;

var checkedSingleCrossingWays = {};

for (var i = 0; i < primaryWay.nodes.length - 1; i++) {
var nid1 = primaryWay.nodes[i];
var nid2 = primaryWay.nodes[i + 1];
Expand All @@ -248,8 +253,12 @@ export function validationCrossingWays() {
var intersected = tree.intersects(extent, graph);
for (var j = 0; j < intersected.length; j++) {
var way = intersected[j];

if (way.type !== 'way') continue;

// skip if this way was already checked and only one issue is needed
if (checkedSingleCrossingWays[way.id]) continue;

// don't check for self-intersection in this validation
if (way.id === primaryWay.id) continue;

Expand All @@ -261,7 +270,10 @@ export function validationCrossingWays() {
continue;
}

var crossCoords = findEdgeToWayCrossCoords(n1, n2, way, graph);
// create only one issue for building crossings
var oneOnly = primaryFeatureType === 'building' || wayFeatureType === 'building';

var crossCoords = findEdgeToWayCrossCoords(n1, n2, way, graph, oneOnly);
for (var k = 0; k < crossCoords.length; k++) {
var crossingInfo = crossCoords[k];
edgeCrossInfos.push({
Expand All @@ -270,6 +282,9 @@ export function validationCrossingWays() {
edges: [[n1.id, n2.id], crossingInfo.edge],
crossPoint: crossingInfo.point
});
if (oneOnly) {
checkedSingleCrossingWays[way.id] = true;
}
}
}
}
Expand Down

0 comments on commit 66db6f3

Please sign in to comment.