SHARE
TWEET

Untitled

a guest Oct 23rd, 2019 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include "trackpoint.h"
  5. #include "track.h"
  6. typedef struct segment
  7. {
  8.   trackpoint * trackpoints;
  9.   double total_distance;
  10.   int num_trackpoints;
  11.  
  12. }segment;
  13. struct track
  14. {
  15.   segment * segments;
  16.   int num_segments;
  17. };
  18. track *track_create()
  19. {
  20.   track *t = malloc(sizeof(track));
  21.   if (t != NULL)
  22.   {
  23.     t->segments[0] = malloc(sizeof(trackpoint *));
  24.   }
  25.   return t;
  26. }
  27. void track_destroy(track *trk)
  28. {
  29.   if (trk != NULL)
  30.   {
  31.     for(int i = 0; i < trk->num_segments; i++)
  32.     {
  33.       // for(int j = 0; j < trk->num_segments[i]->num_trackpoints; j++)
  34.       // {
  35.       //   free(trk->segments[i]->trackpoints[j]);
  36.       // }
  37.       free(trk->segments[i]);
  38.     }
  39.     free(trk);
  40.   }
  41. }
  42. int track_count_segments(const track *trk)
  43. {
  44.   if(trk->segments[0] != NULL)
  45.   {
  46.     return trk->num_segments;
  47.   }
  48.   return 0;
  49. }
  50. int track_count_points(const track *trk, int i)
  51. {
  52.   if(trk->segments[i]->trackpoints[0] != NULL)
  53.   {
  54.     return trk->segments[i]->num_trackpoints;
  55.   }
  56.   return 0;
  57. }
  58. trackpoint *track_get_point(const track *trk, int i, int j)
  59. {
  60.   trackpoint * trkpoint_cpy = malloc(sizeof(trackpoint));
  61.   if(trk->segments[i] != NULL && trk->segments[i].trackpoints[j] != NULL)
  62.   {
  63.     *trkpoint_cpy = trk->segments[i]->trackpoints[j];
  64.     return trkpoint_cpy;
  65.   }
  66.   return NULL;
  67. }
  68. double *track_get_lengths(const track *trk)
  69. {
  70.   trackpoint * arr = malloc(sizeof(trackpoint) * trk->num_segments);
  71.   for(int i = 0; i < trk->num_segments; i++)
  72.   {
  73.     arr[i] = trk->segments[i].total_distance;
  74.   }
  75.   return arr;
  76. }
  77. bool track_add_point(track *trk, const trackpoint *pt)
  78. {
  79.  
  80. }
  81. void track_start_segment(track *trk)
  82. {
  83.  
  84. }
  85. void track_merge_segments(track *trk, int start, int end)
  86. {
  87.  
  88. }
  89. void track_heatmap(const track *trk, double cell_width, double cell_height, int ***map, int *rows, int *cols)
  90. {
  91.  
  92. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top