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
/*!
# **rustool**

Personal toolbox for my Rust projects

## Using **rustool**

Simply add the following to your `Cargo.toml` file:

```.ignore
[dependencies]
rustool = "0.3.2"
```
*/

/// Main functionalities.
pub mod core;

pub use crate::core::*;

extern crate alga;
extern crate itertools;
extern crate log;
extern crate nalgebra as na;
extern crate num_traits;
extern crate simplelog;

use alga::general::RingCommutative;
use na::base::storage::Storage;
use na::{Dynamic, Matrix, Matrix3xX, RowDVector, Scalar, SliceStorage, Vector3};
use num_traits::{NumCast, ToPrimitive};
use std::cmp::PartialOrd;

/// Type alias for [`DVector`]. The matrix has X rows and 1 column.
pub type List<T> = RowDVector<T>;

/// Type alias for [`Vector3`]. The matrix has 1 row and 3 columns.
pub type Vector<T> = Vector3<T>;

/// Type alias for [`MatrixXx3`]. The matrix has X row and 3 columns.
pub type Vectors<T> = Matrix3xX<T>;

/// Type alias to define a slice of the size of its matrix.
pub type Slice<'a, N, R, C, S1> = Matrix<
    N,
    Dynamic,
    Dynamic,
    SliceStorage<
        'a,
        N,
        Dynamic,
        Dynamic,
        <S1 as Storage<N, R, C>>::RStride,
        <S1 as Storage<N, R, C>>::CStride,
    >,
>;

/// Trait that extends [`Scalar`] to create integer matrices like float matrices. It aims to be the
/// equivalent of [`RealField`][nalgebra::RealField] but for integer.
pub trait SuperScalar:
    Scalar
    + RingCommutative
    + PartialOrd
    + std::ops::Div
    + ToPrimitive
    + NumCast
    + Copy
    + serde::ser::Serialize
{
}

impl<T> SuperScalar for T where
    T: Scalar
        + RingCommutative
        + PartialOrd
        + std::ops::Div
        + ToPrimitive
        + NumCast
        + Copy
        + serde::ser::Serialize
{
}