      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
     44
     45
     46
     47
     48
     49
     50
     51
     52
     53
     54
     55
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173

    /*
     *
     * This provides the following operator overladings:
     *
     * Index<(usize, usize)>
     *
     * Rotation × Rotation
     * Rotation ÷ Rotation
     * Rotation × Matrix
     * Matrix   × Rotation
     * Matrix   ÷ Rotation
     * Rotation × Point
     * Rotation × Unit<Vector>
     *
     *
     * Rotation ×= Rotation
     * Matrix   ×= Rotation
     */

    use num::{One, Zero};
    use std::ops::{Div, DivAssign, Index, Mul, MulAssign};

    use alga::general::{ClosedAdd, ClosedMul};

    use crate::base::allocator::Allocator;
    use crate::base::constraint::{AreMultipliable, ShapeConstraint};
    use crate::base::dimension::{Dim, DimName, U1};
    use crate::base::storage::Storage;
    use crate::base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN};

    use crate::geometry::{Point, Rotation};

    impl<N: Scalar, D: DimName> Index<(usize, usize)> for Rotation<N, D>
    where DefaultAllocator: Allocator<N, D, D>
    {
        type Output = N;

        #[inline]
        fn index(&self, row_col: (usize, usize)) -> &N {
            self.matrix().index(row_col)
        }
    }

    // Rotation × Rotation
    md_impl_all!(
        Mul, mul;
        (D, D), (D, D) for D: DimName;
        self: Rotation<N, D>, right: Rotation<N, D>, Output = Rotation<N, D>;
        [val val] => Rotation::from_matrix_unchecked(self.into_inner() * right.into_inner());
        [ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.into_inner());
        [val ref] => Rotation::from_matrix_unchecked(self.into_inner() * right.matrix());
        [ref ref] => Rotation::from_matrix_unchecked(self.matrix() * right.matrix());
    );

    // Rotation ÷ Rotation
    // FIXME: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method?
    md_impl_all!(
        Div, div;
        (D, D), (D, D) for D: DimName;
        self: Rotation<N, D>, right: Rotation<N, D>, Output = Rotation<N, D>;
        [val val] => self * right.inverse();
        [ref val] => self * right.inverse();
        [val ref] => self * right.inverse();
        [ref ref] => self * right.inverse();
    );

    // Rotation × Matrix
    md_impl_all!(
        Mul, mul;
        (D1, D1), (R2, C2) for D1: DimName, R2: Dim, C2: Dim, SB: Storage<N, R2, C2>
        where DefaultAllocator: Allocator<N, D1, C2>
        where ShapeConstraint: AreMultipliable<D1, D1, R2, C2>;
        self: Rotation<N, D1>, right: Matrix<N, R2, C2, SB>, Output = MatrixMN<N, D1, C2>;
        [val val] => self.into_inner() * right;
        [ref val] => self.matrix() * right;
        [val ref] => self.into_inner() * right;
        [ref ref] => self.matrix() * right;
    );

    // Matrix × Rotation
    md_impl_all!(
        Mul, mul;
        (R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage<N, R1, C1>
        where DefaultAllocator: Allocator<N, R1, D2>
        where ShapeConstraint:  AreMultipliable<R1, C1, D2, D2>;
        self: Matrix<N, R1, C1, SA>, right: Rotation<N, D2>, Output = MatrixMN<N, R1, D2>;
        [val val] => self * right.into_inner();
        [ref val] => self * right.into_inner();
        [val ref] => self * right.matrix();
        [ref ref] => self * right.matrix();
    );

    // Matrix ÷ Rotation
    md_impl_all!(
        Div, div;
        (R1, C1), (D2, D2) for R1: Dim, C1: Dim, D2: DimName, SA: Storage<N, R1, C1>
        where DefaultAllocator: Allocator<N, R1, D2>
        where ShapeConstraint: AreMultipliable<R1, C1, D2, D2>;
        self: Matrix<N, R1, C1, SA>, right: Rotation<N, D2>, Output = MatrixMN<N, R1, D2>;
        [val val] => self * right.inverse();
        [ref val] => self * right.inverse();
        [val ref] => self * right.inverse();
        [ref ref] => self * right.inverse();
    );

    // Rotation × Point
    // FIXME: we don't handle properly non-zero origins here. Do we want this to be the intended
    // behavior?
    md_impl_all!(
        Mul, mul;
        (D, D), (D, U1) for D: DimName
        where DefaultAllocator: Allocator<N, D>
        where ShapeConstraint:  AreMultipliable<D, D, D, U1>;
        self: Rotation<N, D>, right: Point<N, D>, Output = Point<N, D>;
        [val val] => self.into_inner() * right;
        [ref val] => self.matrix() * right;
        [val ref] => self.into_inner() * right;
        [ref ref] => self.matrix() * right;
    );

    // Rotation × Unit<Vector>
    md_impl_all!(
        Mul, mul;
        (D, D), (D, U1) for D: DimName, S: Storage<N, D>
        where DefaultAllocator: Allocator<N, D>
        where ShapeConstraint:  AreMultipliable<D, D, D, U1>;
        self: Rotation<N, D>, right: Unit<Vector<N, D, S>>, Output = Unit<VectorN<N, D>>;
        [val val] => Unit::new_unchecked(self.into_inner() * right.into_inner());
        [ref val] => Unit::new_unchecked(self.matrix() * right.into_inner());
        [val ref] => Unit::new_unchecked(self.into_inner() * right.as_ref());
        [ref ref] => Unit::new_unchecked(self.matrix() * right.as_ref());
    );

    // Rotation ×= Rotation
    // FIXME: try not to call `inverse()` explicitly.

    md_assign_impl_all!(
        MulAssign, mul_assign;
        (D, D), (D, D) for D: DimName;
        self: Rotation<N, D>, right: Rotation<N, D>;
        [val] => self.matrix_mut_unchecked().mul_assign(right.into_inner());
        [ref] => self.matrix_mut_unchecked().mul_assign(right.matrix());
    );

    md_assign_impl_all!(
        DivAssign, div_assign;
        (D, D), (D, D) for D: DimName;
        self: Rotation<N, D>, right: Rotation<N, D>;
        [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().into_inner());
        [ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix());
    );

    // Matrix *= Rotation
    // FIXME: try not to call `inverse()` explicitly.
    // FIXME: this shares the same limitations as for the current impl. of MulAssign for matrices.
    // (In particular the number of matrix column must be equal to the number of rotation columns,
    // i.e., equal to the rotation dimension.

    md_assign_impl_all!(
        MulAssign, mul_assign;
        (R1, C1), (C1, C1) for R1: DimName, C1: DimName;
        self: MatrixMN<N, R1, C1>, right: Rotation<N, C1>;
        [val] => self.mul_assign(right.into_inner());
        [ref] => self.mul_assign(right.matrix());
    );

    md_assign_impl_all!(
        DivAssign, div_assign;
        (R1, C1), (C1, C1) for R1: DimName, C1: DimName;
        self: MatrixMN<N, R1, C1>, right: Rotation<N, C1>;
        [val] => self.mul_assign(right.inverse().into_inner());
        [ref] => self.mul_assign(right.inverse().matrix());
    );

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)