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
use std::ops::{Div, DivAssign, Mul, MulAssign};

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

use base::allocator::{Allocator, SameShapeAllocator};
use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint};
use base::dimension::{DimName, U1};
use base::{DefaultAllocator, Scalar};

use geometry::{Point, Translation};

// Translation × Translation
add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: &'b Translation<N, D>, Output = Translation<N, D>;
    Translation::from(&self.vector + &right.vector); 'a, 'b);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: Translation<N, D>, Output = Translation<N, D>;
    Translation::from(&self.vector + right.vector); 'a);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: &'b Translation<N, D>, Output = Translation<N, D>;
    Translation::from(self.vector + &right.vector); 'b);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: Translation<N, D>, Output = Translation<N, D>;
    Translation::from(self.vector + right.vector); );

// Translation ÷ Translation
// FIXME: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method?
add_sub_impl!(Div, div, ClosedSub;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: &'b Translation<N, D>, Output = Translation<N, D>;
    Translation::from(&self.vector - &right.vector); 'a, 'b);

add_sub_impl!(Div, div, ClosedSub;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: Translation<N, D>, Output = Translation<N, D>;
    Translation::from(&self.vector - right.vector); 'a);

add_sub_impl!(Div, div, ClosedSub;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: &'b Translation<N, D>, Output = Translation<N, D>;
    Translation::from(self.vector - &right.vector); 'b);

add_sub_impl!(Div, div, ClosedSub;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: Translation<N, D>, Output = Translation<N, D>;
    Translation::from(self.vector - right.vector); );

// Translation × Point
// FIXME: we don't handle properly non-zero origins here. Do we want this to be the intended
// behavior?
add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: &'b Point<N, D>, Output = Point<N, D>;
    right + &self.vector; 'a, 'b);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: &'a Translation<N, D>, right: Point<N, D>, Output = Point<N, D>;
    right + &self.vector; 'a);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: &'b Point<N, D>, Output = Point<N, D>;
    right + self.vector; 'b);

add_sub_impl!(Mul, mul, ClosedAdd;
    (D, U1), (D, U1) -> (D) for D: DimName;
    self: Translation<N, D>, right: Point<N, D>, Output = Point<N, D>;
    right + self.vector; );

// Translation *= Translation
add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd;
    (D, U1), (D, U1) for D: DimName;
    self: Translation<N, D>, right: &'b Translation<N, D>;
    self.vector += &right.vector; 'b);

add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd;
    (D, U1), (D, U1) for D: DimName;
    self: Translation<N, D>, right: Translation<N, D>;
    self.vector += right.vector; );

add_sub_assign_impl!(DivAssign, div_assign, ClosedSub;
    (D, U1), (D, U1) for D: DimName;
    self: Translation<N, D>, right: &'b Translation<N, D>;
    self.vector -= &right.vector; 'b);

add_sub_assign_impl!(DivAssign, div_assign, ClosedSub;
    (D, U1), (D, U1) for D: DimName;
    self: Translation<N, D>, right: Translation<N, D>;
    self.vector -= right.vector; );

/*
// Translation × Matrix
add_sub_impl!(Mul, mul;
         (D1, D1), (R2, C2) for D1, R2, C2;
         self: &'a Translation<N, D1>, right: &'b Matrix<N, R2, C2>, Output = MatrixMN<N, D1, C2>;
         self.vector() * right; 'a, 'b);

add_sub_impl!(Mul, mul;
         (D1, D1), (R2, C2) for D1, R2, C2;
         self: &'a Translation<N, D1>, right: Matrix<N, R2, C2>, Output = MatrixMN<N, D1, C2>;
         self.vector() * right; 'a);

add_sub_impl!(Mul, mul;
         (D1, D1), (R2, C2) for D1, R2, C2;
         self: Translation<N, D1>, right: &'b Matrix<N, R2, C2>, Output = MatrixMN<N, D1, C2>;
         self.unwrap() * right; 'b);

add_sub_impl!(Mul, mul;
         (D1, D1), (R2, C2) for D1, R2, C2;
         self: Translation<N, D1>, right: Matrix<N, R2, C2>, Output = MatrixMN<N, D1, C2>;
         self.unwrap() * right; );

// Matrix × Translation
add_sub_impl!(Mul, mul;
         (R1, C1), (D2, D2) for R1, C1, D2;
         self: &'a Matrix<N, R1, C1>, right: &'b Translation<N, D2>, Output = MatrixMN<N, R1, D2>;
         self * right.vector(); 'a, 'b);

add_sub_impl!(Mul, mul;
         (R1, C1), (D2, D2) for R1, C1, D2;
         self: &'a Matrix<N, R1, C1>, right: Translation<N, D2>, Output = MatrixMN<N, R1, D2>;
         self * right.unwrap(); 'a);

add_sub_impl!(Mul, mul;
         (R1, C1), (D2, D2) for R1, C1, D2;
         self: Matrix<N, R1, C1>, right: &'b Translation<N, D2>, Output = MatrixMN<N, R1, D2>;
         self * right.vector(); 'b);


add_sub_impl!(Mul, mul;
         (R1, C1), (D2, D2) for R1, C1, D2;
         self: Matrix<N, R1, C1>, right: Translation<N, D2>, Output = MatrixMN<N, R1, D2>;
         self * right.unwrap(); );

// Matrix *= Translation
md_assign_impl!(MulAssign, mul_assign;
                (R1, C1), (C1, C1) for R1, C1;
                self: Matrix<N, R1, C1>, right: &'b Translation<N, C1>;
                self.mul_assign(right.vector()); 'b);

md_assign_impl!(MulAssign, mul_assign;
                (R1, C1), (C1, C1) for R1, C1;
                self: Matrix<N, R1, C1>, right: Translation<N, C1>;
                self.mul_assign(right.unwrap()); );


md_assign_impl!(DivAssign, div_assign;
                (R1, C1), (C1, C1) for R1, C1;
                self: Matrix<N, R1, C1>, right: &'b Translation<N, C1>;
                self.mul_assign(right.inverse().vector()); 'b);

md_assign_impl!(DivAssign, div_assign;
                (R1, C1), (C1, C1) for R1, C1;
                self: Matrix<N, R1, C1>, right: Translation<N, C1>;
                self.mul_assign(right.inverse().unwrap()); );
*/