package dataBase.search.distance;

import dataBase.subPicture.PixelByte;
import dataBase.subPicture.SubPicture;

public abstract class AbstractDistance {

	/**
	 * @param p1
	 * @param p2
	 * @return distance between SubPictures >= 0
	 */
	public float getDistance(SubPicture p1, SubPicture p2) {

		float sum=0;
		PixelByte[][] pixelsA = p1.pixels;
		PixelByte[][] pixelsB = p2.pixels;
		int partsX = SubPicture.partsX;
		int partsY = SubPicture.partsY;

		for(int i=0; i<partsY; i++){
			for(int j=0; j<partsX; j++){
				sum += getDistance(pixelsA[i][j],pixelsB[i][j]);
			}
		}
		return sum;
	}
	
	/**
	 * Distance between single Pixel objects.
	 * @param a
	 * @param b
	 * @return distance >= 0
	 */
	abstract public float getDistance(PixelByte a, PixelByte b);
}
