计算几何点类模板

· · 个人记录

计算几何点类模板。

const double eps = 1e-8;

inline double sqr(double x)
    {return x*x;}

struct Point
{
    double x,y;

    Point() {} Point(double x,double y):x(x),y(y) {}

    friend Point operator + (Point a,Point b)
    {return Point(a.x+b.x,a.y+b.y);}

    friend Point operator - (Point a,Point b)
    {return Point(a.x-b.x,a.y-b.y);}

    friend double operator * (Point a,Point b)
    {return a.x*b.y-a.y*b.x;}

    friend double operator / (Point a,Point b)
    {return a.x*b.x+a.y*b.y;}

    friend bool operator == (Point a,Point b)
    {return fabs(a.x-b.x)<eps && fabs(a.y-b.y)<eps;}

    friend bool operator != (Point a,Point b)
    {return !(a==b);}

    friend bool operator < (Point a,Point b)
    {
        if(fabs(a.y-b.y)<eps)
            return a.x<b.x;
        return a.y<b.y;
    }

    friend double sqdis(Point a)
    {return sqr(a.x)+sqr(a.y);}

    friend void print(Point a)
    {printf("%.2lf %.2lf\n",a.x,a.y);}

};