Skip to content

Commit

Permalink
Updates to LOC type RFC1876 (#1440)
Browse files Browse the repository at this point in the history
  • Loading branch information
systemcrash authored Mar 18, 2023
1 parent 4c50fd8 commit 800bb6f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
14 changes: 8 additions & 6 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 800bb6f

Please sign in to comment.