Skip to content

Commit

Permalink
#5382: Fix and clarify documentation in PatchIterators.h
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Dec 6, 2020
1 parent efb4ecf commit 9cc2a90
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions libs/patch/PatchIterators.h
Expand Up @@ -151,73 +151,73 @@ class SinglePatchColumnIterator :
}
};

// An iterator traversing a the given patch column-wise, iterating over
// one row after the other (which are optionally constrained to [startRow..endRow])
// An iterator traversing a given patch column-wise, iterating over
// one column after the other (which are optionally constrained to [startColumn..endColumn])
class ColumnWisePatchIterator :
public PatchControlIterator
{
public:
ColumnWisePatchIterator(IPatch& patch) :
ColumnWisePatchIterator(patch, 0, patch.getHeight() - 1)
ColumnWisePatchIterator(patch, 0, patch.getWidth() - 1)
{
assert(patch.getHeight() > 0);
assert(patch.getWidth() > 0);
}

ColumnWisePatchIterator(IPatch& patch, std::size_t startRow, std::size_t endRow) :
PatchControlIterator(patch, startRow, 0,
std::bind(ColumnWisePatchIterator::moveNext, std::placeholders::_1, std::ref(patch), endRow))
ColumnWisePatchIterator(IPatch& patch, std::size_t startColumn, std::size_t endColumn) :
PatchControlIterator(patch, 0, startColumn,
std::bind(ColumnWisePatchIterator::moveNext, std::placeholders::_1, std::ref(patch), endColumn))
{}

private:
static void moveNext(PatchControlIterator& it, const IPatch& patch, std::size_t endRow)
static void moveNext(PatchControlIterator& it, const IPatch& patch, std::size_t endColumn)
{
auto nextColumn = it.getColumn() + 1;
auto nextRow = it.getRow();
auto nextRow = it.getRow() + 1;
auto nextColumn = it.getColumn();

if (nextColumn >= patch.getWidth())
if (nextRow >= patch.getHeight())
{
// Advance to the next row
// Advance to the next column
// If that doesn't succeed, just leave the indices out of bounds
if (++nextRow <= endRow)
if (++nextColumn <= endColumn)
{
nextColumn = 0;
nextRow = 0;
}
}

it.set(nextRow, nextColumn);
}
};

// An iterator traversing a the given patch row-wise, iterating over
// one column after the other (which are optionally constrained to [startColumn..endColumn])
// An iterator traversing a given patch row-wise, iterating over
// one row after the other (which are optionally constrained to [startRow..endRow])
class RowWisePatchIterator :
public PatchControlIterator
{
public:
RowWisePatchIterator(IPatch& patch) :
RowWisePatchIterator(patch, 0, patch.getWidth() - 1)
RowWisePatchIterator(patch, 0, patch.getHeight() - 1)
{
assert(patch.getWidth() > 0);
assert(patch.getHeight() > 0);
}

RowWisePatchIterator(IPatch& patch, std::size_t startColumn, std::size_t endColumn) :
PatchControlIterator(patch, startColumn, 0,
std::bind(RowWisePatchIterator::moveNext, std::placeholders::_1, std::ref(patch), endColumn))
RowWisePatchIterator(IPatch& patch, std::size_t startRow, std::size_t endRow) :
PatchControlIterator(patch, startRow, 0,
std::bind(RowWisePatchIterator::moveNext, std::placeholders::_1, std::ref(patch), endRow))
{}

private:
static void moveNext(PatchControlIterator& it, const IPatch& patch, std::size_t endColumn)
static void moveNext(PatchControlIterator& it, const IPatch& patch, std::size_t endRow)
{
auto nextRow = it.getRow() + 1;
auto nextColumn = it.getColumn();
auto nextColumn = it.getColumn() + 1;
auto nextRow = it.getRow();

if (nextRow >= patch.getHeight())
if (nextColumn >= patch.getWidth())
{
// Advance to the next column
// Advance to the next row
// If that doesn't succeed, just leave the indices out of bounds
if (++nextColumn <= endColumn)
if (++nextRow <= endRow)
{
nextRow = 0;
nextColumn = 0;
}
}

Expand Down

0 comments on commit 9cc2a90

Please sign in to comment.