Algebraic genericity



The documentation has an example of “algebraic genericity”:

fn reflect_wrt_hyperplane<V>(plane_normal: &Unit<V>, vector: &V) -> V
    where V: FiniteDimInnerSpace + Copy {
    let n = plane_normal.as_ref(); // Get the underlying vector of type `V`.
    *vector - *n * ( * na::convert(2.0))

Are there more examples of this kind of genericity? Specifically, could such a function be extended to accepting not only a vector from the space V, but also a matrix or similar that can transform such a vector into another vector in the same space?


There are not any other examples at the moment, but this can be achieved with the transformation traits from the “linear” module of tha alga crate. For example:

fn rotate_point_and_vector<P, T>(transform: &T, point: &P, vector: &P::Coordinates) -> (P, V)
    where T: AffineTransformation<P>,
          P: EuclideanSpace {
    (transform.transform_point(point), transform.transform_vector(vector))