From 2f86bed0bfa2c80b609f4b20861522284ace01c6 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Sat, 7 Mar 2020 21:35:41 +0100 Subject: [PATCH] Check Intersection --- .travis.yml | 1 + src/renderer/components/EditBar.vue | 8 +++++- src/renderer/components/FlightgearMap.vue | 2 +- src/renderer/utils/apt.js | 27 ++++++++++++++++++- src/renderer/utils/check.js | 33 ++++++++++++++++++++--- src/renderer/utils/haversine.js | 21 +++++++++++++++ 6 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 src/renderer/utils/haversine.js diff --git a/.travis.yml b/.travis.yml index e50a71e..697abb6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,4 +27,5 @@ deploy: secure: Xm3z86gQmpSajvlXSVgG7mxcaS5K7GfE4HrARIDR4pQ4UguQ3/fFOenRyKAQImmH0kLCSIbVE21NMAQ3YI2F9El9I6GU7Wirccsg14TZZiBQAzKOTXZ+JsBloeBxuTOsR84SkO6pV8OT/pRnQd9frqyc1W7wzoX+0sQykMztXCNfI+1MXXGOAgMzlKuDMO1PVENz0V63mWipL/Mae/SyrHa1Bws+4LJKvv42m0HMKdN7ekt41vxcSUvLmN+YLlqUEVr/eUhQXUNCaWlmM0KxmfuzTedca5/1yzLvN8smEt2I2b0DFRM3Mi/QdI22fVRHs6XGpm8yqZRKmhySDXFspXKWBiuCF6AezX6NiIe/ZUh10gIukjkyLtrNk/o29qhj2WE9HJz4xhsGMAx3632cLSMPku5ALN7jv5scWjwCGNHs4ZeZyyePMeGM6Y6pje1uJPbxWGjwoV6iI4Y4esP+z3KcXvZdnzkpYMy2mzdT4gf7A7zieax1YwB6U/MEanXYKFBH4yzYK9+hx3ck2eLT3LcV/ChHN2bKmERJdf18h+zI8e5YKTzd3/kHLiUUv19N2a4TUYloGOyzrLwn2VD1Xm4jJVVLTIQvWbH5YK7cNkHYa4+PnsB+JppSoby7HiBcothw4OLpJO8eCMqXcPRU1n+cRAZTB7VOS7pWh8e8LFE= file: build/* on: + branch: master repo: Portree-Kid/flightgear-airports diff --git a/src/renderer/components/EditBar.vue b/src/renderer/components/EditBar.vue index 4df74ab..1ba4736 100644 --- a/src/renderer/components/EditBar.vue +++ b/src/renderer/components/EditBar.vue @@ -167,7 +167,13 @@ }, featuresMapper(o) { if (o instanceof L.ParkingSpot) { - return { 'index': Number(o['id']), '_leaflet_id': o._leaflet_id, 'type': 'parking', 'name': o.options.attributes.name, 'radius': String(o.options.attributes.radius) }; + return { 'index': Number(o['id']), + '_leaflet_id': o._leaflet_id, + 'type': 'parking', + 'name': o.options.attributes.name, + 'radius': String(o.options.attributes.radius), + 'lat': o._latlng.lat, + 'lng': o._latlng.lng }; } else if (o instanceof L.RunwayNode) { console.log(o) return { 'index': Number(o['glueindex']), '_leaflet_id': o._leaflet_id, 'type': 'runway' }; diff --git a/src/renderer/components/FlightgearMap.vue b/src/renderer/components/FlightgearMap.vue index 246d5f5..f5ca5ae 100644 --- a/src/renderer/components/FlightgearMap.vue +++ b/src/renderer/components/FlightgearMap.vue @@ -9,7 +9,7 @@ ref="map" > - + diff --git a/src/renderer/utils/apt.js b/src/renderer/utils/apt.js index 6c7a3d0..c591897 100644 --- a/src/renderer/utils/apt.js +++ b/src/renderer/utils/apt.js @@ -36,6 +36,24 @@ var scanMethods = { }); return promise; }, + 18: async (l, apts) => { + var promise = new Promise(function (resolve, reject) { + logger('info','Airport light beacon:', l); + saveCoordinates(apts, icao, l[1], l[2]).then(result => { + resolve(result) + }).catch( err => {reject(err)});; + }); + return promise; + }, + 19: async (l, apts) => { + var promise = new Promise(function (resolve, reject) { + logger('info','Windsock:', l); + saveCoordinates(apts, icao, l[1], l[2]).then(result => { + resolve(result) + }).catch( err => {reject(err)});; + }); + return promise; + }, 99: async (l) => { logger('info','Finished'); } @@ -107,7 +125,14 @@ async function saveCoordinates(features, icao, lat, lon) { } }; } - feature.geometry.coordinates = [lon, lat]; + + if (!feature.geometry.coordinates || isNaN(feature.geometry.coordinates[0]) || isNaN(feature.geometry.coordinates[1])) { + feature.geometry.coordinates = [lon, lat]; + } else { + var avgLon = (Number(lon) + Number(feature.geometry.coordinates[0])) / 2; + var avgLat = (Number(lat) + Number(feature.geometry.coordinates[1])) / 2; + feature.geometry.coordinates = [avgLon, avgLat]; + } logger('info',"ICAO : " + feature.properties.icao); // Create another request that inserts the item back into the database var updateAirportRequest = objectStore.put(feature); diff --git a/src/renderer/utils/check.js b/src/renderer/utils/check.js index 175d4c5..121cc2a 100644 --- a/src/renderer/utils/check.js +++ b/src/renderer/utils/check.js @@ -11,6 +11,7 @@ importScripts('../../../node_modules/dijkstrajs/dijkstra.js'); const homedir = require('os').homedir(); importScripts('logger.js'); +importScripts('haversine.js'); function errorReceiver(event) { throw event.data; @@ -27,8 +28,8 @@ onmessage = function (event) { // event.origin.webContents.send('scanFinished'); } ).catch(result => { - console.log('Crashed'); - console.log(result); + console.error('Crashed'); + console.error(result); postMessage('DONE'); }); } @@ -41,7 +42,8 @@ async function checkGroundnet(data) { 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); - this.max = parkings.length * runwayNodes.length; + this.max = parkings.length * runwayNodes.length + + parkings.length; this.postMessage(['max', this.max]); var graph = {}; @@ -61,6 +63,7 @@ async function checkGroundnet(data) { var node2 = graph[element.end]; node2[Number(element.start)] = 1; }); + // Check if there is a route from every parking to every runway node var okNodes = []; logger('info', graph); parkings.forEach(parkingNode => { @@ -86,6 +89,7 @@ async function checkGroundnet(data) { if (runwayNodes.length === 0) { notOkNodes.push({id:0, message:'No Runwaynodes'}); } + // Ends that are not on Runway and not a Parking var danglingEnds = Object.entries(graph).filter( (v,i) => Object.keys(v[1]).length <= 1 ).filter( @@ -94,6 +98,23 @@ async function checkGroundnet(data) { v => {return {id:Number(v[0]), message:'Node not a legimate end'}} ); notOkNodes = notOkNodes.concat(danglingEnds); + + var parkingNodes = data.map(mapParkingNode).filter(n => n !== undefined); + + // Check for intersecting radii + parkingNodes.forEach(parkingNode => { + parkingNodes.forEach( parkingNode1 => { + console.log(parkingNode, parkingNode1); + if(parkingNode.index !== parkingNode1.index) { + var d = distance([parkingNode.lng, parkingNode.lat], + [parkingNode1.lng, parkingNode1.lat]); + if (d < parkingNode.radius + parkingNode1.radius) { + notOkNodes.push({id: parkingNode.index, message:'Intersecting node'}); + } + } + this.postMessage(['progress', 1]); + }); + }); // check1(graph); // check2(); @@ -146,6 +167,12 @@ var mapParkings = function (o) { console.log(o); } +var mapParkingNode = function (o) { + if(o.type === 'parking') + return {index: o.index, lat:o.lat, lng:o.lng, radius: Number(o.radius)}; + console.log(o); +} + var mapRunwayNodes = function (o) { if(o.type === 'runway') return o.index; diff --git a/src/renderer/utils/haversine.js b/src/renderer/utils/haversine.js new file mode 100644 index 0000000..0ce1067 --- /dev/null +++ b/src/renderer/utils/haversine.js @@ -0,0 +1,21 @@ +var earthRadius = 6371008.8; + + +function distance(point1, point2) { + var dLat = degrees_to_radians((point2[1] - point1[1])); + var dLon = degrees_to_radians((point2[0] - point1[0])); + var lat1 = degrees_to_radians(point1[1]); + var lat2 = degrees_to_radians(point2[1]); + + var a = Math.pow(Math.sin(dLat / 2), 2) + + Math.pow(Math.sin(dLon / 2), 2) * Math.cos(lat1) * Math.cos(lat2); + + return earthRadius * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); +} + +function degrees_to_radians(degrees) +{ + var pi = Math.PI; + return degrees * (pi/180); +} +