package app.brest.utils.geometry;

import java.io.Serializable;

/**
 * Created by ptitcois on 16/08/16.
 */
public class GPSPoint extends app.brest.utils.geometry.Point  implements Serializable {
    protected float mAccuracy;



    public GPSPoint()
    {
        mX=mY=0.0;
    }

    public GPSPoint(Point b)
    {
        mX=b.mX;
        mY=b.mY;
    }

    public GPSPoint(double x, double y)
    {
        mX=x;
        mY=y;
    }

    public GPSPoint(double x, double y, float acc)
    {
        mX=x;
        mY=y;
        mAccuracy=acc;
    }

    public float getAccuracy()
    {
        return mAccuracy;
    }

    public void setAccuracy(float acc)
    {
        mAccuracy=acc;
    }

    public double getDistanceWith(Point b)
    {
		double theta = mY - b.mY;
		double dist = Math.sin(deg2rad(mX)) * Math.sin(deg2rad(b.mX)) + Math.cos(deg2rad(mX)) * Math.cos(deg2rad(b.mX)) * Math.cos(deg2rad(theta));
		dist = Math.acos(dist);
		dist = rad2deg(dist);
		dist = dist * 60 * 1.1515;
		dist = dist * 1.609344 *1000;

		return (dist);

	}
    
    private static double rad2deg(double rad) {
		return (rad * 180 / Math.PI);
	}
    
    private static double deg2rad(double deg) {
		return (deg * Math.PI / 180.0);
	}

    public double getDistanceXWith(GPSPoint _b)
    {
        Point b = new GPSPoint(_b);
        b.mY=mY;

        return getDistanceWith(b);
    }


    public double getDistanceYWith(GPSPoint _b)
    {
        Point b = new GPSPoint(_b);
        b.mX=mX;

        return getDistanceWith(b);
    }

}
