File: coordinate.c

package info (click to toggle)
libshumate 1.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 7,836 kB
  • sloc: ansic: 21,756; xml: 38; makefile: 18; javascript: 10
file content (50 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#undef G_DISABLE_ASSERT

#include <gtk/gtk.h>
#include <shumate/shumate.h>

#define ACCEPTABLE_EPSILON 0.0000000000001

static void
test_coordinate_convert (void)
{
  ShumateMapSourceRegistry *registry;
  ShumateMapSource *source;
  double latitude = -73.75f;
  double longitude = 45.466f;
  double zoom_level;

  registry = shumate_map_source_registry_new_with_defaults ();

  g_assert_nonnull (registry);

  source = shumate_map_source_registry_get_by_id (registry, SHUMATE_MAP_SOURCE_OSM_MAPNIK);

  g_assert_nonnull (source);
  
  for (zoom_level = shumate_map_source_get_min_zoom_level (source);
       zoom_level <= shumate_map_source_get_max_zoom_level (source);
       zoom_level += 0.5)
    {
      double x;
      double y;

      x = shumate_map_source_get_x (source, zoom_level, longitude);
      g_assert_cmpfloat_with_epsilon (shumate_map_source_get_longitude (source, zoom_level, x), longitude, ACCEPTABLE_EPSILON);

      y = shumate_map_source_get_y (source, zoom_level, latitude);
      g_assert_cmpfloat_with_epsilon (shumate_map_source_get_latitude (source, zoom_level, y), latitude, ACCEPTABLE_EPSILON);
    }

  g_object_unref (registry);
}

int
main (int argc, char *argv[])
{
  g_test_init (&argc, &argv, NULL);

  g_test_add_func ("/coordinate/convert", test_coordinate_convert);

  return g_test_run ();
}