Skip to content

measure.SpheroidDistance returns NaN for some data #114

@Izolius

Description

@Izolius
func TestUnit_Measure_Nan(t *testing.T) {
	t.Parallel()
	m1 := matrix.Matrix{37.622326727937677, 55.75513948864943}
	m2 := matrix.Matrix{37.622326727937677, 55.75513948864943}
	distance := measure.SpheroidDistance(m1, m2)
	assert.True(t, math.IsNaN(distance))
}

Hello! Here is some test example that passes. For this input data measure.SpheroidDistance returns Nan.
I think the reason is rounding error of theta := lng1 - lng0. theta is actually a bit greater than zero and therefore math.Sin(lat0)*math.Sin(lat1) + math.Cos(lat0)*math.Cos(lat1)*math.Cos(theta) a bit greater than one and math.Acos(math.Sin(lat0)*math.Sin(lat1) + math.Cos(lat0)*math.Cos(lat1)*math.Cos(theta)) returns Nan.
That's what debugger shows:

Image

What I expect: function returns 0 for this case and actually never returns NaN.

I'm using github.com/spatial-go/geoos v1.1.3 but as I far as I see, v1.2 has the same code of this function

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions