From 26cf80f38f7812431d8abd0380594e3d03498ff5 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 16 Nov 2011 13:55:34 -0800 Subject: [PATCH] Added an integer MathUtil with clamp(low, value, high). --- src/main/java/pythagoras/i/MathUtil.java | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/java/pythagoras/i/MathUtil.java diff --git a/src/main/java/pythagoras/i/MathUtil.java b/src/main/java/pythagoras/i/MathUtil.java new file mode 100644 index 0000000..b8a9399 --- /dev/null +++ b/src/main/java/pythagoras/i/MathUtil.java @@ -0,0 +1,20 @@ +// +// Pythagoras - a collection of geometry classes +// http://github.com/samskivert/pythagoras + +package pythagoras.i; + +/** + * Math utility methods. + */ +public class MathUtil +{ + /** + * Clamps the supplied {@code value} to between {@code low} and {@code high} (both inclusive). + */ + public static int clamp (int low, int value, int high) { + if (value < low) return low; + if (value > high) return high; + return value; + } +}