This page describes the low-level C++ types that all higher-level modules use. They are intentionally small: the C++ facade owns C++ storage at the boundary, borrows user buffers only for the duration of a call, and hides the private Rust/C++ bridge behind .cpp files.
Include
Most applications can include only:
Span<T>
copp::Span<T> is a C++17-compatible subset of std::span. It is a borrowed view of contiguous memory and does not allocate, copy, or own the data.
std::vector<double> s{0.0, 0.5, 1.0};
double raw[] = {1.0, 2.0, 3.0};
Non-owning view of a contiguous one-dimensional array.
Input spans must remain alive only for the call that consumes them, unless a type explicitly documents longer borrowing.
Matrices
COPP's internal Rust storage is column-major, and the C++ copp::Matrix follows the same rule:
m(0, 0) = 0.0;
m(1, 0) = 1.0;
double first_column_second_row = m(1, 0);
Lightweight owned column-major matrix.
The physical index is:
\[\text{offset}(i, j) = i + j \cdot \text{rows}.
\]
copp::MatrixView borrows input matrices. Column-major data can usually cross the bridge without reshaping; row-major data is accepted and copied once into column-major storage when Rust needs contiguous columns.
std::vector<double> row_major{
0.0, 0.0,
0.5, 0.25,
1.0, 1.0,
};
static constexpr MatrixView row_major(const double *data, std::size_t rows, std::size_t cols) noexcept
static Path from_waypoints(MatrixView waypoints, SplineConfig config={})
Build a spline path from waypoint positions.
copp::MatrixRef is a writable borrowed matrix used by C++ callbacks:
for (std::size_t j = 0; j < s.
size(); ++j) {
q(0, j) = s[j];
dq(0, j) = 1.0;
ddq(0, j) = 0.0;
}
};
Mutable column-major matrix view used by callback APIs.
constexpr std::size_t size() const noexcept
Initializer Helpers
Matrix::from_rows is convenient for ordinary tabular data:
{0.0, 0.5, 1.0},
{0.0, 0.25, 1.0},
});
static Matrix from_rows(std::initializer_list< std::initializer_list< double > > rows)
Build a matrix from row-major initializer-list notation.
Matrix::from_columns is convenient for waypoints because each waypoint is one column in COPP:
{0.0, 0.0},
{0.5, 0.25},
{1.0, 1.0},
});
static Matrix from_columns(std::initializer_list< std::initializer_list< double > > columns)
Build a matrix from column-major initializer-list notation.
Eigen Adapter
When Eigen support is enabled, copp/eigen.hpp provides adapters instead of changing the core return type. Solver outputs still return copp::Matrix, and Eigen users can map or view the storage explicitly.
Eigen::MatrixXd q = Eigen::MatrixXd::Zero(2, 3);
auto view = copp::eigen::view(q);
This keeps the public ABI stable whether Eigen is present or disabled.
Errors And No-Throw Calls
The primary C++ API throws copp::Error:
{% raw %}
try {
std::cerr << error.what() << "\n";
}
Exception type thrown by the default C++ API.
{% endraw %}
Selected APIs also provide a no-throw overload with copp::no_throw as the final argument:
{% raw %}
if (!result) {
std::cerr << result.error().message << "\n";
return;
}
auto path = std::move(result).value();
constexpr NoThrowTag no_throw
{% endraw %}
The no-throw form uses copp::Expected<T>, a small C++17 expected-like type.
Ownership Summary
- Path, Robot, Constraints, solver Problem objects, profiles, matrices, and result structs use RAII.
- ConstraintsRef, Span, MatrixView, MatrixRef, and Profile3rdRef are borrowed views.
- Robot::constraints() and non-const Constraints::ref() return borrowed views. The owning object must outlive the solver call.
- Returned vectors and matrices own their memory.
- The C++ facade calls Rust through a private cxx bridge, not through the public C ABI.