的算法在每行單次檢測的邊界(但不角落起初)/行會:
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,你增加ÿ我們可以在這裏也知道,如果我們得到了一個角球,而不是垂直邊界:
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
這應該是一個預處理,除非你的地形動態,不要那樣做每幀!