Skip to content

Commit

Permalink
Added a length function to the track that returns the great circle le…
Browse files Browse the repository at this point in the history
…ngth in meters.
  • Loading branch information
Samuel Cowen committed Jun 4, 2014
1 parent ee722bf commit e7db3ed
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/editable_tracks.c
Expand Up @@ -52,7 +52,7 @@ static int click_down_y = 0;
static gboolean
on_track_changed(GtkWidget* widget)
{
printf("track has been edited\n");
printf("new track length: %f\n", osm_gps_map_track_get_length(maptrack));
}

static gboolean
Expand Down
23 changes: 23 additions & 0 deletions src/osm-gps-map-track.c
Expand Up @@ -29,6 +29,7 @@
**/

#include <gdk/gdk.h>
#include <math.h>

#include "converter.h"
#include "osm-gps-map-track.h"
Expand Down Expand Up @@ -342,6 +343,28 @@ osm_gps_map_track_get_color (OsmGpsMapTrack *track, GdkRGBA *color)
color->blue = track->priv->color.blue;
}

double
osm_gps_map_track_get_length(OsmGpsMapTrack* track)
{
GSList* points = track->priv->track;
double ret = 0;
OsmGpsMapPoint* point_a = NULL;
OsmGpsMapPoint* point_b = NULL;

while(points)
{
point_a = point_b;
point_b = points->data;
if(point_a)
{
ret += acos(sin(point_a->rlat)*sin(point_b->rlat)
+ cos(point_a->rlat)*cos(point_b->rlat)*cos(point_b->rlon-point_a->rlon)) * 6371109; //the mean raduis of earth
}
points = points->next;
}
return ret;
}


OsmGpsMapTrack *
osm_gps_map_track_new (void)
Expand Down
18 changes: 18 additions & 0 deletions src/osm-gps-map-track.h
Expand Up @@ -80,11 +80,29 @@ void osm_gps_map_track_add_point (OsmGpsMapTrack *track, cons
GSList * osm_gps_map_track_get_points (OsmGpsMapTrack *track);
void osm_gps_map_track_get_color (OsmGpsMapTrack *track, GdkRGBA *color);

/**
* osm_gps_map_track_remove_point:
* @track (in): a #OsmGpsMapTrack
* @pos: Position of the point to remove
*
**/
void osm_gps_map_track_remove_point(OsmGpsMapTrack* track, int pos);

/**
*
**/
int osm_gps_map_track_n_points(OsmGpsMapTrack* track);
void osm_gps_map_track_insert_point(OsmGpsMapTrack* track, OsmGpsMapPoint* np, int pos);
OsmGpsMapPoint* osm_gps_map_track_get_point(OsmGpsMapTrack* track, int pos);

/**
* osm_gps_map_track_get_length:
* @track (in): a #OsmGpsMapTrack
*
* Returns: the length of the track in meters.
**/
double osm_gps_map_track_get_length(OsmGpsMapTrack* track);


G_END_DECLS

Expand Down

0 comments on commit e7db3ed

Please sign in to comment.