From e1a2c295e2bbb42d54d59472d0fe885edbba7e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Rudowicz?= Date: Sat, 14 May 2022 14:14:19 +0200 Subject: [PATCH] Fixed Maidenhead calculation --- src/maidenhead.vala | 14 +++++++------- src/tests/maidenhead_tests.vala | 12 ++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/maidenhead.vala b/src/maidenhead.vala index e4e7f15..92859b5 100644 --- a/src/maidenhead.vala +++ b/src/maidenhead.vala @@ -7,7 +7,7 @@ namespace Hamlocator { private string l2m; public LocationToMaidenhead() { - this.l2m = "abcdefghijklmnopqrstuvwxyz"; + this.l2m = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; } public string get_locator(GClue.Location pos) { @@ -15,10 +15,10 @@ namespace Hamlocator { double lon = pos.longitude + 180; // Field - double lat1 = (lat / 10) + 0.0000001; - double lon1 = (lon / 20) + 0.0000001; + double lat1 = (lat / 10); + double lon1 = (lon / 20); - string loc1 = @"$(this.l2m[Math.lround(Math.floor(lon1))])$(this.l2m[Math.lround(Math.floor(lat1))])".up(); + string loc1 = @"$(this.l2m[Math.lround(Math.floor(lon1))])$(this.l2m[Math.lround(Math.floor(lat1))])"; // Square double lat2 = 10 * (lat1 - Math.floor(lat1)); @@ -27,10 +27,10 @@ namespace Hamlocator { string loc2 = @"$(Math.lround(Math.floor(lon2)))$(Math.lround(Math.floor(lat2)))"; // Subsquare - double lat3 = 24 * (lat1 - Math.floor(lat1)); - double lon3 = 24 * (lon1 - Math.floor(lon1)); + double lat3 = 24 * (lat2 - Math.floor(lat2)); + double lon3 = 24 * (lon2 - Math.floor(lon2)); - string loc3 = @"$(this.l2m[Math.lround(Math.floor(lon3))])$(this.l2m[Math.lround(Math.floor(lat3))])"; + string loc3 = @"$(this.l2m[Math.lround(Math.floor(lon3))])$(this.l2m[Math.lround(Math.floor(lat3))])".down(); return @"$loc1$loc2$loc3"; } diff --git a/src/tests/maidenhead_tests.vala b/src/tests/maidenhead_tests.vala index 78d2b3a..d7a63c2 100644 --- a/src/tests/maidenhead_tests.vala +++ b/src/tests/maidenhead_tests.vala @@ -11,6 +11,18 @@ public class MaidenheadTests : TestCase { add_test_location(90.0, -180.0, "AS00aa"); add_test_location(-90.0, 180.0, "SA00aa"); + add_test_location(51.0, 17.0, "JO80lx"); + add_test_location(51.1, 17.1, "JO81nc"); + add_test_location(51.2, 17.2, "JO81oe"); + add_test_location(51.3, 17.3, "JO81ph"); + add_test_location(51.4, 17.4, "JO81qj"); + add_test_location(51.5, 17.5, "JO81sm"); + add_test_location(51.6, 17.6, "JO81to"); + add_test_location(51.7, 17.7, "JO81uq"); + add_test_location(51.8, 17.8, "JO81vt"); + add_test_location(51.9, 17.9, "JO81wv"); + add_test_location(51.99, 17.99, "JO81xx"); + add_test_location(51.1205, 17.0261, "JO81mc"); add_test_location(37.1104, -5.4932, "IM77gc"); add_test_location(-30.5377, 22.8516, "KF19kl");