Rename and simplify wxGridBlockCoords::ContainsBlock()
Change the return type of this function to a simple and clear bool instead of 3-valued int requiring a special explanation. This is simpler and not any less efficient as checking for whether one block contains another or the other one contains this one are separate operations anyhow. Rename the function to a more grammatically correct name. Also move it inline as it's now trivial enough for this to be worth it.
This commit is contained in:
@@ -823,11 +823,12 @@ public:
|
|||||||
m_leftCol <= cell.GetCol() && cell.GetCol() <= m_rightCol;
|
m_leftCol <= cell.GetCol() && cell.GetCol() <= m_rightCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether the blocks contain each other.
|
// Return whether this blocks fully contains another one.
|
||||||
// returns 1, if this block contains the other,
|
bool ContainsBlock(const wxGridBlockCoords& other) const
|
||||||
// -1, if the other block contains this one,
|
{
|
||||||
// 0, otherwise
|
return m_topRow <= other.m_topRow && other.m_bottomRow <= m_bottomRow &&
|
||||||
int ContainBlock(const wxGridBlockCoords& other) const;
|
m_leftCol <= other.m_leftCol && other.m_rightCol <= m_rightCol;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculates the result blocks by subtracting the other block from this
|
// Calculates the result blocks by subtracting the other block from this
|
||||||
// block. splitOrientation can be wxVERTICAL or wxHORIZONTAL.
|
// block. splitOrientation can be wxVERTICAL or wxHORIZONTAL.
|
||||||
|
@@ -1924,14 +1924,12 @@ public:
|
|||||||
bool ContainsCell(const wxGridCellCoords& cell) const;
|
bool ContainsCell(const wxGridCellCoords& cell) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Whether the blocks contain each other.
|
Check whether this block contains another one.
|
||||||
|
|
||||||
@return
|
@return
|
||||||
1, if this block contains the other,
|
@true if @a other is entirely contained within this block.
|
||||||
-1, if the other block contains this one,
|
|
||||||
0, otherwise.
|
|
||||||
*/
|
*/
|
||||||
int ContainBlock(const wxGridBlockCoords& other) const;
|
int ContainsBlock(const wxGridBlockCoords& other) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Calculates the result blocks by subtracting the other block from this
|
Calculates the result blocks by subtracting the other block from this
|
||||||
|
@@ -1140,21 +1140,6 @@ const wxGridCornerHeaderRenderer& wxGridCellAttrProvider::GetCornerRenderer()
|
|||||||
// wxGridBlockCoords
|
// wxGridBlockCoords
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
int wxGridBlockCoords::ContainBlock(const wxGridBlockCoords& other) const
|
|
||||||
{
|
|
||||||
// returns 1, if this block contains the other,
|
|
||||||
// -1, if the other block contains this one,
|
|
||||||
// 0, otherwise
|
|
||||||
if ( m_topRow <= other.m_topRow && other.m_bottomRow <= m_bottomRow &&
|
|
||||||
m_leftCol <= other.m_leftCol && other.m_rightCol <= m_rightCol )
|
|
||||||
return 1;
|
|
||||||
else if ( other.m_topRow <= m_topRow && m_bottomRow <= other.m_bottomRow &&
|
|
||||||
other.m_leftCol <= m_leftCol && m_rightCol <= other.m_rightCol )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxGridBlockDiffResult
|
wxGridBlockDiffResult
|
||||||
wxGridBlockCoords::Difference(const wxGridBlockCoords& other,
|
wxGridBlockCoords::Difference(const wxGridBlockCoords& other,
|
||||||
int splitOrientation) const
|
int splitOrientation) const
|
||||||
|
@@ -741,19 +741,14 @@ void wxGridSelection::MergeOrAddBlock(wxVectorGridBlockCoords& blocks,
|
|||||||
{
|
{
|
||||||
const wxGridBlockCoords& block = blocks[n];
|
const wxGridBlockCoords& block = blocks[n];
|
||||||
|
|
||||||
switch ( block.ContainBlock(newBlock) )
|
if ( block.ContainsBlock(newBlock) )
|
||||||
|
return;
|
||||||
|
|
||||||
|
if ( newBlock.ContainsBlock(block) )
|
||||||
{
|
{
|
||||||
case 1:
|
blocks.erase(blocks.begin() + n);
|
||||||
return;
|
n--;
|
||||||
|
count--;
|
||||||
case -1:
|
|
||||||
blocks.erase(blocks.begin() + n);
|
|
||||||
n--;
|
|
||||||
count--;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1337,17 +1337,19 @@ TEST_CASE("GridBlockCoords::ContainsCell", "[grid]")
|
|||||||
CHECK(!wxGridBlockCoords(1, 1, 3, 3).ContainsCell(wxGridCellCoords(5, 5)));
|
CHECK(!wxGridBlockCoords(1, 1, 3, 3).ContainsCell(wxGridCellCoords(5, 5)));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("GridBlockCoords::ContainBlock", "[grid]")
|
TEST_CASE("GridBlockCoords::ContainsBlock", "[grid]")
|
||||||
{
|
{
|
||||||
wxGridBlockCoords block1(1, 1, 5, 5);
|
wxGridBlockCoords block1(1, 1, 5, 5);
|
||||||
wxGridBlockCoords block2(1, 1, 3, 3);
|
wxGridBlockCoords block2(1, 1, 3, 3);
|
||||||
wxGridBlockCoords block3(2, 2, 7, 7);
|
wxGridBlockCoords block3(2, 2, 7, 7);
|
||||||
wxGridBlockCoords block4(10, 10, 12, 12);
|
wxGridBlockCoords block4(10, 10, 12, 12);
|
||||||
|
|
||||||
CHECK(block1.ContainBlock(block2) == 1);
|
CHECK( block1.ContainsBlock(block2));
|
||||||
CHECK(block2.ContainBlock(block1) == -1);
|
CHECK(!block2.ContainsBlock(block1));
|
||||||
CHECK(block1.ContainBlock(block3) == 0);
|
CHECK(!block1.ContainsBlock(block3));
|
||||||
CHECK(block1.ContainBlock(block4) == 0);
|
CHECK(!block1.ContainsBlock(block4));
|
||||||
|
CHECK(!block3.ContainsBlock(block1));
|
||||||
|
CHECK(!block4.ContainsBlock(block1));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("GridBlockCoords::Difference", "[grid]")
|
TEST_CASE("GridBlockCoords::Difference", "[grid]")
|
||||||
|
Reference in New Issue
Block a user