nalgebra/base/
constraint.rs1use crate::base::dimension::{Dim, DimName, Dynamic};
4
5#[derive(Copy, Clone, Debug)]
7pub struct ShapeConstraint;
8
9pub trait AreMultipliable<R1: Dim, C1: Dim, R2: Dim, C2: Dim>: DimEq<C1, R2> {}
11
12impl<R1: Dim, C1: Dim, R2: Dim, C2: Dim> AreMultipliable<R1, C1, R2, C2> for ShapeConstraint where
13 ShapeConstraint: DimEq<C1, R2>
14{
15}
16
17pub trait DimEq<D1: Dim, D2: Dim> {
19 type Representative: Dim;
22}
23
24impl<D: Dim> DimEq<D, D> for ShapeConstraint {
25 type Representative = D;
26}
27
28impl<D: DimName> DimEq<D, Dynamic> for ShapeConstraint {
29 type Representative = D;
30}
31
32impl<D: DimName> DimEq<Dynamic, D> for ShapeConstraint {
33 type Representative = D;
34}
35
36macro_rules! equality_trait_decl(
37 ($($doc: expr, $Trait: ident),* $(,)*) => {$(
38 #[doc = $doc]
40 pub trait $Trait<D1: Dim, D2: Dim>: DimEq<D1, D2> + DimEq<D2, D1> {
41 type Representative: Dim;
44 }
45
46 impl<D: Dim> $Trait<D, D> for ShapeConstraint {
47 type Representative = D;
48 }
49
50 impl<D: DimName> $Trait<D, Dynamic> for ShapeConstraint {
51 type Representative = D;
52 }
53
54 impl<D: DimName> $Trait<Dynamic, D> for ShapeConstraint {
55 type Representative = D;
56 }
57 )*}
58);
59
60equality_trait_decl!(
61 "Constraints `D1` and `D2` to be equivalent. \
62 They are both assumed to be the number of \
63 rows of a matrix.",
64 SameNumberOfRows,
65 "Constraints `D1` and `D2` to be equivalent. \
66 They are both assumed to be the number of \
67 columns of a matrix.",
68 SameNumberOfColumns
69);
70
71pub trait SameDimension<D1: Dim, D2: Dim>:
74 SameNumberOfRows<D1, D2> + SameNumberOfColumns<D1, D2>
75{
76 type Representative: Dim;
79}
80
81impl<D: Dim> SameDimension<D, D> for ShapeConstraint {
82 type Representative = D;
83}
84
85impl<D: DimName> SameDimension<D, Dynamic> for ShapeConstraint {
86 type Representative = D;
87}
88
89impl<D: DimName> SameDimension<Dynamic, D> for ShapeConstraint {
90 type Representative = D;
91}