From 8b3b8635c44081033c0e8919a6b6fed0a39d38d4 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Mon, 2 Mar 2020 11:13:21 +0100 Subject: [PATCH] Find loose ends --- .../loaders/TaxiwaySegmentExtender.js | 1 + src/renderer/utils/check.js | 111 ++++++++++-------- 2 files changed, 65 insertions(+), 47 deletions(-) diff --git a/src/renderer/loaders/TaxiwaySegmentExtender.js b/src/renderer/loaders/TaxiwaySegmentExtender.js index b5059dc..a4861e0 100644 --- a/src/renderer/loaders/TaxiwaySegmentExtender.js +++ b/src/renderer/loaders/TaxiwaySegmentExtender.js @@ -39,6 +39,7 @@ exports.extendTaxiSegment = function (taxiwaySegment) { } this.featureLookup[this.begin].push(this); this.featureLookup[this.end].push(this); + this.bidirectional = true; }; taxiwaySegment.__proto__.addListeners = function () { this.on('click', function (event) { diff --git a/src/renderer/utils/check.js b/src/renderer/utils/check.js index b082f30..b591150 100644 --- a/src/renderer/utils/check.js +++ b/src/renderer/utils/check.js @@ -36,55 +36,72 @@ onmessage = function (event) { async function checkGroundnet(data) { var promise = new Promise(function (resolve, reject) { - this.max = 4; - debugger; - var parkings = data.map(mapParkings).filter(n => n !== undefined); - var runwayNodes = data.map(mapRunwayNodes).filter(n => n !== undefined); - var edges = data.map(mapEdges).filter(n => n !== undefined); - - var graph = {}; - parkings.forEach(element => { - graph[element] = {}; - }); - runwayNodes.forEach(element => { - graph[element] = {}; - }); - edges.forEach(element => { - graph[element.start] = {}; - graph[element.end] = {}; - }); - edges.forEach(element => { - var node1 = graph[element.start]; - node1[element.end] = 1; - var node2 = graph[element.end]; - node2[element.start] = 1; - }); - var okNodes = []; - logger('info', graph); - parkings.forEach(parkingNode => { - runwayNodes.forEach(runwayNode => { - var ok = checkRoute(graph, parkingNode, runwayNode); - if(ok) { - okNodes.push(parkingNode); - okNodes.push(runwayNode); - } - this.progress += 1; + try { + this.max = 4; + debugger; + var parkings = data.map(mapParkings).filter(n => n !== undefined); + var runwayNodes = data.map(mapRunwayNodes).filter(n => n !== undefined); + var edges = data.map(mapEdges).filter(n => n !== undefined); + + var graph = {}; + parkings.forEach(element => { + graph[element] = {}; }); - }); - okNodes = okNodes.filter((v,i) => okNodes.indexOf(v) === i); - var allNodes = parkings.concat(runwayNodes); - var notOkNodes = allNodes.filter((v,i) => okNodes.indexOf(v) < 0).map(id => {return {id:id, message:'Node not connected'}}); - if (parkings.length === 0) { - notOkNodes.push({id:0, message:'No parkings'}); + runwayNodes.forEach(element => { + graph[element] = {}; + }); + edges.forEach(element => { + graph[element.start] = {}; + graph[element.end] = {}; + }); + edges.forEach(element => { + var node1 = graph[element.start]; + node1[Number(element.end)] = 1; + var node2 = graph[element.end]; + node2[Number(element.start)] = 1; + }); + var okNodes = []; + logger('info', graph); + parkings.forEach(parkingNode => { + runwayNodes.forEach(runwayNode => { + var ok = checkRoute(graph, parkingNode, runwayNode); + if(ok) { + okNodes.push(parkingNode); + okNodes.push(runwayNode); + } + this.progress += 1; + }); + }); + okNodes = okNodes.filter((v,i) => okNodes.indexOf(v) === i); + var allLegitimateEndNodes = parkings.concat(runwayNodes); + var notOkNodes = allLegitimateEndNodes.filter( + (v,i) => okNodes.indexOf(v) < 0 + ).map( + id => {return {id:id, message:'Node not connected'}} + ); + if (parkings.length === 0) { + notOkNodes.push({id:0, message:'No parkings'}); + } + if (runwayNodes.length === 0) { + notOkNodes.push({id:0, message:'No Runwaynodes'}); + } + var danglingEnds = Object.entries(graph).filter( + (v,i) => Object.keys(v[1]).length <= 1 + ).filter( + (v,i) => allLegitimateEndNodes.indexOf(Number(v[0])) < 0 + ).map( + v => {return {id:Number(v[0]), message:'Node not a legimate end'}} + ); + notOkNodes = notOkNodes.concat(danglingEnds); + + // check1(graph); + // check2(); + // this.progress += 1; + resolve(notOkNodes); + + } catch (error) { + reject(error); } - if (runwayNodes.length === 0) { - notOkNodes.push({id:0, message:'No Runwaynodes'}); - } - -// check1(graph); -// check2(); -// this.progress += 1; - resolve(notOkNodes); }); return promise; }