/*
\brief 二分查找法,求多边形上方向是u的极点,设凸多边形是逆时针顺序的。
*/
int ExtremePoint_BinarySearch( const Point2D* p, int n, const Vector2D& u)
{
	int	a = 0, b = n, m;
	int upA = Direction(p[1] - p[0],u) , upM;
	if( upA<=0 && !IsAbove(p[n-1],p[0],u) )
		return 0;
	while(true)
	{
		m = (a + b) / 2;
		upM = Direction(p[(m+1)%n] - p[m],u);
		if( upM<=0 && !IsAbove(p[m-1],p[m],u) )
			return m;
		if( upA>0 )
		{
			if( upM<0 )
			{				//选择[a,m]
				b = m;		
			}
			else if( IsAbove(p[a],p[m],u) )
			{				//选择[a,m]
				b = m;		
			}
			else
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
		}
		else
		{
			if( upM>0 )
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
			else if( IsBelow(p[a],p[m],u) )
			{				//选择[a,m]
				b = m;
			}
			else
			{				//选择[m,b]
				a = m;
				upA = upM;
			}
		}
	}
	return 0;
}
Esempio n. 2
0
void BOCTX::InsMainList(SEGM2 * s)
{
	SEGM_LIST::iterator segm = m_S.begin();
	while (segm != m_S.end() and IsAbove(*s, *segm))
		++segm;
	// insert s below segm
	m_S.insert(segm, *s);
} // BOCTX::InsMainList
Esempio n. 3
0
bool CglList::MousePress(int x, int y, int button)
{
	if (button != SDL_BUTTON_LEFT || !IsAbove(x, y))
		return false;

	activeMousePress = true;
	MouseUpdate(x, y); // make sure place is up to date
	return true;
}
Esempio n. 4
0
bool ProfileDrawer::MousePress(int x, int y, int button)
{
	if (!IsAbove(x, y))
		return false;

	const float my = CInputReceiver::MouseY(y);
	const int selIndex = (int) ((start_y - my) / lineHeight);

	// switch the selected Timers showGraph value
	if ((selIndex >= 0) && (selIndex < profiler.profile.size())) {
		auto pi = profiler.profile.begin();
		std::advance(pi, selIndex);
		pi->second.showGraph = !pi->second.showGraph;
		return true;
	}

	return false;
}