Merge pull request #160 from LukasKorba/159

Enhancement of the clamping the index for the seed
This commit is contained in:
Francisco Gindre 2022-02-18 13:45:28 -03:00 committed by GitHub
commit 9e6d3a7525
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 6 deletions

View File

@ -16,16 +16,17 @@ struct Clamped<Value: Comparable> {
let range: ClosedRange<Value>
var wrappedValue: Value {
get { value }
set {
value = min(
max(range.lowerBound, newValue),
range.upperBound
)
}
set { value = clamp(newValue, using: range) }
}
init(wrappedValue: Value, _ range: ClosedRange<Value>) {
self.value = wrappedValue
self.range = range
value = clamp(wrappedValue, using: range)
}
private func clamp(_ value: Value, using range: ClosedRange<Value>) -> Value {
min(range.upperBound, max(range.lowerBound, wrappedValue))
}
}