From 800bb6fc53d9eb9f8db9a71ec4f09d72ae3e20da Mon Sep 17 00:00:00 2001 From: Paul Dee Date: Sat, 18 Mar 2023 12:57:18 +0100 Subject: [PATCH] Updates to LOC type RFC1876 (#1440) https://www.rfc-editor.org/rfc/rfc1876 --- types.go | 14 ++++++++------ types_test.go | 14 +++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/types.go b/types.go index 1c7dc0976..03afeccda 100644 --- a/types.go +++ b/types.go @@ -198,7 +198,7 @@ const ( _CD = 1 << 4 // checking disabled ) -// Various constants used in the LOC RR. See RFC 1887. +// Various constants used in the LOC RR. See RFC 1876. const ( LOC_EQUATOR = 1 << 31 // RFC 1876, Section 2. LOC_PRIMEMERIDIAN = 1 << 31 // RFC 1876, Section 2. @@ -792,7 +792,10 @@ type LOC struct { // cmToM takes a cm value expressed in RFC 1876 SIZE mantissa/exponent // format and returns a string in m (two decimals for the cm). -func cmToM(m, e uint8) string { +func cmToM(x uint8) string { + m := x & 0xf0 >> 4 + e := x & 0x0f + if e < 2 { if e == 1 { m *= 10 @@ -848,10 +851,9 @@ func (rr *LOC) String() string { s += fmt.Sprintf("%.0fm ", alt) } - s += cmToM(rr.Size&0xf0>>4, rr.Size&0x0f) + "m " - s += cmToM(rr.HorizPre&0xf0>>4, rr.HorizPre&0x0f) + "m " - s += cmToM(rr.VertPre&0xf0>>4, rr.VertPre&0x0f) + "m" - + s += cmToM(rr.Size) + "m " + s += cmToM(rr.HorizPre) + "m " + s += cmToM(rr.VertPre) + "m" return s } diff --git a/types_test.go b/types_test.go index b3f5583fa..32df35bf0 100644 --- a/types_test.go +++ b/types_test.go @@ -5,37 +5,37 @@ import ( ) func TestCmToM(t *testing.T) { - s := cmToM(0, 0) + s := cmToM((0 << 4) + 0) if s != "0.00" { t.Error("0, 0") } - s = cmToM(1, 0) + s = cmToM((1 << 4) + 0) if s != "0.01" { t.Error("1, 0") } - s = cmToM(3, 1) + s = cmToM((3 << 4) + 1) if s != "0.30" { t.Error("3, 1") } - s = cmToM(4, 2) + s = cmToM((4 << 4) + 2) if s != "4" { t.Error("4, 2") } - s = cmToM(5, 3) + s = cmToM((5 << 4) + 3) if s != "50" { t.Error("5, 3") } - s = cmToM(7, 5) + s = cmToM((7 << 4) + 5) if s != "7000" { t.Error("7, 5") } - s = cmToM(9, 9) + s = cmToM((9 << 4) + 9) if s != "90000000" { t.Error("9, 9") }