• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

paulmthompson / WhiskerToolbox / 17270491352

27 Aug 2025 02:57PM UTC coverage: 65.333%. Remained the same
17270491352

push

github

paulmthompson
Merge branch 'main' of https://github.com/paulmthompson/WhiskerToolbox

352 of 628 new or added lines in 92 files covered. (56.05%)

357 existing lines in 24 files now uncovered.

26429 of 40453 relevant lines covered (65.33%)

1119.34 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/DataManager/utils/polynomial/parametric_polynomial_utils.cpp
1
#include "parametric_polynomial_utils.hpp"
2

3
#include "armadillo" // For arma::mat, arma::vec, arma::solve, arma::conv_to
4

5
#include <vector>
6
#include <cmath> // For std::sqrt, std::pow
7

8
// Helper function to compute t-values based on cumulative distance
9
std::vector<double> compute_t_values(Line2D const & line) {
×
10
    if (line.empty()) {
×
11
        return {};
×
12
    }
13
    
14
    std::vector<double> distances;
×
15
    distances.reserve(line.size());
×
16
    distances.push_back(0.0);  // First point has distance 0
×
17
    
18
    double total_distance = 0.0;
×
19
    for (size_t i = 1; i < line.size(); ++i) {
×
20
        double dx = line[i].x - line[i-1].x;
×
21
        double dy = line[i].y - line[i-1].y;
×
22
        double segment_distance = std::sqrt(dx*dx + dy*dy);
×
23
        total_distance += segment_distance;
×
24
        distances.push_back(total_distance);
×
25
    }
26
    
27
    std::vector<double> t_values;
×
28
    t_values.reserve(line.size());
×
29
    if (total_distance > 0.0) {
×
30
        for (double d : distances) {
×
31
            t_values.push_back(d / total_distance);
×
32
        }
33
    } else {
34
        for (size_t i = 0; i < line.size(); ++i) {
×
35
            t_values.push_back(static_cast<double>(i) / static_cast<double>(line.size() > 1 ? line.size() - 1 : 1));
×
36
        }
37
    }
38
    
39
    return t_values;
×
40
}
×
41

42

43

44

45
// Helper function to fit a single dimension (x or y) of a parametric polynomial.
46
std::vector<double> fit_single_dimension_polynomial_internal(
×
47
    const std::vector<double>& dimension_coords,
48
    const std::vector<double>& t_values,
49
    int order) {
50
    
51
    if (dimension_coords.size() <= static_cast<size_t>(order) || t_values.size() != dimension_coords.size()) {
×
52
        return {}; // Not enough data or mismatched sizes
×
53
    }
54

NEW
55
    arma::mat X_vandermonde(t_values.size(), static_cast<arma::uword>(order) + 1);
×
56
    arma::vec Y_coords(const_cast<double*>(dimension_coords.data()), dimension_coords.size(), false); // Use const_cast and non-copy for efficiency
×
57

58
    for (size_t i = 0; i < t_values.size(); ++i) {
×
59
        for (int j = 0; j <= order; ++j) {
×
NEW
60
            X_vandermonde(i, static_cast<arma::uword>(j)) = std::pow(t_values[i], j);
×
61
        }
62
    }
63

64
    arma::vec coeffs_arma;
×
65
    bool success = arma::solve(coeffs_arma, X_vandermonde, Y_coords);
×
66

67
    if (!success) {
×
68
        return {};
×
69
    }
70
    return arma::conv_to<std::vector<double>>::from(coeffs_arma);
×
71
} 
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc