package cz.vutbr.feec.utko.objectTracking.example;

import java.security.DigestException;
import java.util.List;

import org.opencv.core.Point;

public class PredictionMatcher implements IMatcher {
	double multiplicator=0.01;	//0.01
	@Override
	public void match(List<Template> listOfTemplates, List<Template> listOfDetections, double[][] assignmentArray) {
		// TODO Auto-generated method stub
		for (Template detection : listOfDetections) {
			int idGoodMatch=200;
			double nearestDistance=1000;
			Point detectionPoint = new Point();
			detectionPoint.x= (detection.getRect().x+detection.getRect().width)/2;
			detectionPoint.y=(detection.getRect().y+detection.getRect().height)/2;
			for (Template template : listOfTemplates) {
				double distance=Math.sqrt(Math.pow(template.getPredictedState().x-detectionPoint.x, 2)+Math.pow(template.getPredictedState().y-detectionPoint.y, 2));
			if (distance<nearestDistance) {
				nearestDistance=distance;
				idGoodMatch=listOfTemplates.indexOf(template);
			}
			}
			//detection.setIdOfDistanceMatch(idGoodMatch);
			assignmentArray[listOfDetections.indexOf(detection)][idGoodMatch]+=1*multiplicator;
			detection.setNearestSizeDistance(nearestDistance);
		}
	}

	@Override
	public void setMultiplicator(double multiplicator) {
		// TODO Auto-generated method stub
		this.multiplicator=multiplicator;
	}

	@Override
	public double getMultiplicator() {
		// TODO Auto-generated method stub
		return multiplicator;
	}

}
