Beispiel #1
0
/**
 * \brief Subtract a rectangle \a b from a rectangle \a a.
 * \param a The target.
 * \param b The rectangle to remove in \a a.
 * \param boxes The subparts of \a a after the subtraction.
 */
void bear::visual::screen::subtract
( const rectangle_type& a, const rectangle_type& b,
  rectangle_list& result ) const
{
  if ( !a.intersects(b) )
    result.push_front(a);
  else
    {
      const rectangle_type inter = a.intersection(b);

      if ( (inter.width() <= 8) || (inter.height() <= 8) )
        result.push_front(a);
      else
        {
          if ( a.left() != inter.left() )
            result.push_front
              ( rectangle_type( a.left(), a.bottom(), inter.left(), a.top() ) );

          if ( a.top() != inter.top() )
            result.push_front
              ( rectangle_type
                ( inter.left(), inter.top(), inter.right(), a.top() ) );

          if ( a.right() != inter.right() )
            result.push_front
              ( rectangle_type
                ( inter.right(), a.bottom(), a.right(), a.top() ) );

          if ( a.bottom() != inter.bottom() )
            result.push_front
              ( rectangle_type
                ( inter.left(), a.bottom(), inter.right(), inter.bottom() ) );
        }
    }
} // screen::subtract()
Beispiel #2
0
/**
 * \brief Tell if a rectangle intersects a rectangle from a list.
 * \param r The rectangle to check.
 * \param boxes The boxes to compare to.
 */
bool bear::visual::screen::intersects_any
( const rectangle_type& r, const rectangle_list& boxes ) const
{
  bool result=false;
  rectangle_list::const_iterator it;

  for (it=boxes.begin(); !result && (it!=boxes.end()); ++it)
    if ( r.intersects(*it) )
      {
        const rectangle_type inter = r.intersection(*it);
        result = (inter.width() > 0) && (inter.height() > 0);
      }

  return result;
} // screen::intersects_any()