]> Pileus Git - grits/commitdiff
Fix up primitive datatypes
authorAndy Spencer <andy753421@gmail.com>
Wed, 10 Feb 2010 12:27:19 +0000 (12:27 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 10 Feb 2010 12:27:19 +0000 (12:27 +0000)
- Move GisPoint to gis-util.[ch]
- Add a GisBBox for n,s,e,w coords

src/gis-util.c
src/gis-util.h
src/objects/gis-object.c
src/objects/gis-object.h
src/objects/gis-tile.c
src/objects/gis-tile.h
src/plugins/elev.c
src/plugins/map.c
src/plugins/sat.c

index 587dd5c10d26e3418a1d80b0ef6c282d37117011..951b45219aff7b5a733e890cf9459320f40c6302 100644 (file)
 
 #include "gis-util.h"
 
 
 #include "gis-util.h"
 
+/************
+ * GisPoint *
+ ************/
+/**
+ * gis_point_set_lle:
+ * @point: the point to modify
+ * @lat:   the new latitude
+ * @lon:   the new longitude
+ * @elev:  the new elevation
+ *
+ * Set the latitude, longitude, and elevation for a point.
+ */
+void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev)
+{
+       point->lat  = lat;
+       point->lon  = lon;
+       point->elev = elev;
+}
+
+
+/***********
+ * GisBBox *
+ ***********/
+/**
+ * gis_bbox_set_bounds:
+ * @n: the north edge
+ * @s: the south edge
+ * @e: the east edge
+ * @w: the west edge
+ *
+ * Set the north, south, east, and west edges of the bounding box
+ */
+void gis_bbox_set_bounds(GisBBox *bbox,
+               gdouble n, gdouble s, gdouble e, gdouble w)
+{
+       bbox->n = n;
+       bbox->s = s;
+       bbox->e = e;
+       bbox->w = w;
+}
+
+
 /******************
  * Global helpers *
  ******************/
 /******************
  * Global helpers *
  ******************/
index c7838966709f9c74f8cb5a3de23b54f9b486280f..1b03f2fa578ff1c314b8f6d9886c1a98dbe56d21 100644 (file)
 #define rad2deg(rad) (((rad)*180.0)/G_PI)
 
 
 #define rad2deg(rad) (((rad)*180.0)/G_PI)
 
 
+/*************
+ * Datatypes *
+ *************/
+
+/* GisPoint */
+typedef struct _GisPoint GisPoint;
+struct _GisPoint {
+       gdouble lat, lon, elev;
+};
+
+void gis_point_set_lle(GisPoint *point,
+               gdouble lat, gdouble lon, gdouble elev);
+
+/* GisBBox */
+typedef struct _GisBBox GisBBox;
+struct _GisBBox {
+       gdouble n, s, e, w;
+};
+
+void gis_bbox_set_bounds(GisBBox *bbox,
+               gdouble n, gdouble s, gdouble e, gdouble w);
+
+
 /********
  * Misc *
  ********/
 /********
  * Misc *
  ********/
index 84e5c4722eb3d07af753736cac19f80e2b8921a1..9eff935f2efae3f0df77622f3fc7e029299faa46 100644 (file)
@@ -17,7 +17,7 @@
 
 /**
  * SECTION:gis-object
 
 /**
  * SECTION:gis-object
- * @short_description: Base classes for drawing operations
+ * @short_description: Base class for drawing operations
  *
  * Objects in libgis are things which can be added to the viewer and will be
  * displayed to the user. Each object has information such as it's location and
  *
  * Objects in libgis are things which can be added to the viewer and will be
  * displayed to the user. Each object has information such as it's location and
 #include <config.h>
 #include "gis-object.h"
 
 #include <config.h>
 #include "gis-object.h"
 
-/************
- * GisPoint *
- ************/
-/**
- * gis_point_new:
- *
- * Create a new #GisPoint
- *
- * Returns: the new point
- */
-GisPoint *gis_point_new()
-{
-       return g_new0(GisPoint, 1);
-}
-
-/**
- * gis_point_set_lle:
- * @point: the point to modify
- * @lat:   the new latitude
- * @lon:   the new longitude
- * @elev:  the new elevation
- *
- * Set the latitude, longitude, and elevation for a point.
- */
-void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev)
-{
-       point->lat  = lat;
-       point->lon  = lon;
-       point->elev = elev;
-}
-
-/**
- * gis_point_free:
- * @point: The point to free
- *
- * Free data used by a #GisPoint
- */
-void gis_point_free(GisPoint *point)
-{
-       g_free(point);
-}
-
 
 /*************
  * GisObject *
 
 /*************
  * GisObject *
index 4f105d80a1f7a25f1a2c8304553e9878629f2ee3..1777fce1fb27713af276971c95f929876a2ef593 100644 (file)
 
 #include <glib.h>
 #include <glib-object.h>
 
 #include <glib.h>
 #include <glib-object.h>
-
-/* GisPoint */
-typedef struct _GisPoint GisPoint;
-
-struct _GisPoint {
-       gdouble lat, lon, elev;
-};
-
-GisPoint *gis_point_new();
-void gis_point_set_lle(GisPoint *point, gdouble lat, gdouble lon, gdouble elev);
-void gis_point_free(GisPoint *point);
-
+#include "gis-util.h"
 
 /* GisObject */
 #define GIS_TYPE_OBJECT            (gis_object_get_type())
 
 /* GisObject */
 #define GIS_TYPE_OBJECT            (gis_object_get_type())
index 9a2a29886a4277ad90b2a503948dbf90a592c72d..24214ade125a4434a4871661879c6652c6a27cb0 100644 (file)
@@ -33,7 +33,6 @@
  */
 
 #include <config.h>
  */
 
 #include <config.h>
-#include "gis-util.h"
 #include "gis-tile.h"
 
 gchar *gis_tile_path_table[2][2] = {
 #include "gis-tile.h"
 
 gchar *gis_tile_path_table[2][2] = {
@@ -58,11 +57,8 @@ GisTile *gis_tile_new(GisTile *parent,
 {
        GisTile *tile = g_object_new(GIS_TYPE_TILE, NULL);
        tile->parent = parent;
 {
        GisTile *tile = g_object_new(GIS_TYPE_TILE, NULL);
        tile->parent = parent;
-       tile->edge.n = n;
-       tile->edge.s = s;
-       tile->edge.e = e;
-       tile->edge.w = w;
        tile->atime  = time(NULL);
        tile->atime  = time(NULL);
+       gis_bbox_set_bounds(&tile->edge, n, s, e, w);
        return tile;
 }
 
        return tile;
 }
 
@@ -93,38 +89,35 @@ gchar *gis_tile_get_path(GisTile *child)
        return g_string_free(path, FALSE);
 }
 
        return g_string_free(path, FALSE);
 }
 
-static gdouble _gis_tile_get_min_dist(
-               gdouble lat, gdouble lon, gdouble elev,
-               gdouble n, gdouble s, gdouble e, gdouble w)
+static gdouble _gis_tile_get_min_dist(GisPoint *eye, GisBBox *bounds)
 {
 {
-       gdouble tlat  = lat > n ? n :
-                       lat < s ? s : lat;
-       gdouble tlon  = lon > e ? e :
-                       lon < w ? w : lon;
-       gdouble telev = 0; // TODO: elevation at rlat,rlon
-       //if (lat == tlat && lon == tlon)
+       GisPoint pos = {};
+       pos.lat = eye->lat > bounds->n ? bounds->n :
+                 eye->lat < bounds->s ? bounds->s : eye->lat;
+       pos.lon = eye->lon > bounds->e ? bounds->e :
+                 eye->lon < bounds->w ? bounds->w : eye->lon;
+       //if (eye->lat == pos.lat && eye->lon == pos.lon)
        //      return elev; /* Shortcut? */
        gdouble a[3], b[3];
        //      return elev; /* Shortcut? */
        gdouble a[3], b[3];
-       lle2xyz( lat,  lon,  elev, a+0, a+1, a+2);
-       lle2xyz(tlat, tlon, telev, b+0, b+1, b+2);
+       lle2xyz(eye->lat, eye->lon, eye->elev, a+0, a+1, a+2);
+       lle2xyz(pos.lat,  pos.lon,  pos.elev,  b+0, b+1, b+2);
        return distd(a, b);
 }
 
        return distd(a, b);
 }
 
-static gboolean _gis_tile_precise(
-               gdouble lat, gdouble lon, gdouble elev,
-               gdouble n, gdouble s, gdouble e, gdouble w,
+static gboolean _gis_tile_precise(GisPoint *eye, GisBBox *bounds,
                gdouble max_res, gint width, gint height)
 {
                gdouble max_res, gint width, gint height)
 {
-       gdouble min_dist  = _gis_tile_get_min_dist(lat, lon, elev, n, s, e, w);
+       gdouble min_dist  = _gis_tile_get_min_dist(eye, bounds);
        gdouble view_res  = MPPX(min_dist);
 
        gdouble view_res  = MPPX(min_dist);
 
-       gdouble lat_point = n < 0 ? n : s > 0 ? s : 0;
-       gdouble lon_dist  = e - w;
+       gdouble lat_point = bounds->n < 0 ? bounds->n :
+                           bounds->s > 0 ? bounds->s : 0;
+       gdouble lon_dist  = bounds->e - bounds->w;
        gdouble tile_res  = ll2m(lon_dist, lat_point)/width;
 
        /* This isn't really right, but it helps with memory since we don't (yet?) test if the tile
         * would be drawn */
        gdouble tile_res  = ll2m(lon_dist, lat_point)/width;
 
        /* This isn't really right, but it helps with memory since we don't (yet?) test if the tile
         * would be drawn */
-       gdouble scale = elev / min_dist;
+       gdouble scale = eye->elev / min_dist;
        view_res /= scale;
        //view_res /= 1.4; /* make it a little nicer, not sure why this is needed */
        //g_message("tile=(%7.2f %7.2f %7.2f %7.2f) "
        view_res /= scale;
        //view_res /= 1.4; /* make it a little nicer, not sure why this is needed */
        //g_message("tile=(%7.2f %7.2f %7.2f %7.2f) "
@@ -141,12 +134,10 @@ static gboolean _gis_tile_precise(
 /**
  * gis_tile_update:
  * @root:      the root tile to split
 /**
  * gis_tile_update:
  * @root:      the root tile to split
+ * @eye:       the point the tile is viewed from, for calculating distances
  * @res:       a maximum resolution in meters per pixel to split tiles to
  * @width:     width in pixels of the image associated with the tile
  * @height:    height in pixels of the image associated with the tile
  * @res:       a maximum resolution in meters per pixel to split tiles to
  * @width:     width in pixels of the image associated with the tile
  * @height:    height in pixels of the image associated with the tile
- * @lat:       latitude of the eye point
- * @lon:       longitude of the eye point
- * @elev:      elevation of the eye point
  * @load_func: function used to load the image when a new tile is created
  * @user_data: user data to past to the load function
  *
  * @load_func: function used to load the image when a new tile is created
  * @user_data: user data to past to the load function
  *
@@ -156,9 +147,8 @@ static gboolean _gis_tile_precise(
  * the tile is recursively subdivided until a sufficient resolution is
  * achieved.
  */
  * the tile is recursively subdivided until a sufficient resolution is
  * achieved.
  */
-void gis_tile_update(GisTile *root,
+void gis_tile_update(GisTile *root, GisPoint *eye,
                gdouble res, gint width, gint height,
                gdouble res, gint width, gint height,
-               gdouble lat, gdouble lon, gdouble elev,
                GisTileLoadFunc load_func, gpointer user_data)
 {
        root->atime = time(NULL);
                GisTileLoadFunc load_func, gpointer user_data)
 {
        root->atime = time(NULL);
@@ -173,19 +163,20 @@ void gis_tile_update(GisTile *root,
        int row, col;
        gis_tile_foreach_index(root, row, col) {
                GisTile **child = &root->children[row][col];
        int row, col;
        gis_tile_foreach_index(root, row, col) {
                GisTile **child = &root->children[row][col];
-               const gdouble n = root->edge.n-(lat_step*(row+0));
-               const gdouble s = root->edge.n-(lat_step*(row+1));
-               const gdouble e = root->edge.w+(lon_step*(col+1));
-               const gdouble w = root->edge.w+(lon_step*(col+0));
-               if (!_gis_tile_precise(lat,lon,elev, n,s,e,w,
-                                       res,width/cols,height/rows)) {
+               GisBBox edge;
+               edge.n = root->edge.n-(lat_step*(row+0));
+               edge.s = root->edge.n-(lat_step*(row+1));
+               edge.e = root->edge.w+(lon_step*(col+1));
+               edge.w = root->edge.w+(lon_step*(col+0));
+               if (!_gis_tile_precise(eye, &edge, res,
+                                       width/cols, height/rows)) {
                        if (!*child) {
                        if (!*child) {
-                               *child = gis_tile_new(root, n,s,e,w);
+                               *child = gis_tile_new(root, edge.n, edge.s,
+                                               edge.e, edge.w);
                                load_func(*child, user_data);
                        }
                                load_func(*child, user_data);
                        }
-                       gis_tile_update(*child,
+                       gis_tile_update(*child, eye,
                                        res, width, height,
                                        res, width, height,
-                                       lat, lon, elev,
                                        load_func, user_data);
                }
        }
                                        load_func, user_data);
                }
        }
index 98052c69abb821d4f7b2634891e59abc523f8f7d..4ebf7ef190ac3a8d731431c7046fd3cf8f4e5a2c 100644 (file)
@@ -39,9 +39,7 @@ struct _GisTile {
        gpointer data;
 
        /* North,South,East,West limits */
        gpointer data;
 
        /* North,South,East,West limits */
-       struct {
-               gdouble n,s,e,w;
-       } edge;
+       GisBBox edge;
 
        /* Pointers to parent/child nodes */
        GisTile *parent;
 
        /* Pointers to parent/child nodes */
        GisTile *parent;
@@ -112,10 +110,9 @@ GisTile *gis_tile_new(GisTile *parent,
 gchar *gis_tile_get_path(GisTile *child);
 
 /* Update a root tile */
 gchar *gis_tile_get_path(GisTile *child);
 
 /* Update a root tile */
-/* Based on eye distance (lat,lon,elev) */
-void gis_tile_update(GisTile *root,
+/* Based on eye distance */
+void gis_tile_update(GisTile *root, GisPoint *eye,
                gdouble res, gint width, gint height,
                gdouble res, gint width, gint height,
-               gdouble lat, gdouble lon, gdouble elev,
                GisTileLoadFunc load_func, gpointer user_data);
 
 /* Find the leaf tile containing lat-lon */
                GisTileLoadFunc load_func, gpointer user_data);
 
 /* Find the leaf tile containing lat-lon */
index 9279b08190ca9c6e1ec314077b2e4cc52d26da73..a8f9df1ac89264e88a49c7ee2ab9bee2357d07c4 100644 (file)
@@ -248,11 +248,10 @@ static gpointer _update_tiles(gpointer _elev)
        GisPluginElev *elev = _elev;
        if (!g_mutex_trylock(elev->mutex))
                return NULL;
        GisPluginElev *elev = _elev;
        if (!g_mutex_trylock(elev->mutex))
                return NULL;
-       gdouble lat, lon, elevation;
-       gis_viewer_get_location(elev->viewer, &lat, &lon, &elevation);
-       gis_tile_update(elev->tiles,
+       GisPoint eye;
+       gis_viewer_get_location(elev->viewer, &eye.lat, &eye.lon, &eye.elev);
+       gis_tile_update(elev->tiles, &eye,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
-                       lat, lon, elevation,
                        _load_tile, elev);
        gis_tile_gc(elev->tiles, time(NULL)-10,
                        _free_tile, elev);
                        _load_tile, elev);
        gis_tile_gc(elev->tiles, time(NULL)-10,
                        _free_tile, elev);
index 7a2d66d373f91d7d6d6daeb0a6e6ef101767bef7..0ae8ef6c411fadf497d7fa426547c8114a2f781b 100644 (file)
@@ -136,11 +136,10 @@ static gpointer _update_tiles(gpointer _map)
        GisPluginMap *map = _map;
        if (!g_mutex_trylock(map->mutex))
                return NULL;
        GisPluginMap *map = _map;
        if (!g_mutex_trylock(map->mutex))
                return NULL;
-       gdouble lat, lon, elev;
-       gis_viewer_get_location(map->viewer, &lat, &lon, &elev);
-       gis_tile_update(map->tiles,
+       GisPoint eye;
+       gis_viewer_get_location(map->viewer, &eye.lat, &eye.lon, &eye.elev);
+       gis_tile_update(map->tiles, &eye,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
-                       lat, lon, elev,
                        _load_tile, map);
        gis_tile_gc(map->tiles, time(NULL)-10,
                        _free_tile, map);
                        _load_tile, map);
        gis_tile_gc(map->tiles, time(NULL)-10,
                        _free_tile, map);
index 1af0bfc7c4e0490884756f53512ae3f27b43c59d..66150be765791ecd401fa09975ee9d7bc7f1846d 100644 (file)
@@ -127,11 +127,10 @@ static gpointer _update_tiles(gpointer _sat)
        GisPluginSat *sat = _sat;
        if (!g_mutex_trylock(sat->mutex))
                return NULL;
        GisPluginSat *sat = _sat;
        if (!g_mutex_trylock(sat->mutex))
                return NULL;
-       gdouble lat, lon, elev;
-       gis_viewer_get_location(sat->viewer, &lat, &lon, &elev);
-       gis_tile_update(sat->tiles,
+       GisPoint eye;
+       gis_viewer_get_location(sat->viewer, &eye.lat, &eye.lon, &eye.elev);
+       gis_tile_update(sat->tiles, &eye,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
                        MAX_RESOLUTION, TILE_WIDTH, TILE_WIDTH,
-                       lat, lon, elev,
                        _load_tile, sat);
        gis_tile_gc(sat->tiles, time(NULL)-10,
                        _free_tile, sat);
                        _load_tile, sat);
        gis_tile_gc(sat->tiles, time(NULL)-10,
                        _free_tile, sat);