#pragma once
namespace mycell{
struct HLine
{
int xLeft;
int xRight;
int y;
HLine():xLeft(0),xRight(0),y(0)
{}
HLine(int _x1,int _x2,int _y):xLeft(_x1),xRight(_x2),y(_y)
{}
void set(int _x1,int _x2,int _y)
{
xLeft=_x1;
xRight=_x2;
y=_y;
}
bool IsValid()const
{
return xLeft<xRight;
}
bool GetIntersect(HLine rhs,HLine& out)const
{
if(rhs.y==y){
out.xLeft=max(xLeft,rhs.xLeft);
out.xRight=min(xRight,rhs.xRight);
return out.xLeft<=out.xRight;
}
return false;
}
void Xor(HLine rhs,HLine& o1,HLine& o2)const
{
//_ASSERT(y==rhs.y);
o1.y=y;
o2.y=rhs.y;
if(y!=rhs.y || xRight<=rhs.xLeft || xLeft>=rhs.xRight){
o1=*this;
o2=rhs;
}else{
o1.xLeft=min(xLeft,rhs.xLeft);
o1.xRight=max(xLeft,rhs.xLeft);
o2.xLeft=min(xRight,rhs.xRight);
o2.xRight=max(xRight,rhs.xRight);
}
}
};
struct VLine
{
int yTop;
int yBottom;
int x;
VLine():yTop(0),yBottom(0),x(0)
{}
VLine(int _yTop,int _yBottom,int _x):yTop(_yTop),yBottom(_yBottom),x(_x)
{}
void set(int _yTop,int _yBottom,int _x)
{
yTop=_yTop;
yBottom=_yBottom;
x=_x;
}
void Xor(VLine rhs,VLine& o1,VLine& o2)const
{
//_ASSERT(x==rhs.x);
o1.x=x;o2.x=rhs.x;
if(x!=rhs.x || yBottom<=rhs.yTop || yTop>=rhs.yBottom){
o1=*this;
o2=rhs;
}else{
o1.yTop=min(yTop,rhs.yTop);
o1.yBottom=max(yTop,rhs.yTop);
o2.yTop=min(yBottom,rhs.yBottom);
o2.yBottom=max(yBottom,rhs.yBottom);
}
}
};
}//namespace mycell