Sources/CryGame C++/Solution1/CryGame/XArea.cpp
//////////////////////////////////////////////////////////////////////
//adds segment to area, calculates line parameters y=kx+b, sets horizontal/vertical flags

adds segment to area, calculates line parameters y=kx+b, sets horizontal/vertical flags
adds segment to area calculates line parameters y = kx + b sets horizontal / vertical flags
void	CXArea::AddSegment(const a2DPoint& p0, const a2DPoint& p1)
{
	a2DSegment*	newSegment = new a2DSegment;
	if(p1.y == p0.y)
		newSegment->isHorizontal = true;
	else
		newSegment->isHorizontal = false;
	if( p0.x < p1.x )
	{
		newSegment->bbox.min.x = p0.x;
		newSegment->bbox.max.x = p1.x;
	}
	else
	{
		newSegment->bbox.min.x = p1.x;
		newSegment->bbox.max.x = p0.x;
	}
	if( p0.y < p1.y )
	{
		newSegment->bbox.min.y = p0.y;
		newSegment->bbox.max.y = p1.y;
	}
	else
	{
		newSegment->bbox.min.y = p1.y;
		newSegment->bbox.max.y = p0.y;
	}
	if(!newSegment->isHorizontal)
	{
		if(p1.x == p0.x)
		{
			newSegment->k = 0;
			newSegment->b = p0.x;
		}
		else
		{
			newSegment->k = (p1.y - p0.y)/(p1.x - p0.x);
			newSegment->b = p0.y - newSegment->k*p0.x;
		}
	}
	else
	{
			newSegment->k = 0;
			newSegment->b = 0;
	}
	m_vpSegments.push_back( newSegment );
}
void CXArea :: AddSegment ( const a2DPoint & p0 , const a2DPoint & p1 ) { a2DSegment * newSegment = new a2DSegment ; if ( p1 . y == p0 . y ) newSegment -> isHorizontal = true ; else newSegment -> isHorizontal = false ; if ( p0 . x < p1 . x ) { newSegment -> bbox . min . x = p0 . x ; newSegment -> bbox . max . x = p1 . x ; } else { newSegment -> bbox . min . x = p1 . x ; newSegment -> bbox . max . x = p0 . x ; } if ( p0 . y < p1 . y ) { newSegment -> bbox . min . y = p0 . y ; newSegment -> bbox . max . y = p1 . y ; } else { newSegment -> bbox . min . y = p1 . y ; newSegment -> bbox . max . y = p0 . y ; } if ( ! newSegment -> isHorizontal ) { if ( p1 . x == p0 . x ) { newSegment -> k = 0 ; newSegment -> b = p0 . x ; } else { newSegment -> k = ( p1 . y - p0 . y ) / ( p1 . x - p0 . x ) ; newSegment -> b = p0 . y - newSegment -> k * p0 . x ; } } else { newSegment -> k = 0 ; newSegment -> b = 0 ; } m_vpSegments . push_back ( newSegment ) ; }
adds segment to area, calculates line parameters y=kx+b, sets horizontal/vertical flags
adds segment to area calculates line parameters y = kx + b sets horizontal / vertical flags
//if this is horizontal line set flag. This segment is needed only for distance calculations
 //if this is vertical line - spesial case
