Last active
August 29, 2015 14:02
-
-
Save PadraigK/d6d64787510136558552 to your computer and use it in GitHub Desktop.
Help me get better at Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func rangeOfPixelsForRow(row: Int) -> Range<Int> | |
{ | |
return row * imageSize.width..(row+1)*imageSize.width | |
} | |
func rangeOfPixelsForColumn(column: Int) -> StridedRangeGenerator<Int> | |
{ | |
return (column..imageSize.height*imageSize.width).by(imageSize.width) | |
} | |
func indicesOfEdgePixels(inset: Int) -> Array<Int> | |
{ | |
var indices = Int[]() | |
for pixelIndex in rangeOfPixelsForRow(0) | |
{ | |
indices.append(pixelIndex) | |
} | |
for pixelIndex in rangeOfPixelsForRow(imageSize.height-1) | |
{ | |
indices.append(pixelIndex) | |
} | |
for pixelIndex in rangeOfPixelsForColumn(0) | |
{ | |
indices.append(pixelIndex) | |
} | |
for pixelIndex in rangeOfPixelsForColumn(imageSize.width-1) | |
{ | |
indices.append(pixelIndex) | |
} | |
return indices | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's currently a bug where this code double counts corner pixels, but my main questions are: