package app.brest.utils.geometry;

import java.io.Serializable;

/**
 * Created by ptitcois on 16/08/16.
 */


public class Point  implements Serializable {
    protected  double mX;
    protected  double mY;

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

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

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


    void setX(double x)
    {
        mX=x;
    }

    void setY(double y)
    {
        mY=y;
    }

    void set(double x, double y)
    {
        mX=x;
        mY=y;
    }

    public double getDistanceWith(Point b)
    {
        double dx = b.mX - mX;
        double dy = b.mY - mY;

        if(dx<0) dx=-dx;
        if(dy<0) dy=-dy;

        return Math.sqrt(dx*dx + dy*dy);
    }

    public String toString()
    {
    	return "("+mX+", "+mY+")";
    }
    
    public double getAngleRadWith(Point b)
    {
        double dx = b.mX - mX;
        double dy = b.mY - mY;

        return Math.atan(dx/dy);
    }

    public double getAngleDegWith(Point b)
    {
        return getAngleRadWith(b) *180/Math.PI;
    }


    public double getX(){return mX;}
    public double getY(){return mY;}

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

        return getDistanceWith(b);
    }


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

        return getDistanceWith(b);
    }

}
