mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-23 16:49:40 +02:00
Reduce duplicate code in almost junction validation
This commit is contained in:
@@ -49,49 +49,32 @@ export function validationAlmostJunction() {
|
||||
var results = [];
|
||||
if (way.isClosed()) return results;
|
||||
|
||||
var nidFirst = way.nodes[0];
|
||||
var nidLast = way.nodes[way.nodes.length - 1];
|
||||
var nodeFirst = graph.entity(nidFirst);
|
||||
var nodeLast = graph.entity(nidLast);
|
||||
var testNodes, index;
|
||||
var testNodes;
|
||||
var endpointIndicies = [0, way.nodes.length - 1];
|
||||
endpointIndicies.forEach(function(nodeIndex) {
|
||||
|
||||
if (isExtendableCandidate(nodeFirst, way, graph)) {
|
||||
var connNearFirst = canConnectByExtend(way, 0, graph, tree);
|
||||
if (connNearFirst) {
|
||||
testNodes = graph.childNodes(way).slice(); // shallow copy
|
||||
index = 0; // first
|
||||
testNodes[index] = testNodes[index].move(connNearFirst.cross_loc);
|
||||
var nodeID = way.nodes[nodeIndex];
|
||||
var node = graph.entity(nodeID);
|
||||
|
||||
// don't flag issue if connecting the ways would cause self-intersection
|
||||
if (!geoHasSelfIntersections(testNodes, nodeFirst.id)) {
|
||||
results.push({
|
||||
node: nodeFirst,
|
||||
wid: connNearFirst.wid,
|
||||
edge: connNearFirst.edge,
|
||||
cross_loc: connNearFirst.cross_loc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isExtendableCandidate(node, way, graph)) return;
|
||||
|
||||
if (isExtendableCandidate(nodeLast, way, graph)) {
|
||||
var connNearLast = canConnectByExtend(way, way.nodes.length - 1, graph, tree);
|
||||
if (connNearLast) {
|
||||
testNodes = graph.childNodes(way).slice(); // shallow copy
|
||||
index = testNodes.length - 1; // last
|
||||
testNodes[index] = testNodes[index].move(connNearLast.cross_loc);
|
||||
var connectionInfo = canConnectByExtend(way, nodeIndex, graph, tree);
|
||||
if (!connectionInfo) return;
|
||||
|
||||
testNodes = graph.childNodes(way).slice(); // shallow copy
|
||||
testNodes[nodeIndex] = testNodes[nodeIndex].move(connectionInfo.cross_loc);
|
||||
|
||||
// don't flag issue if connecting the ways would cause self-intersection
|
||||
if (geoHasSelfIntersections(testNodes, nodeID)) return;
|
||||
|
||||
results.push({
|
||||
node: node,
|
||||
wid: connectionInfo.wid,
|
||||
edge: connectionInfo.edge,
|
||||
cross_loc: connectionInfo.cross_loc
|
||||
});
|
||||
});
|
||||
|
||||
// don't flag issue if connecting the ways would cause self-intersection
|
||||
if (!geoHasSelfIntersections(testNodes, nodeLast.id)) {
|
||||
results.push({
|
||||
node: nodeLast,
|
||||
wid: connNearLast.wid,
|
||||
edge: connNearLast.edge,
|
||||
cross_loc: connNearLast.cross_loc
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user