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

Refactor curvature sampling loop to avoid using float counter #1428

Merged
merged 2 commits into from
Nov 11, 2024
Merged
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
14 changes: 10 additions & 4 deletions common/math/geometry/src/spline/hermite_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,19 @@ std::pair<double, double> HermiteCurve::get2DMinMaxCurvatureValue() const
{
std::pair<double, double> ret;
std::vector<double> curvatures;
/**
* @brief 0.1 is a sampling resolution of the curvature
*/
for (double s = 0; s <= 1; s = s + 0.1) {

/// @note Specifies the number of samples. The curve is divided into 10 segments for calculation.
constexpr int sample_count = 10;

/// @note Sampling resolution. Calculated as 1.0 divided by sample_count.
constexpr double resolution = 1.0 / sample_count;

for (int i = 0; i <= sample_count; ++i) {
double s = i * resolution;
double curvature = get2DCurvature(s);
curvatures.push_back(curvature);
}

ret.first = *std::min_element(curvatures.begin(), curvatures.end());
ret.second = *std::max_element(curvatures.begin(), curvatures.end());
return ret;
Expand Down
Loading