17 lines
310 B
Go
17 lines
310 B
Go
|
// Copyright 2015 The Go Authors. All rights reserved.
|
||
|
// Use of this source code is governed by a BSD-style
|
||
|
// license that can be found in the LICENSE file.
|
||
|
|
||
|
package scale
|
||
|
|
||
|
// clamp clamps x to the range [0, 1].
|
||
|
func clamp(x float64) float64 {
|
||
|
if x < 0 {
|
||
|
return 0
|
||
|
}
|
||
|
if x > 1 {
|
||
|
return 1
|
||
|
}
|
||
|
return x
|
||
|
}
|