Пример #1
0
bool wxBlockDouble::Combine(const wxBlockDouble &b)
{
    if (!Touches(b)) return false;
    if (Contains(b)) return true;
    if (b.Contains(*this))
    {
        *this = b;
        return true;
    }

    wxBlockDouble unionBlock;
    Union( *this, b, &unionBlock );

    if (unionBlock.IsEmpty()) return false;

    // at least one of the two blocks has to be at each corner of the union
    if (((unionBlock.GetLeftTop() == GetLeftTop()) || (unionBlock.GetLeftTop() == b.GetLeftTop())) &&
        ((unionBlock.GetRightTop() == GetRightTop()) || (unionBlock.GetRightTop() == b.GetRightTop())) &&
        ((unionBlock.GetLeftBottom() == GetLeftBottom()) || (unionBlock.GetLeftBottom() == b.GetLeftBottom())) &&
        ((unionBlock.GetRightBottom() == GetRightBottom()) || (unionBlock.GetRightBottom() == b.GetRightBottom())) )
    {
        *this = unionBlock;
        return true;
    }

    return false;
}
Пример #2
0
bool wxRangeInt::Combine( const wxRangeInt &r, bool only_if_touching )
{
    if (only_if_touching)
    {
        if (Touches(r))
        {
            *this += r;
            return true;
        }
    }
    else if (!IsEmpty() && !r.IsEmpty())
    {
        bool added = false;
        if (r.m_min < m_min) { m_min = r.m_min; added = true; }
        if (r.m_max > m_max) { m_max = r.m_max; added = true; }
        return added;
    }
    return false;
}
Пример #3
0
bool wxSheetBlock::Combine(const wxSheetBlock &block)
{
    
    //if (IsEmpty() || block.IsEmpty()) return false;
    if (!Touches(block)) return false;    
    if (Contains(block)) return true;
    if (block.Contains(*this))
    {
        *this = block;
        return true;
    }
    
    // FIXME I forgot why wxSheetBlock::Combine needs this code? Isn't Contains good enough?
    const wxSheetBlock uBlock(Union(block));
    if (uBlock.IsEmpty()) return false;

    // ugh this is really ugly, I can't figure a better way though
/*      
    // at least one of the two blocks has to be at each corner of the union
    if (((uBlock.GetLeftTop() == GetLeftTop()) || (uBlock.GetLeftTop() == block.GetLeftTop())) &&
        ((uBlock.GetRightTop() == GetRightTop()) || (uBlock.GetRightTop() == block.GetRightTop())) &&
        ((uBlock.GetLeftBottom() == GetLeftBottom()) || (uBlock.GetLeftBottom() == block.GetLeftBottom())) &&
        ((uBlock.GetRightBottom() == GetRightBottom()) || (uBlock.GetRightBottom() == block.GetRightBottom())) )
    {
        *this = uBlock;
        return true;
    }
*/

    const int t = GetTop();
    const int b = GetBottom();
    const int l = GetLeft();
    const int r = GetRight();

    const int b_t = block.GetTop();
    const int b_b = block.GetBottom();
    const int b_l = block.GetLeft();
    const int b_r = block.GetRight();

    const int ub_t = uBlock.GetTop();
    const int ub_b = uBlock.GetBottom();
    const int ub_l = uBlock.GetLeft();
    const int ub_r = uBlock.GetRight();

    if ( ( ((ub_t==t)&&(ub_l==l)) || ((ub_t==b_t)&&(ub_l==b_l)) ) &&
         ( ((ub_t==t)&&(ub_r==r)) || ((ub_t==b_t)&&(ub_r==b_r)) ) &&
         ( ((ub_b==b)&&(ub_l==l)) || ((ub_b==b_b)&&(ub_l==b_l)) ) &&
         ( ((ub_b==b)&&(ub_r==r)) || ((ub_b==b_b)&&(ub_r==b_r)) ) )
    {
        *this = uBlock;
        return true;
    }

    return false;


/*
    const int t = GetTop();
    const int b = GetBottom();
    const int l = GetLeft();
    const int r = GetRight();
    if ((t < b) || (l < r)) return false; // this is empty

    const int b_t = block.GetTop();
    const int b_b = block.GetBottom();
    const int b_l = block.GetLeft();
    const int b_r = block.GetRight();
    if ((b_t < b_b) || (b_l < b_r)) return false; // block is empty

    // if this contains other block
    if ((t <= b_t) && (l <= b_l) && (b >= b_b) && (r >= b_r))
        return true;
    // if block contains this
    if ((t >= b_t) && (l >= b_l) && (b <= b_b) && (r <= b_r))
    {
        *this = block;
        return true;
    }
    

    const int ub_t = uBlock.GetTop();
    const int ub_b = uBlock.GetBottom();
    const int ub_l = uBlock.GetLeft();
    const int ub_r = uBlock.GetRight();

    if ( ( ((ub_t==t)&&(ub_l==l)) || ((ub_t==b_t)&&(ub_l==b_l)) ) &&
         ( ((ub_t==t)&&(ub_r==r)) || ((ub_t==b_t)&&(ub_r==b_r)) ) &&
         ( ((ub_b==b)&&(ub_l==l)) || ((ub_b==b_b)&&(ub_l==b_l)) ) &&
         ( ((ub_b==b)&&(ub_r==r)) || ((ub_b==b_b)&&(ub_r==b_r)) ) )
    {
        *this = uBlock;
        return true;
    }

    return false;
*/    
}