geoos icon indicating copy to clipboard operation
geoos copied to clipboard

measure.SpheroidDistance returns NaN for some data

Open Izolius opened this issue 8 months ago • 0 comments

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

Izolius avatar May 22 '25 05:05 Izolius