20 lines
946 B
JavaScript
20 lines
946 B
JavaScript
const assert = require('node:assert/strict');
|
|
let R;
|
|
try { R = require('../rastreamento-core.js'); } catch(e) { assert.fail('Rastreamento ausente'); }
|
|
const faces = [{x:.2,y:.1,w:.3,h:.4,score:.9}];
|
|
const hands = [Array.from({length:21},()=>({x:.8,y:.6}))];
|
|
assert.equal(R.target(faces,hands).tipo,'mao');
|
|
assert.equal(R.target(faces,[]).tipo,'rosto');
|
|
assert.equal(R.target([],[]),null);
|
|
assert.equal(R.target([{x:NaN,y:0,w:1,h:1}],[]),null);
|
|
const rect = R.fit(1000,500,640,480);
|
|
assert.ok(Math.abs(rect.x - (1000/2 - (500*640/480)/2)) < 1e-9);
|
|
assert.equal(rect.y,0);
|
|
assert.equal(R.point({x:0,y:0},rect).x,rect.x);
|
|
const gate = new R.FreshTarget();
|
|
gate.accept({tipo:'mao',x:.8,y:.5,atividade:true},100);
|
|
assert.equal(gate.get(200).x,.8);
|
|
assert.equal(gate.get(451),null,'Alvo antigo precisa expirar');
|
|
assert.equal(gate.accept({x:Infinity,y:0},500),false);
|
|
console.log('Rastreamento: prioridade, coordenadas, validação e expiração OK');
|