Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to LOC type RFC1876 #1440

Merged
merged 1 commit into from
Mar 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.
systemcrash marked this conversation as resolved.
Show resolved Hide resolved
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