Skip to content

Fix preconditions and generic types#1

Merged
yeldarby merged 1 commit intomasterfrom
yeldarby-fixes
Jan 15, 2018
Merged

Fix preconditions and generic types#1
yeldarby merged 1 commit intomasterfrom
yeldarby-fixes

Conversation

@yeldarby
Copy link
Copy Markdown
Owner

The preconditions prevented reading row, column, and channel 0. And the lack of a type constraint on the generic classes were preventing from creating an extension that performed arithmetic operations on the pixel data.

(eg this would fail because yo ucouldn't compare image[r, c, 0] to 0; constraining <T> to a BinaryInteger should fix it (and it wouldn't even make sense for <T> to be something weird like a UIView or something like that):

extension SGLImage {
	func toASCII() {
		let image = self

		var output = ""
		for r in 0..<image.height {
			if(r % 10 != 0) { continue }
			for c in 0..<image.width {
				if(c % 10 != 0) { continue }
				
				if(image[r, c, 0] > 0) {
					output += "+"
				} else {
					output += " "
				}
			}
			output += "\n"
		}
	}
}

(Fixes SwiftGL#2)

The preconditions prevented reading row, column, and channel 0. And the lack of a type constraint on the generic classes were preventing from creating an extension that performed arithmetic operations on the pixel data.

(eg this would fail because yo ucouldn't compare `image[r, c, 0]` to 0; constraining `<T>` to a `BinaryInteger` should fix it (and it wouldn't even make sense for `<T>` to be something weird like a `UIView` or something like that):
```
extension SGLImage {
	func toASCII() {
		let image = self

		var output = ""
		for r in 0..<image.height {
			if(r % 10 != 0) { continue }
			for c in 0..<image.width {
				if(c % 10 != 0) { continue }
				
				if(image[r, c, 0] > 0) {
					output += "+"
				} else {
					output += " "
				}
			}
			output += "\n"
		}
	}
}
```
@yeldarby yeldarby merged commit b09cd8a into master Jan 15, 2018
@yeldarby yeldarby deleted the yeldarby-fixes branch January 15, 2018 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reading the first row/column/channel

1 participant