#pragma once

#include <math.h>
typedef struct _XPoint
{
    int x;
    int y;
#ifdef __cplusplus
    float Dist(_XPoint p)
    {
        int dx = x - p.x; dx = dx*dx;
        int dy = y - p.y; dy = dy * dy;
        return sqrt((float)dx + dy);
    }
#endif
}XPoint;

typedef struct _XRect
{
    int left;
    int right;
    int top;
    int bottom;
	
#ifdef __cplusplus
    int Width() { return right - left + 1; }
    int Height() { return bottom - top + 1; }
    int Area() {
        return Width()*Height();
    }
    void Zero() { left = right = top = bottom = 0; }

    void Union(_XRect &r2)
    {
        if (left > r2.left)left = r2.left;
        if(right < r2.right) right = r2.right;
        if(top > r2.top)top = r2.top;
        if(bottom < r2.bottom) bottom = r2.bottom;
    }
    //bool Intersect(XPoint p1, XPoint p2)
    //{

    //}
#endif
}XRect;
