Go to the documentation of this file.00001
00002
00003
00004
00005 #include "SgSystem.h"
00006 #include "SgConnCompIterator.h"
00007
00008 using namespace std;
00009
00010
00011
00012 SgConnCompIterator::SgConnCompIterator(const SgPointSet& set, int boardSize)
00013 : m_set(set),
00014 m_nextPoint(SgPointUtil::Pt(1, 1) - 1),
00015 m_lastBoardPoint(SgPointUtil::Pt(boardSize, boardSize))
00016 {
00017 SG_ASSERTRANGE(boardSize, 1, SG_MAX_SIZE);
00018 operator++();
00019 }
00020
00021 void SgConnCompIterator::operator++()
00022 {
00023 ++m_nextPoint;
00024 while ((m_nextPoint <= m_lastBoardPoint) && !(m_set[m_nextPoint]))
00025 ++m_nextPoint;
00026 if (m_nextPoint <= m_lastBoardPoint)
00027 {
00028 m_nextSet = m_set.ConnComp(m_nextPoint);
00029 m_set -= m_nextSet;
00030 }
00031 }
00032
00033 const SgPointSet& SgConnCompIterator::operator*() const
00034 {
00035 SG_ASSERT(m_nextPoint <= m_lastBoardPoint);
00036 return m_nextSet;
00037 }
00038
00039
00040
00041 SgConnComp8Iterator::SgConnComp8Iterator(const SgPointSet& set, int boardSize)
00042 : m_set(set),
00043 m_nextPoint(SgPointUtil::Pt(1, 1) - 1),
00044 m_lastBoardPoint(SgPointUtil::Pt(boardSize, boardSize))
00045 {
00046 SG_ASSERTRANGE(boardSize, 1, SG_MAX_SIZE);
00047 operator++();
00048 }
00049
00050 void SgConnComp8Iterator::operator++()
00051 {
00052 ++m_nextPoint;
00053 while ((m_nextPoint <= m_lastBoardPoint) && !(m_set[m_nextPoint]))
00054 ++m_nextPoint;
00055 if (m_nextPoint <= m_lastBoardPoint)
00056 {
00057 m_nextSet = m_set.ConnComp8(m_nextPoint);
00058 m_set -= m_nextSet;
00059 }
00060 }
00061
00062 const SgPointSet& SgConnComp8Iterator::operator*() const
00063 {
00064 SG_ASSERT(m_nextPoint <= m_lastBoardPoint);
00065 return m_nextSet;
00066 }
00067
00068
00069