行/行ごとに1回のパスで境界(最初はコーナーではない)を検出するアルゴリズムは次のようになります。
for each horizontal line
previousTag = getTag( first line pixel ) // land or water in our example
for each pixel of the line
currentTag = getTag( this pixel )
if ( previousTag == currentTag )
continue // not a border
else
// We got a vertical border, do what is needed
previousTag = currentTag
endforeach
endforeach
同じことが垂直線にも当てはまります(xをインクリメントする代わりに、yをインクリメントします。ここで、垂直境界の代わりにコーナーを取得したかどうかもわかります。
for each vertical line
previousTag = getTag( first line pixel ) // land or water in our example
for each pixel of the line
currentTag = getTag( this pixel )
if ( previousTag == currentTag )
continue // not a border
else
if ( pixel on the right or on the left is a border )
// we got a corner
else
// we got a horizontal border
previousTag = currentTag
endforeach
endforeach
地形が動的でない限り、これは前処理である必要があります。とにかく各フレームでそれをしないでください!