<commit_before>package group3;
import group2.Blob;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;

import global.Constant;

public class MovingBlobDetection implements IMovingBlobDetection {
	Constant c = new Constant();
	
	//list of all moving blobs that have been recently tracked
	private List<MovingBlob> movingBlobs;
	//maximum time before unmatched MovingBlob is deleted
	int maxTimeOffScreen = c.MAX_TIME_OFF_SCREEN;
	//maximum distance in pixels between blobs that can be matched
	int distanceLimitX = c.DISTANCE_LIMIT_X;
	int distanceLimitY = c.DISTANCE_LIMIT_Y;
	int widthChangeLimit = c.MAX_CHANGE_WIDTH;
	int heightChangeLimit = c.MAX_CHANGE_HEIGHT;
	
	//maximum distance between edges to unify
	int xEdgeDistanceLimit = c.X_EDGE_DISTANCE_LIMIT;
	int yEdgeDistanceLimit = c.Y_EDGE_DISTANCE_LIMIT;
	float xOverlapPercent = c.X_OVERLAP_PERCENT;
	float yOverlapPercent = c.Y_OVERLAP_PERCENT;

	//maximum difference in velocity to unify
	int unifyVelocityLimitX = c.UNIFY_VELOCITY_LIMIT_X;
	int unifyVelocityLimitY = c.UNIFY_VELOCITY_LIMIT_Y;
	float velocityLimitIncreaseX = c.VELOCITY_LIMIT_INCREASE_X;
	float velocityLimitIncreaseY = c.VELOCITY_LIMIT_INCREASE_Y;

	public MovingBlobDetection() {
		movingBlobs = new LinkedList<>();
	}

	public List<MovingBlob> getUnifiedBlobs(List<MovingBlob> movingBlobs){
		//pairs that should be unified
		HashSet<MovingBlob[]> pairs = new HashSet<>();
		for(MovingBlob movingBlob1:movingBlobs){
			for(MovingBlob movingBlob2:movingBlobs){
				float distanceX;
				float distanceY;
				if(movingBlob1.x>movingBlob2.x){
					distanceX = movingBlob1.x-(movingBlob2.x+movingBlob2.width);
				} else {
					distanceX = movingBlob2.x-(movingBlob1.x+movingBlob1.width);
				}
				if(movingBlob1.y>movingBlob2.y){
					distanceY = movingBlob1.y-(movingBlob2.y+movingBlob2.height);
				} else {
					distanceY = movingBlob2.y-(movingBlob1.y+movingBlob1.height);
				}
				float velocityDifferenceX = Math.abs(movingBlob1.velocityX-movingBlob2.velocityX);
				float velocityDifferenceY = Math.abs(movingBlob1.velocityY-movingBlob2.velocityY);
				//checks if distance and velocity differences are under thresholds
				if(((distanceX<xEdgeDistanceLimit && distanceY<-yOverlapPercent*Math.min(movingBlob1.height, movingBlob2.height)) 
						|| (distanceY<yEdgeDistanceLimit && distanceX<-xOverlapPercent*Math.min(movingBlob1.width, movingBlob2.width)))&&
						velocityDifferenceX<unifyVelocityLimitX+
						velocityLimitIncreaseX*Math.max(movingBlob1.velocityX, movingBlob2.velocityX) &&
						velocityDifferenceY<unifyVelocityLimitY+
						velocityLimitIncreaseY*Math.max(movingBlob1.velocityY, movingBlob2.velocityY)){
					MovingBlob[] pair = {movingBlob1,movingBlob2};
					pairs.add(pair);
				}<commit_msg>added distance function<commit_after>package group3;
import group2.Blob;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;

import global.Constant;

public class MovingBlobDetection implements IMovingBlobDetection {
	Constant c = new Constant();
	
	//list of all moving blobs that have been recently tracked
	private List<MovingBlob> movingBlobs;
	//maximum time before unmatched MovingBlob is deleted
	int maxTimeOffScreen = c.MAX_TIME_OFF_SCREEN;
	//maximum distance in pixels between blobs that can be matched
	int distanceLimitX = c.DISTANCE_LIMIT_X;
	int distanceLimitY = c.DISTANCE_LIMIT_Y;
	int widthChangeLimit = c.MAX_CHANGE_WIDTH;
	int heightChangeLimit = c.MAX_CHANGE_HEIGHT;
	
	//maximum distance between edges to unify
	int xEdgeDistanceLimit = c.X_EDGE_DISTANCE_LIMIT;
	int yEdgeDistanceLimit = c.Y_EDGE_DISTANCE_LIMIT;
	float xOverlapPercent = c.X_OVERLAP_PERCENT;
	float yOverlapPercent = c.Y_OVERLAP_PERCENT;

	//maximum difference in velocity to unify
	int unifyVelocityLimitX = c.UNIFY_VELOCITY_LIMIT_X;
	int unifyVelocityLimitY = c.UNIFY_VELOCITY_LIMIT_Y;
	float velocityLimitIncreaseX = c.VELOCITY_LIMIT_INCREASE_X;
	float velocityLimitIncreaseY = c.VELOCITY_LIMIT_INCREASE_Y;

	public MovingBlobDetection() {
		movingBlobs = new LinkedList<>();
	}
	
	private float distBetweenBlobs(MovingBlob blob1,MovingBlob blob2){
		float distanceX;
		float distanceY;
		if(blob1.x>blob2.x){
			distanceX = blob1.x-(blob2.x+blob2.width);
		} else {
			distanceX = blob2.x-(blob1.x+blob1.width);
		}
		if(blob1.y>blob2.y){
			distanceY = blob1.y-(blob2.y+blob2.height);
		} else {
			distanceY = blob2.y-(blob1.y+blob1.height);
		}
		distanceX = Math.max(0,distanceX);
		distanceY = Math.max(0,distanceY);
		float distanceVX = Math.abs(blob1.velocityX-blob2.velocityX);
		float distanceVY = Math.abs(blob1.velocityX-blob2.velocityY);
		return (float) Math.sqrt(distanceX*distanceX + distanceY*distanceY + distanceVX*distanceVX + distanceVY*distanceVY);
	}
	
	private float

	public List<MovingBlob> getUnifiedBlobs(List<MovingBlob> movingBlobs){
		//pairs that should be unified
		HashSet<MovingBlob[]> pairs = new HashSet<>();
		for(MovingBlob movingBlob1:movingBlobs){
			for(MovingBlob movingBlob2:movingBlobs){
				float distanceX;
				float distanceY;
				if(movingBlob1.x>movingBlob2.x){
					distanceX = movingBlob1.x-(movingBlob2.x+movingBlob2.width);
				} else {
					distanceX = movingBlob2.x-(movingBlob1.x+movingBlob1.width);
				}
				if(movingBlob1.y>movingBlob2.y){
					distanceY = movingBlob1.y-(movingBlob2.y+movingBlob2.height);
				} else {
					distanceY = movingBlob2.y-(movingBlob1.y+movingBlob1.height);
				}
				float velocityDifferenceX = Math.abs(movingBlob1.velocityX-movingBlob2.velocityX);
				float velocityDifferenceY = Math.abs(movingBlob1.velocityY-movingBlob2.velocityY);
				//checks if distance and velocity differences are under thresholds
				if(((distanceX<xEdgeDistanceLimit && distanceY<-yOverlapPercent*Math.min(movingBlob1.height, movingBlob2.height)) 
						|| (distanceY<yEdgeDistanceLimit && distanceX<-xOverlapPercent*Math.min(movingBlob1.width, movingBlob2.width)))&&
						velocityDifferenceX<unifyVelocityLimitX+
						velocityLimitIncreaseX*Math.max(movingBlob1.velocityX, movingBlob2.velocityX) &&
						velocityDifferenceY<unifyVelocityLimitY+
						velocityLimitIncreaseY*Math.max(movingBlob1.velocityY, movingBlob2.velocityY)){
					MovingBlob[] pair = {movingBlob1,movingBlob2};
					pairs.add(pair);
				}
{'fraction_non_alphanumeric': 0.09728892331525948, 'fraction_numerical': 0.014252517428350117, 'mean_word_length': 5.183908045977011, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '948064', 'n_tokens_mistral': 2497, 'n_tokens_neox': 2157, 'n_words': 395}