1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//! Residual factor implementations with automatic differentiation support.
//!
//! Factors (also called cost functions or residual blocks) compute the difference between
//! observed measurements and predictions from estimated parameters. All factor implementations
//! are generic over [`nalgebra::RealField`] to support both f64 evaluation and automatic
//! differentiation via dual numbers.
//!
//! # Design Pattern
//!
//! Factor functions follow this pattern:
//!
//! ```rust,ignore
//! pub(crate) fn my_factor_generic<T: RealField>(
//! param1: DVectorView<'_, T>,
//! param2: DVectorView<'_, T>,
//! measurement: [f64; N],
//! ) -> SVector<T, M> {
//! // Extract parameters with .clone() (cheap for dual numbers)
//! let p1 = param1[0].clone();
//!
//! // Perform computations using generic operations
//! let prediction = compute_prediction(p1, ...);
//!
//! // Return residual as SVector
//! SVector::<T, M>::new(...)
//! }
//! ```
//!
//! ## Key Guidelines
//!
//! - Use `.clone()` liberally on `T: RealField` values (dual numbers are `Copy`-like)
//! - Avoid in-place mutations
//! - Convert constants with `T::from_f64().unwrap()`
//! - Use `T::one()` and `T::zero()` for identity elements
//! - Include `debug_assert!` for parameter dimension checks
//!
//! # Available Factors
//!
//! - [`reprojection_model`] - Pinhole camera reprojection with optional Brown-Conrady distortion
//! - [`laserline`] - Laser plane residuals for laserline calibration