@@ -289,5 +289,93 @@ module.exports = function ({ cv, utils }) {
289
289
} ) ;
290
290
} ) ;
291
291
} ) ;
292
+
293
+ describe ( 'Vec6' , ( ) => {
294
+ const vec0 = new cv . Vec ( 50 , 100 , 200 , 300 , 400 , 500 ) ;
295
+ const vec1 = new cv . Vec ( 10 , 25 , 50 , 75 , 100 , 125 ) ;
296
+ const vec2 = new cv . Vec ( 2 , 5 , 4 , 3 , 2 , 1 ) ;
297
+ const operatorRequiresArg = OperatorRequiresArg ( vec0 ) ;
298
+ describe ( 'add' , ( ) => {
299
+ operatorRequiresArg ( 'add' ) ;
300
+
301
+ it ( 'add vectors' , ( ) => {
302
+ assertPropsWithValue ( vec0 . add ( vec1 ) ) ( { u : 60 , v : 125 , w : 250 , x : 375 , y : 500 , z : 625 } ) ;
303
+ } ) ;
304
+ } ) ;
305
+
306
+ describe ( 'sub' , ( ) => {
307
+ operatorRequiresArg ( 'sub' ) ;
308
+
309
+ it ( 'subtract vectors' , ( ) => {
310
+ assertPropsWithValue ( vec0 . sub ( vec1 ) ) ( { u : 40 , v : 75 , w : 150 , x : 225 , y : 300 , z : 375 } ) ;
311
+ } ) ;
312
+ } ) ;
313
+
314
+ describe ( 'mul' , ( ) => {
315
+ operatorRequiresArg ( 'mul' , true ) ;
316
+
317
+ it ( 'multiply vector by scalar' , ( ) => {
318
+ assertPropsWithValue ( vec0 . mul ( 2 ) ) ( { u : 100 , v : 200 , w : 400 , x : 600 , y : 800 , z : 1000 } ) ;
319
+ } ) ;
320
+ } ) ;
321
+
322
+ describe ( 'div' , ( ) => {
323
+ operatorRequiresArg ( 'div' , true ) ;
324
+
325
+ it ( 'divide vector by scalar' , ( ) => {
326
+ assertPropsWithValue ( vec0 . div ( 2 ) ) ( { u : 25 , v : 50 , w : 100 , x : 150 , y : 200 , z : 250 } ) ;
327
+ } ) ;
328
+ } ) ;
329
+
330
+ describe ( 'hMul' , ( ) => {
331
+ operatorRequiresArg ( 'hMul' ) ;
332
+
333
+ it ( 'elementwise multiply vectors' , ( ) => {
334
+ assertPropsWithValue ( vec0 . hMul ( vec2 ) ) ( { u : 100 , v : 500 , w : 800 , x : 900 , y : 800 , z : 500 } ) ;
335
+ } ) ;
336
+ } ) ;
337
+
338
+ describe ( 'hDiv' , ( ) => {
339
+ operatorRequiresArg ( 'hDiv' ) ;
340
+
341
+ it ( 'elementwise divide vectors' , ( ) => {
342
+ assertPropsWithValue ( vec0 . hDiv ( vec2 ) ) ( { u : 25 , v : 20 , w : 50 , x : 100 , y : 200 , z : 500 } ) ;
343
+ } ) ;
344
+ } ) ;
345
+
346
+ describe ( 'dot' , ( ) => {
347
+ operatorRequiresArg ( 'dot' ) ;
348
+
349
+ it ( 'compute dot product of vectors' , ( ) => {
350
+ expect ( vec0 . dot ( vec2 ) ) . to . equal ( 3600 ) ;
351
+ } ) ;
352
+ } ) ;
353
+
354
+ describe ( 'absdiff' , ( ) => {
355
+ operatorRequiresArg ( 'absdiff' ) ;
356
+
357
+ it ( 'apply absdiff to matrices' , ( ) => {
358
+ assertPropsWithValue ( new cv . Vec ( 0 , 100 , 50 , 25 , 150 , 10 ) . absdiff ( new cv . Vec ( 50 , 25 , 75 , 25 , 50 , 20 ) ) ) ( { u : 50 , v : 75 , w : 25 , x : 0 , y : 50 , z : 10 } ) ;
359
+ } ) ;
360
+ } ) ;
361
+
362
+ describe ( 'exp' , ( ) => {
363
+ it ( 'apply exp to vector' , ( ) => {
364
+ assertPropsWithValue ( new cv . Vec ( Math . log ( 1 ) , Math . log ( 4 ) , 0 , Math . log ( 0 ) , Math . log ( 3 ) , Math . log ( 2 ) ) . exp ( ) ) ( { u : 1 , v : 4 , w : 1 , x : 0 , y : 3 , z : 2 } ) ;
365
+ } ) ;
366
+ } ) ;
367
+
368
+ describe ( 'sqrt' , ( ) => {
369
+ it ( 'apply sqrt to vector' , ( ) => {
370
+ assertPropsWithValue ( new cv . Vec ( 0 , 4 , 16 , 64 , 255 , 510 ) . sqrt ( ) ) ( { u : 0 , v : 2 , w : 4 , x : 8 , y : 16 , z : 32 } ) ;
371
+ } ) ;
372
+ } ) ;
373
+
374
+ describe ( 'norm' , ( ) => {
375
+ it ( 'should return magnitude' , ( ) => {
376
+ expect ( new cv . Vec ( Math . sqrt ( 4 ) , Math . sqrt ( 4 ) , Math . sqrt ( 4 ) , Math . sqrt ( 4 ) , Math . sqrt ( 4 ) , Math . sqrt ( 4 ) ) . norm ( ) ) . to . equal ( 4 ) ;
377
+ } ) ;
378
+ } ) ;
379
+ } ) ;
292
380
} ) ;
293
381
} ;
0 commit comments