Beispiel #1
0
bool Line2::intersect(const Rect2& r) const
{
  if (intersect(Segment2(r.bottomLeft(), r.topLeft())))
    return true;
    
  if (intersect(Segment2(r.topLeft(), r.topRight())))
    return true;

  if (intersect(Segment2(r.bottomLeft(), r.bottomRight())))
    return true;
    
  if (intersect(Segment2(r.bottomRight(), r.topRight())))
    return true;
    
  return false;
}
bool intersect(const Rect2& rect, ConstPointIterator2 begin, ConstPointIterator2 end)
{
  Segment2 bottom(rect.bottomLeft(), rect.bottomRight());
  Segment2 top(rect.topLeft(), rect.topRight());
  Segment2 left(rect.bottomLeft(), rect.topLeft());
  Segment2 right(rect.bottomRight(), rect.topRight());
    
  ConstPointIterator2 it;
  for (it = begin+1; it != end; ++it) {
    Segment2 seg(*it, *(it-1));
    if (seg.intersect(bottom)) return true;
    if (seg.intersect(top)) return true;    
    if (seg.intersect(left)) return true;        
    if (seg.intersect(right)) return true;        
  }
  return false;  
}
Beispiel #3
0
/*!
  The collision polygon calculated isn't optimal. We do it because it is used
  for drawing. For collision handling it is poor.
  
  \todo Refactor so collision and drawing polygon don't need to be the same
*/
PointsView::PointsView(Points2::iterator begin, Points2::iterator end) : iPoints(begin, end)
{
  // Find rectangular polygon that will enclose all
  // added points
  Rect2 r;
  Points2::iterator it;
  for (it = begin; it != end; ++it) {
    r = r.surround(*it);
  }
  
  Polygon2 p;
  p.push_back(r.bottomLeft());
  p.push_back(r.bottomRight());
  p.push_back(r.topRight());
  p.push_back(r.topLeft());      
  
  setCollisionPolygon(p);
}