package cz.vutbr.feec.gui;

import java.awt.Point;

import cz.vutbr.feec.math.DistanceAndConversion;

public class MappingCoordinates {
	private static final double[] refPointGps1 = {37.97d,23.72d};
	private static final Point refPointImg1 = new Point(353,415);
	private static final double[] refPointGps2 = {38.7d,-9.1d};
	private static final Point refPointImg2 = new Point(23,405);
	private static final double[] zeroPointGps = {70.5d,-17.0d};
	private static final Point zeroPointPict = new Point(0,0);

	private static final double[] refPointGps11 = {46.05d,14.50d};
	private static final Point refPointImg11 = new Point(259,314);
	private static final double[] refPointGps12 = {50.1d,14.4d};
	private static final Point refPointImg12 = new Point(256,264);

	
	
	public static Point getPositionXY(double lng, double lat) {
		Point bod = new Point();
		double kX = 0;
		double kY = 0;		
		int x1 = refPointImg1.x;
		int y1 = refPointImg1.y;
		int x2 = refPointImg2.x;
		int y2 = refPointImg2.y;
		double lat1 = refPointGps1[0];
		double lng1 = refPointGps1[1];
		double lat2 = refPointGps2[0];
		double lng2 = refPointGps2[1];
		double x=0,y=0;	
		
		int x11 = refPointImg11.x;
		int y11 = refPointImg11.y;
		int x12 = refPointImg12.x;
		int y12 = refPointImg12.y;
		double lat11 = refPointGps11[0];
		double lng11 = refPointGps11[1];
		double lat12 = refPointGps12[0];
		double lng12 = refPointGps12[1];
		
		
		double distanceObrRef1 = Math.sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
		double distanceRealRef1 = DistanceAndConversion.getDistance2(lat1, lng1, lat2, lng2);
			
		double distanceObrRef2 = Math.sqrt((x12-x11)*(x12-x11)+(y12-y11)*(y12-y11));
		double distanceRealRef2 = DistanceAndConversion.getDistance2(lat11, lng11, lat12, lng12);
		
		kX = distanceObrRef1/distanceRealRef1;
		kY = distanceObrRef2/distanceRealRef2;
		
		
		double xNorm = DistanceAndConversion.getDistance2(lat, lng, lat, zeroPointGps[1]);
		double yNorm = DistanceAndConversion.getDistance2(lat, lng, zeroPointGps[0], lng);
			
		x = kX*xNorm;
		y = kY*yNorm;
		
		bod.x = (int) x;
		bod.y = (int) y;
		
		
/*		
		for(int i=0; i<MainWindow.height(); i++) {
			for(int j=0; j<MainWindow.width(); j++) {
				
			}
		}
*/		
		return bod;
	}
	
	/**
	 * 
	 * @param x
	 * @param y
	 * @return souradnice longitude a latitude
	 */
	public static double[] getPositionGps(int x, int y) {
		double[] bod = new double[2];
		
		return bod;
	}
}
