Ejemplo n.º 1
0
float BBFind::Rectangle::intersecting(const Rectangle &rectA, const Rectangle &rectB)
{
   // Returns a ratio representing how much of the smaller
   // rectangle is inside the larger rectangle.

   if(!touching(rectA, rectB)) return 0.0f;
	float areaA = rectA.width * rectA.height;
	float areaB = rectB.width * rectB.height;
	// Check if one completely contains another
   if(areaA > areaB)
	{
		if(rectB.left()   >= rectA.left() &&
			rectB.right()  <= rectA.right() &&
			rectB.top()    >= rectA.top() &&
			rectB.bottom() <= rectA.bottom())
         return 1.0f;
	}
	else
	{
		if(rectA.left()   >= rectB.left() &&
			rectA.right()  <= rectB.right() &&
			rectA.top()    >= rectB.top() &&
			rectA.bottom() <= rectB.bottom())
         return 1.0f;
	}
	// Find intersection rectangle
	int left   = std::max(rectA.left(),   rectB.left());
	int top    = std::max(rectA.top(),    rectB.top());
	int right  = std::min(rectA.right(),  rectB.right());
	int bottom = std::min(rectA.bottom(), rectB.bottom());
	float intersectArea = (right - left) * (bottom - top);
	if(areaA > areaB) return intersectArea / areaB;
	return intersectArea / areaA;
}
Ejemplo n.º 2
0
void AreaDxfRead::OnReadVertex(const double* s, const CVertex& v)
{
	bool reverse_span = false;

	if(m_curve)
	{
		bool is_touching = false;

		if(touching(s, m_previous_end))
		{
			is_touching = true;
		}
		else if(touching(v.m_p, m_previous_end))
		{
			is_touching = true;
			reverse_span = true;
		}

		// if end point touching
		if(!is_touching)
		{
			// add curve
			m_area->m_curves.push_back(*m_curve);
			m_curve = NULL;
		}
	}

	if(m_curve == NULL)
	{
		// start a new curve
		m_curve = new CCurve();
		m_curve->m_vertices.push_back(CVertex(0, s[0], s[1], 0, 0));
	}

	// add to curve
	if(reverse_span)m_curve->m_vertices.push_back(CVertex(-v.m_type, s[0], s[1], v.m_c[0], v.m_c[1]));
	else m_curve->m_vertices.push_back(v);

	// remember end point
	memcpy(m_previous_end, v.m_p, 2*sizeof(double));
}
Ejemplo n.º 3
0
void General::checkCollision(Input *input, SDL_Rect &s1Rect, SDL_Rect &e1Rect, int screenw, int screenh) {
	if (touching(s1Rect, e1Rect)) {
		input->setGameDone();
	}

	if (s1Rect.y < 0) {
		s1Rect.y = 0;
	}
	
	if ((s1Rect.y + s1Rect.h) > screenh) {
		s1Rect.y = screenh - s1Rect.h;
	}
	
	if (s1Rect.x < 0) {
		s1Rect.x = 0;
	}
	
	if ((s1Rect.x + s1Rect.w) > screenw) {
		s1Rect.x = screenw - s1Rect.w;
	}
}
Ejemplo n.º 4
0
bool Frame::overlaps (Frame& frame)
{
	return touching(current, frame.current);
}