@@ -68,7 +68,7 @@ impl<S: BaseNum> Point3<S> {
68
68
/// Specifies the numeric operations for point types.
69
69
pub trait Point : Clone where
70
70
// FIXME: Ugly type signatures - blocked by rust-lang/rust#24092
71
- Self : Array1 < Element = << Self as Point > :: Vector as Vector >:: Scalar > ,
71
+ Self : Array1 < Element = <Self as Point >:: Scalar > ,
72
72
// FIXME: blocked by rust-lang/rust#20671
73
73
//
74
74
// for<'a, 'b> &'a Self: Add<&'b V, Output = Self>,
@@ -78,8 +78,13 @@ pub trait Point: Clone where
78
78
// for<'a> &'a Self: Div<S, Output = Self>,
79
79
// for<'a> &'a Self: Rem<S, Output = Self>,
80
80
{
81
+ /// The associated scalar.
82
+ ///
83
+ /// Due to the equality constraints demanded by `Self::Vector`, this is effectively just an
84
+ /// alias to `Self::Vector::Scalar`.
85
+ type Scalar : BaseNum ;
81
86
/// The associated displacement vector.
82
- type Vector : Vector ;
87
+ type Vector : Vector < Scalar = Self :: Scalar > ;
83
88
84
89
/// Create a point at the origin.
85
90
fn origin ( ) -> Self ;
@@ -91,13 +96,13 @@ pub trait Point: Clone where
91
96
92
97
/// Multiply each component by a scalar, returning the new point.
93
98
#[ must_use]
94
- fn mul_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Self ;
99
+ fn mul_s ( & self , scalar : Self :: Scalar ) -> Self ;
95
100
/// Divide each component by a scalar, returning the new point.
96
101
#[ must_use]
97
- fn div_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Self ;
102
+ fn div_s ( & self , scalar : Self :: Scalar ) -> Self ;
98
103
/// Subtract a scalar from each component, returning the new point.
99
104
#[ must_use]
100
- fn rem_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Self ;
105
+ fn rem_s ( & self , scalar : Self :: Scalar ) -> Self ;
101
106
102
107
/// Add a vector to this point, returning the new point.
103
108
#[ must_use]
@@ -106,17 +111,17 @@ pub trait Point: Clone where
106
111
fn sub_p ( & self , p : & Self ) -> Self :: Vector ;
107
112
108
113
/// Multiply each component by a scalar, in-place.
109
- fn mul_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) ;
114
+ fn mul_self_s ( & mut self , scalar : Self :: Scalar ) ;
110
115
/// Divide each component by a scalar, in-place.
111
- fn div_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) ;
116
+ fn div_self_s ( & mut self , scalar : Self :: Scalar ) ;
112
117
/// Take the remainder of each component by a scalar, in-place.
113
- fn rem_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) ;
118
+ fn rem_self_s ( & mut self , scalar : Self :: Scalar ) ;
114
119
115
120
/// Add a vector to this point, in-place.
116
121
fn add_self_v ( & mut self , v : & Self :: Vector ) ;
117
122
118
123
/// This is a weird one, but its useful for plane calculations.
119
- fn dot ( & self , v : & Self :: Vector ) -> << Self as Point > :: Vector as Vector > :: Scalar ;
124
+ fn dot ( & self , v : & Self :: Vector ) -> Self :: Scalar ;
120
125
121
126
#[ must_use]
122
127
fn min ( & self , p : & Self ) -> Self ;
@@ -130,6 +135,7 @@ impl<S: BaseNum> Array1 for Point2<S> {
130
135
}
131
136
132
137
impl < S : BaseNum > Point for Point2 < S > {
138
+ type Scalar = S ;
133
139
type Vector = Vector2 < S > ;
134
140
135
141
#[ inline]
@@ -147,26 +153,26 @@ impl<S: BaseNum> Point for Point2<S> {
147
153
Vector2 :: new ( self . x , self . y )
148
154
}
149
155
150
- #[ inline] fn mul_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point2 < S > { self * scalar }
151
- #[ inline] fn div_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point2 < S > { self / scalar }
152
- #[ inline] fn rem_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point2 < S > { self % scalar }
156
+ #[ inline] fn mul_s ( & self , scalar : S ) -> Point2 < S > { self * scalar }
157
+ #[ inline] fn div_s ( & self , scalar : S ) -> Point2 < S > { self / scalar }
158
+ #[ inline] fn rem_s ( & self , scalar : S ) -> Point2 < S > { self % scalar }
153
159
#[ inline] fn add_v ( & self , v : & Vector2 < S > ) -> Point2 < S > { self + v }
154
160
#[ inline] fn sub_p ( & self , p : & Point2 < S > ) -> Vector2 < S > { self - p }
155
161
156
162
#[ inline]
157
- fn mul_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
163
+ fn mul_self_s ( & mut self , scalar : S ) {
158
164
self . x = self . x * scalar;
159
165
self . y = self . y * scalar;
160
166
}
161
167
162
168
#[ inline]
163
- fn div_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
169
+ fn div_self_s ( & mut self , scalar : S ) {
164
170
self . x = self . x / scalar;
165
171
self . y = self . y / scalar;
166
172
}
167
173
168
174
#[ inline]
169
- fn rem_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
175
+ fn rem_self_s ( & mut self , scalar : S ) {
170
176
self . x = self . x % scalar;
171
177
self . y = self . y % scalar;
172
178
}
@@ -209,6 +215,7 @@ impl<S: BaseNum> Array1 for Point3<S> {
209
215
}
210
216
211
217
impl < S : BaseNum > Point for Point3 < S > {
218
+ type Scalar = S ;
212
219
type Vector = Vector3 < S > ;
213
220
214
221
#[ inline]
@@ -226,28 +233,28 @@ impl<S: BaseNum> Point for Point3<S> {
226
233
Vector3 :: new ( self . x , self . y , self . z )
227
234
}
228
235
229
- #[ inline] fn mul_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point3 < S > { self * scalar }
230
- #[ inline] fn div_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point3 < S > { self / scalar }
231
- #[ inline] fn rem_s ( & self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) -> Point3 < S > { self % scalar }
236
+ #[ inline] fn mul_s ( & self , scalar : S ) -> Point3 < S > { self * scalar }
237
+ #[ inline] fn div_s ( & self , scalar : S ) -> Point3 < S > { self / scalar }
238
+ #[ inline] fn rem_s ( & self , scalar : S ) -> Point3 < S > { self % scalar }
232
239
#[ inline] fn add_v ( & self , v : & Vector3 < S > ) -> Point3 < S > { self + v }
233
240
#[ inline] fn sub_p ( & self , p : & Point3 < S > ) -> Vector3 < S > { self - p }
234
241
235
242
#[ inline]
236
- fn mul_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
243
+ fn mul_self_s ( & mut self , scalar : S ) {
237
244
self . x = self . x * scalar;
238
245
self . y = self . y * scalar;
239
246
self . z = self . z * scalar;
240
247
}
241
248
242
249
#[ inline]
243
- fn div_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
250
+ fn div_self_s ( & mut self , scalar : S ) {
244
251
self . x = self . x / scalar;
245
252
self . y = self . y / scalar;
246
253
self . z = self . z / scalar;
247
254
}
248
255
249
256
#[ inline]
250
- fn rem_self_s ( & mut self , scalar : << Self as Point > :: Vector as Vector > :: Scalar ) {
257
+ fn rem_self_s ( & mut self , scalar : S ) {
251
258
self . x = self . x % scalar;
252
259
self . y = self . y % scalar;
253
260
self . z = self . z % scalar;
0 commit comments