From 77edb72d2c57d60bc320c4c5e55f077d53a6add7 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 23 Aug 2023 14:22:20 +0200 Subject: [PATCH 1/3] Handle VUCC grid lines and corners in Qrb mapping --- application/libraries/Qra.php | 44 ++++++++++++++++++++++------------- assets/js/sections/common.js | 6 ++--- 2 files changed, 31 insertions(+), 19 deletions(-) diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index db55dc93..5dadc311 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -23,12 +23,6 @@ class Qra { // calculate the bearing between two squares function bearing($tx, $rx, $unit = 'M') { - if(strlen($tx) > 6) { - $tx = substr($tx, 0, 6); - } - if(strlen($rx) > 6) { - $rx = substr($rx, 0, 6); - } $my = qra2latlong($tx); $stn = qra2latlong($rx); @@ -44,12 +38,6 @@ class Qra { * */ function distance($tx, $rx, $unit = 'M') { - if(strlen($tx) > 6) { - $tx = substr($tx, 0, 6); - } - if(strlen($rx) > 6) { - $rx = substr($rx, 0, 6); - } // Calc LatLongs $my = qra2latlong($tx); $stn = qra2latlong($rx); @@ -176,9 +164,34 @@ function get_bearing($lat1, $lon1, $lat2, $lon2) { } function qra2latlong($strQRA) { - if (strpos($strQRA, ',') !== false) { - $gridsquareArray = explode(',', $strQRA); - $strQRA = $gridsquareArray[0]; + if (substr_count($strQRA, ',') == 3) { + // Handle grid corners + $grids = explode(',', $strQRA); + $coords = array(0, 0); + for($i=0; $i<4; $i++) { + $cornercoords[$i] = qra2latlong($grids[$i]); + $coords[0] += $cornercoords[$i][0]; + $coords[1] += $cornercoords[$i][1]; + } + return array (round($coords[0]/4), round($coords[1]/4)); + } else if (substr_count($strQRA, ',') == 1) { + // Handle grid lines + $grids = explode(',', $strQRA); + $coords = array(0, 0); + for($i=0; $i<2; $i++) { + $linecoords[$i] = qra2latlong($grids[$i]); + } + if ($linecoords[0][0] != $linecoords[1][0]) { + $coords[0] = round((($linecoords[0][0] + $linecoords[1][0]) / 2),1); + } else { + $coords[0] = round($linecoords[0][0],1); + } + if ($linecoords[0][1] != $linecoords[1][1]) { + $coords[1] = round(($linecoords[0][1] + $linecoords[1][1]) / 2); + } else { + $coords[1] = round($linecoords[0][1]); + } + return $coords; } if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 8)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8 @@ -200,7 +213,6 @@ function qra2latlong($strQRA) { $g = ord($g) - ord('0'); $h = ord($h) - ord('0'); - $nLong = ($a*20) + ($c*2) + (($e+0.5)/12) + (($g-5)/120) - 180; // the 4th pair is "in the middle", so we've to substract 5 $nLat = ($b*10) + $d + (($f+0.5)/24) + (($h-5)/240) - 90; diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 265f27f1..4606da55 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -345,13 +345,13 @@ function calculateQrb() { data: {'locator1': locator1, 'locator2': locator2}, success: function (html) { - + var result = "
Negative latitudes are south of the equator, negative longitudes are west of Greenwich.
"; result += ' ' + locator1.toUpperCase() + ' Latitude = ' + html['latlng1'][0] + ' Longitude = ' + html['latlng1'][1] + '
'; result += ' ' + locator2.toUpperCase() + ' Latitude = ' + html['latlng2'][0] + ' Longitude = ' + html['latlng2'][1] + '
'; result += 'Distance between ' + locator1.toUpperCase() + ' and ' + locator2.toUpperCase() + ' is ' + html['distance'] + '.
'; result += 'The bearing is ' + html['bearing'] + '.
'; - + $(".qrbResult").html(result); newpath(html['latlng1'], html['latlng2'], locator1, locator2); } @@ -365,7 +365,7 @@ function validateLocator(locator) { if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) { return false; } - + return true; } From 61e24616460bbd8e3cb2370904498254ad3ec671 Mon Sep 17 00:00:00 2001 From: phl0 Date: Wed, 23 Aug 2023 14:48:49 +0200 Subject: [PATCH 2/3] Add an exit for the case 2 or more than 3 commans exist in grid --- application/libraries/Qra.php | 56 +++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/application/libraries/Qra.php b/application/libraries/Qra.php index 5dadc311..a9122c29 100644 --- a/application/libraries/Qra.php +++ b/application/libraries/Qra.php @@ -164,34 +164,38 @@ function get_bearing($lat1, $lon1, $lat2, $lon2) { } function qra2latlong($strQRA) { - if (substr_count($strQRA, ',') == 3) { - // Handle grid corners - $grids = explode(',', $strQRA); - $coords = array(0, 0); - for($i=0; $i<4; $i++) { - $cornercoords[$i] = qra2latlong($grids[$i]); - $coords[0] += $cornercoords[$i][0]; - $coords[1] += $cornercoords[$i][1]; - } - return array (round($coords[0]/4), round($coords[1]/4)); - } else if (substr_count($strQRA, ',') == 1) { - // Handle grid lines - $grids = explode(',', $strQRA); - $coords = array(0, 0); - for($i=0; $i<2; $i++) { - $linecoords[$i] = qra2latlong($grids[$i]); - } - if ($linecoords[0][0] != $linecoords[1][0]) { - $coords[0] = round((($linecoords[0][0] + $linecoords[1][0]) / 2),1); + if (substr_count($strQRA, ',') > 0) { + if (substr_count($strQRA, ',') == 3) { + // Handle grid corners + $grids = explode(',', $strQRA); + $coords = array(0, 0); + for($i=0; $i<4; $i++) { + $cornercoords[$i] = qra2latlong($grids[$i]); + $coords[0] += $cornercoords[$i][0]; + $coords[1] += $cornercoords[$i][1]; + } + return array (round($coords[0]/4), round($coords[1]/4)); + } else if (substr_count($strQRA, ',') == 1) { + // Handle grid lines + $grids = explode(',', $strQRA); + $coords = array(0, 0); + for($i=0; $i<2; $i++) { + $linecoords[$i] = qra2latlong($grids[$i]); + } + if ($linecoords[0][0] != $linecoords[1][0]) { + $coords[0] = round((($linecoords[0][0] + $linecoords[1][0]) / 2),1); + } else { + $coords[0] = round($linecoords[0][0],1); + } + if ($linecoords[0][1] != $linecoords[1][1]) { + $coords[1] = round(($linecoords[0][1] + $linecoords[1][1]) / 2); + } else { + $coords[1] = round($linecoords[0][1]); + } + return $coords; } else { - $coords[0] = round($linecoords[0][0],1); + return false; } - if ($linecoords[0][1] != $linecoords[1][1]) { - $coords[1] = round(($linecoords[0][1] + $linecoords[1][1]) / 2); - } else { - $coords[1] = round($linecoords[0][1]); - } - return $coords; } if ((strlen($strQRA) % 2 == 0) && (strlen($strQRA) <= 8)) { // Check if QRA is EVEN (the % 2 does that) and smaller/equal 8 From 2bd09d31e17068c60b1debe1c03ad79b16262e45 Mon Sep 17 00:00:00 2001 From: phl0 Date: Thu, 24 Aug 2023 18:12:55 +0200 Subject: [PATCH 3/3] Check for invalid grids in qrbCalc --- assets/js/sections/common.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/assets/js/sections/common.js b/assets/js/sections/common.js index 4606da55..158b1228 100644 --- a/assets/js/sections/common.js +++ b/assets/js/sections/common.js @@ -362,6 +362,10 @@ function calculateQrb() { } function validateLocator(locator) { + vucc_gridno = locator.split(",").length; + if(vucc_gridno == 3 || vucc_gridno > 4) { + return false; + } if(locator.length < 4 && !(/^[a-rA-R]{2}[0-9]{2}[a-xA-X]{0,2}[0-9]{0,2}[a-xA-X]{0,2}$/.test(locator))) { return false; }