Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(interpolation): fix spline interpolation when the number of input data is 3 #1162

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/interpolation/src/spline_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ inline std::vector<double> solveTridiagonalMatrixAlgorithm(const TDMACoef & tdma
x[j] = p[j] * x[j + 1] + q[j];
}
} else {
x.push_back(d[0] / b[0]);
x[0] = (d[0] / b[0]);
}

return x;
Expand Down
14 changes: 13 additions & 1 deletion common/interpolation/test/src/test_spline_interpolation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(spline_interpolation, slerp)
}
}

{ // curve: query_keys is same as random
{ // curve: query_keys is random
const std::vector<double> base_keys{-1.5, 1.0, 5.0, 10.0, 15.0, 20.0};
const std::vector<double> base_values{-1.2, 0.5, 1.0, 1.2, 2.0, 1.0};
const std::vector<double> query_keys{0.0, 8.0, 18.0};
Expand Down Expand Up @@ -96,6 +96,18 @@ TEST(spline_interpolation, slerp)
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon);
}
}

{ // curve: query_keys is random. size of base_keys is 3 (edge case in the implementation)
const std::vector<double> base_keys{-1.5, 1.0, 5.0};
const std::vector<double> base_values{-1.2, 0.5, 1.0};
const std::vector<double> query_keys{-1.0, 0.0, 4.0};
const std::vector<double> ans{-0.808769, -0.077539, 1.035096};

const auto query_values = interpolation::slerp(base_keys, base_values, query_keys);
for (size_t i = 0; i < query_values.size(); ++i) {
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon);
}
}
}

TEST(spline_interpolation, slerpYawFromPoints)
Expand Down