A PX4 based camera pointer

latlon_test.go 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // Copyright 2017 Google Inc.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. //
  15. package pipoint
  16. import (
  17. "fmt"
  18. "math"
  19. "testing"
  20. "github.com/stretchr/testify/assert"
  21. )
  22. func TestLatLength(t *testing.T) {
  23. // Test vectors from https://en.wikipedia.org/wiki/Latitude
  24. assert.InDelta(t, LatLength(0*math.Pi/180), 110574, 1)
  25. assert.InDelta(t, LatLength(15*math.Pi/180), 110649, 1)
  26. assert.InDelta(t, LatLength(30*math.Pi/180), 110852, 1)
  27. assert.InDelta(t, LatLength(45*math.Pi/180), 111132, 1)
  28. assert.InDelta(t, LatLength(60*math.Pi/180), 111412, 1)
  29. assert.InDelta(t, LatLength(75*math.Pi/180), 111618, 1)
  30. }
  31. func TestLonLength(t *testing.T) {
  32. // Test vectors from https://en.wikipedia.org/wiki/Latitude
  33. assert.InDelta(t, LonLength(0*math.Pi/180), 111320, 1)
  34. assert.InDelta(t, LonLength(15*math.Pi/180), 107550, 1)
  35. assert.InDelta(t, LonLength(30*math.Pi/180), 96486, 1)
  36. assert.InDelta(t, LonLength(45*math.Pi/180), 78847, 1)
  37. assert.InDelta(t, LonLength(60*math.Pi/180), 55800, 1)
  38. assert.InDelta(t, LonLength(75*math.Pi/180), 28902, 1)
  39. }
  40. func ExampleLatLength() {
  41. fmt.Println(int(LatLength(46.8 * math.Pi / 180)))
  42. // Output: 111166
  43. }