@@ -208,4 +208,59 @@ void main() {
208
208
expectDouble (position.screenAngle (), math.pi / 2 );
209
209
});
210
210
});
211
+
212
+ group ('projection' , () {
213
+ test ('Project onto longer vector' , () {
214
+ final u = Vector2 (5 , 2 );
215
+ final v = Vector2 (10 , 0 );
216
+ final result = u.projection (v);
217
+ expect (result, Vector2 (5 , 0 ));
218
+ });
219
+
220
+ test ('Project onto shorter vector' , () {
221
+ final u = Vector2 (5 , 2 );
222
+ final v = Vector2 (2 , 0 );
223
+ final result = u.projection (v);
224
+ expect (result, Vector2 (5 , 0 ));
225
+ });
226
+
227
+ test ('Project onto vector in other direction' , () {
228
+ final u = Vector2 (5 , 2 );
229
+ final v = Vector2 (- 10 , 0 );
230
+ final result = u.projection (v);
231
+ expect (result, Vector2 (5 , 0 ));
232
+ });
233
+
234
+ test ('Project onto vector with out' , () {
235
+ final out = Vector2 .zero ();
236
+ final u = Vector2 (5 , 2 );
237
+ final v = Vector2 (- 10 , 0 );
238
+ final result = u.projection (v, out: out);
239
+ expect (result, Vector2 (5 , 0 ));
240
+ expect (out, Vector2 (5 , 0 ));
241
+ });
242
+
243
+ test ('Project onto vector with out as sane return and argument' , () {
244
+ var out = Vector2 .zero ();
245
+ final u = Vector2 (5 , 2 );
246
+ final v = Vector2 (- 10 , 0 );
247
+ out = u.projection (v, out: out);
248
+ expect (out, Vector2 (5 , 0 ));
249
+ });
250
+ });
251
+
252
+ group ('inversion' , () {
253
+ test ('invert' , () {
254
+ final v = Vector2 .all (1 );
255
+ v.invert ();
256
+ expect (v, Vector2 .all (- 1 ));
257
+ });
258
+
259
+ test ('inverted' , () {
260
+ final v = Vector2 .all (1 );
261
+ final w = v.inverted ();
262
+ expect (v, Vector2 .all (1 ));
263
+ expect (w, Vector2 .all (- 1 ));
264
+ });
265
+ });
211
266
}
0 commit comments