X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/ddc47a46f3a6b10f73c527d63beeaa0b18db980f..700b0908d71f64c9449ba372d0b9a8363257afb1:/src/viktrack.c diff --git a/src/viktrack.c b/src/viktrack.c index 9bbea58f..dc87516f 100644 --- a/src/viktrack.c +++ b/src/viktrack.c @@ -452,6 +452,30 @@ void compute_spline(int n, double *x, double *f, spline_coeff_t *p) { double *h, *alpha, *B, *m; int i; + int orig_n = n; + double new_x[3], new_f[3]; + + if (n==0) return; + if (n==1) { + new_x[0] = x[0]; + new_f[0] = f[0]; + new_x[1] = x[0]+0.00001; + new_f[1] = f[0]; + x = new_x; + f = new_f; + n = 3; + } + if (n==2) { + new_x[0] = x[0]; + new_f[0] = f[0]; + new_x[1] = x[1]; + new_f[1] = f[1]; + new_x[2] = x[1] + x[1]-x[0]; + new_f[2] = f[1] + f[1]-f[0]; + x = new_x; + f = new_f; + n = 3; + } /* we're solving a linear system of equations of the form Ax = B. * The matrix a is tridiagonal and consists of coefficients in @@ -495,7 +519,7 @@ void compute_spline(int n, double *x, double *f, spline_coeff_t *p) m[i] = (B[i]-h[i+1]*m[i+1])/alpha[i]; } - for (i=0; itrackpoints ) return NULL; g_assert ( num_chunks < 16000 ); +#ifdef XXXXXXXXXXXXXXXXXX + iter = tr->trackpoints; + while (iter) { + + } +#endif /*XXXXXXXXXXXXXXXXXX*/ + t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp; t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp; duration = t2 - t1; @@ -601,15 +633,15 @@ gdouble *vik_track_make_speed_map ( const VikTrack *tr, guint16 num_chunks ) } /* by Alex Foobarian */ -VikCoord *vik_track_get_closest_tp_by_percentage_dist ( VikTrack *tr, gdouble reldist ) +VikTrackpoint *vik_track_get_closest_tp_by_percentage_dist ( VikTrack *tr, gdouble reldist ) { gdouble dist = vik_track_get_length_including_gaps(tr) * reldist; gdouble current_dist = 0.0; gdouble current_inc = 0.0; - VikCoord *rv; if ( tr->trackpoints ) { GList *iter = tr->trackpoints->next; + GList *last_iter = NULL; while (iter) { current_inc = vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), @@ -617,19 +649,17 @@ VikCoord *vik_track_get_closest_tp_by_percentage_dist ( VikTrack *tr, gdouble re current_dist += current_inc; if ( current_dist >= dist ) break; + last_iter = iter; iter = iter->next; } + if (!iter) /* passing the end the track */ + return (last_iter ? last_iter->data : NULL); /* we've gone past the dist already, was prev trackpoint closer? */ /* should do a vik_coord_average_weighted() thingy. */ if ( iter->prev && abs(current_dist-current_inc-dist) < abs(current_dist-dist) ) iter = iter->prev; - - - rv = g_malloc(sizeof(VikCoord)); - *rv = VIK_TRACKPOINT(iter->data)->coord; - - return rv; + return VIK_TRACKPOINT(iter->data); } return NULL;