From 62cefc262e64c674c3b9d945911e692eb553abcc Mon Sep 17 00:00:00 2001
From: faiface <faiface@ksp.sk>
Date: Sun, 15 Oct 2017 19:42:13 +0200
Subject: [PATCH] add pixel.Clamp

---
 geometry.go | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/geometry.go b/geometry.go
index 0fe8a9d..1d538d3 100644
--- a/geometry.go
+++ b/geometry.go
@@ -5,6 +5,20 @@ import (
 	"math"
 )
 
+// Clamp returns x clamped to the interval [min, max].
+//
+// If x is less than min, min is returned. If x is more than max, max is returned. Otherwise, x is
+// returned.
+func Clamp(x, min, max float64) float64 {
+	if x < min {
+		return min
+	}
+	if x > max {
+		return max
+	}
+	return x
+}
+
 // Vec is a 2D vector type with X and Y coordinates.
 //
 // Create vectors with the V constructor:
-- 
GitLab