From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Fri, 28 Jul 2023 20:40:30 +0000 (-0600) Subject: fix bugs with simplify filter (#1148) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2~1^2~34 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c9dd6e3f34549b3a1bc35a23f9ebe3ce72f386ff;p=gpsbabel.git fix bugs with simplify filter (#1148) 1. With the length option the last point deleted took the total error over the specified limit. 2. When computing the total error if another point is deleted it was possible to refer to an xte record that needed to be updated due to the deletion of one of its neighbors. --- diff --git a/reference/simplify_error_length.gpx b/reference/simplify_error_length.gpx index 4a162239f..48a4357ab 100644 --- a/reference/simplify_error_length.gpx +++ b/reference/simplify_error_length.gpx @@ -516,6 +516,11 @@ 5.373000 + + 541.600 + + 6.961000 + 537.200 diff --git a/smplrout.cc b/smplrout.cc index 88d6db0e3..3ddf224b7 100644 --- a/smplrout.cc +++ b/smplrout.cc @@ -235,13 +235,12 @@ void SimplifyRouteFilter::shuffle_xte(struct xte* xte_rec) void SimplifyRouteFilter::routesimple_tail(const route_head* rte) { - int i; if (!cur_rte) { return; } /* compute all distances */ - for (i = 0; i < xte_count ; i++) { + for (int i = 0; i < xte_count ; i++) { compute_xte(xte_recs+i); } @@ -257,7 +256,7 @@ void SimplifyRouteFilter::routesimple_tail(const route_head* rte) } - for (i = 0; i < xte_count; i++) { + for (int i = 0; i < xte_count; i++) { xte_recs[i].intermed->xte_rec = xte_recs+i; } // Ensure totalerror starts with the distance between first and second points @@ -273,23 +272,8 @@ void SimplifyRouteFilter::routesimple_tail(const route_head* rte) while ((xte_count) && (((limit_basis == limit_basis_t::count) && (count < xte_count)) || ((limit_basis == limit_basis_t::error) && (totalerror < error)))) { - i = xte_count - 1; + int i = xte_count - 1; /* remove the record with the lowest XTE */ - if (limit_basis == limit_basis_t::error) { - switch (metric) { - case metric_t::crosstrack: - case metric_t::relative: - if (i > 1) { - totalerror = xte_recs[i-1].distance; - } else { - totalerror = xte_recs[i].distance; - } - break; - case metric_t::length: - totalerror += xte_recs[i].distance; - break; - } - } (*waypt_del_fnp)(const_cast(rte), const_cast(xte_recs[i].intermed->wpt)); delete xte_recs[i].intermed->wpt; @@ -306,8 +290,23 @@ void SimplifyRouteFilter::routesimple_tail(const route_head* rte) } xte_count--; free_xte(xte_recs+xte_count); - /* end of loop */ - } + + /* compute impact of deleting next point */ + if (xte_count) { + if (limit_basis == limit_basis_t::error) { + i = xte_count - 1; + switch (metric) { + case metric_t::crosstrack: + case metric_t::relative: + totalerror = xte_recs[i].distance; + break; + case metric_t::length: + totalerror += xte_recs[i].distance; + break; + } + } + } + } /* end of loop */ if (xte_count) { do { xte_count--;