From 5ec33a2721c6989198c3bffc6c2254a4c5e5fe96 Mon Sep 17 00:00:00 2001
From: tsteven4 <13596209+tsteven4@users.noreply.github.com>
Date: Thu, 27 Jul 2023 14:17:07 -0600
Subject: [PATCH] fix bugs with simplify filter
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.
---
reference/simplify_error_length.gpx | 5 ++++
smplrout.cc | 41 ++++++++++++++---------------
2 files changed, 25 insertions(+), 21 deletions(-)
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--;