Skip to content

Commit 1a09ff6

Browse files
oxidaseTheMarex
authored andcommitted
Don't remove the last original coordinate during tiding
1 parent 2794a52 commit 1a09ff6

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

include/engine/api/match_parameters_tidy.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ inline Result keep_all(const MatchParameters &params)
8080

8181
inline Result tidy(const MatchParameters &params, Thresholds cfg = {15., 5})
8282
{
83+
BOOST_ASSERT(!params.coordinates.empty());
84+
8385
Result result;
8486

8587
result.can_be_removed.resize(params.coordinates.size(), false);
@@ -91,10 +93,8 @@ inline Result tidy(const MatchParameters &params, Thresholds cfg = {15., 5})
9193
Thresholds running{0., 0};
9294

9395
// Walk over adjacent (coord, ts)-pairs, with rhs being the candidate to discard or keep
94-
for (std::size_t current = 0; current < params.coordinates.size() - 1; ++current)
96+
for (std::size_t current = 0, next = 1; next < params.coordinates.size() - 1; ++current, ++next)
9597
{
96-
const auto next = current + 1;
97-
9898
auto distance_delta = util::coordinate_calculation::haversineDistance(
9999
params.coordinates[current], params.coordinates[next]);
100100
running.distance_in_meters += distance_delta;
@@ -130,7 +130,11 @@ inline Result tidy(const MatchParameters &params, Thresholds cfg = {15., 5})
130130
}
131131
}
132132

133-
BOOST_ASSERT(result.can_be_removed.size() == params.coordinates.size());
133+
// Always use the last coordinate if more than two original coordinates
134+
if (params.coordinates.size() > 1)
135+
{
136+
result.tidied_to_original.push_back(params.coordinates.size() - 1);
137+
}
134138

135139
// We have to filter parallel arrays that may be empty or the exact same size.
136140
// result.parameters contains an empty MatchParameters at this point: conditionally fill.

unit_tests/engine/tidy.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ BOOST_AUTO_TEST_CASE(two_item_trace_needs_tidiying_test)
5353
auto result = tidy::tidy(params, thresholds);
5454

5555
BOOST_CHECK_EQUAL(result.can_be_removed.size(), 2);
56-
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 1);
56+
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 2);
5757

5858
BOOST_CHECK_EQUAL(result.can_be_removed[0], false);
59-
BOOST_CHECK_EQUAL(result.can_be_removed[1], true);
59+
BOOST_CHECK_EQUAL(result.can_be_removed[1], false);
6060
BOOST_CHECK_EQUAL(result.tidied_to_original[0], 0);
6161
}
6262

@@ -87,16 +87,18 @@ BOOST_AUTO_TEST_CASE(two_blobs_in_traces_needs_tidiying_test)
8787
auto result = tidy::tidy(params, thresholds);
8888

8989
BOOST_CHECK_EQUAL(result.can_be_removed.size(), params.coordinates.size());
90-
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 2);
90+
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 3);
9191

9292
BOOST_CHECK_EQUAL(result.tidied_to_original[0], 0);
9393
BOOST_CHECK_EQUAL(result.tidied_to_original[1], 3);
94+
BOOST_CHECK_EQUAL(result.tidied_to_original[2], 5);
9495

9596
const auto redundant = result.can_be_removed.count();
96-
BOOST_CHECK_EQUAL(redundant, params.coordinates.size() - 2);
97+
BOOST_CHECK_EQUAL(redundant, params.coordinates.size() - 3);
9798

9899
BOOST_CHECK_EQUAL(result.can_be_removed[0], false);
99100
BOOST_CHECK_EQUAL(result.can_be_removed[3], false);
101+
BOOST_CHECK_EQUAL(result.can_be_removed[5], false);
100102
}
101103

102104
BOOST_AUTO_TEST_CASE(two_blobs_in_traces_needs_tidiying_no_timestamps_test)
@@ -118,15 +120,17 @@ BOOST_AUTO_TEST_CASE(two_blobs_in_traces_needs_tidiying_no_timestamps_test)
118120
auto result = tidy::tidy(params, thresholds);
119121

120122
BOOST_CHECK_EQUAL(result.can_be_removed.size(), params.coordinates.size());
121-
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 2);
123+
BOOST_CHECK_EQUAL(result.tidied_to_original.size(), 3);
122124
BOOST_CHECK_EQUAL(result.tidied_to_original[0], 0);
123125
BOOST_CHECK_EQUAL(result.tidied_to_original[1], 3);
126+
BOOST_CHECK_EQUAL(result.tidied_to_original[2], 5);
124127

125128
const auto redundant = result.can_be_removed.count();
126-
BOOST_CHECK_EQUAL(redundant, params.coordinates.size() - 2);
129+
BOOST_CHECK_EQUAL(redundant, params.coordinates.size() - 3);
127130

128131
BOOST_CHECK_EQUAL(result.can_be_removed[0], false);
129132
BOOST_CHECK_EQUAL(result.can_be_removed[3], false);
133+
BOOST_CHECK_EQUAL(result.can_be_removed[5], false);
130134
}
131135

132136
BOOST_AUTO_TEST_SUITE_END()

0 commit comments

Comments
 (0)