github.com/liucxer/courier@v1.7.1/h3/vec3d_test.go (about) 1 package h3 2 3 import ( 4 "math" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_pointSquareDist(t *testing.T) { 11 v1 := Vec3d{0, 0, 0} 12 v2 := Vec3d{1, 0, 0} 13 v3 := Vec3d{0, 1, 1} 14 v4 := Vec3d{1, 1, 1} 15 v5 := Vec3d{1, 1, 2} 16 17 require.True(t, math.Abs(_pointSquareDist(&v1, &v1)) < math.SmallestNonzeroFloat64, "distance to self is 0") 18 require.True(t, math.Abs(_pointSquareDist(&v1, &v2)-1) < math.SmallestNonzeroFloat64, "distance to <1,0,0> is 1") 19 require.True(t, math.Abs(_pointSquareDist(&v1, &v3)-2) < math.SmallestNonzeroFloat64, "distance to <0,1,1> is 2") 20 require.True(t, math.Abs(_pointSquareDist(&v1, &v4)-3) < math.SmallestNonzeroFloat64, "distance to <1,1,1> is 3") 21 require.True(t, math.Abs(_pointSquareDist(&v1, &v5)-6) < math.SmallestNonzeroFloat64, "distance to <1,1,2> is 6") 22 } 23 24 func Test_geoToVec3d(t *testing.T) { 25 origin := Vec3d{} 26 c1 := GeoCoord{0, 0} 27 var p1 Vec3d 28 _geoToVec3d(&c1, &p1) 29 require.True(t, math.Abs(_pointSquareDist(&origin, &p1)-1) < EPSILON_RAD, "Geo point is on the unit sphere") 30 31 c2 := GeoCoord{M_PI_2, 0} 32 var p2 Vec3d 33 _geoToVec3d(&c2, &p2) 34 require.True(t, math.Abs(_pointSquareDist(&p1, &p2)-2) < EPSILON_RAD, "Geo point is on another axis") 35 36 c3 := GeoCoord{M_PI, 0} 37 var p3 Vec3d 38 _geoToVec3d(&c3, &p3) 39 require.True(t, math.Abs(_pointSquareDist(&p1, &p3)-4) < EPSILON_RAD, "Geo point is the other side of the sphere") 40 }