Browse Source

added clampScalar

Darren Ranalli 21 years ago
parent
commit
384f9df938
1 changed files with 17 additions and 0 deletions
  1. 17 0
      direct/src/showbase/PythonUtil.py

+ 17 - 0
direct/src/showbase/PythonUtil.py

@@ -909,6 +909,23 @@ def mostDerivedLast(classList):
         return result
         return result
     classList.sort(compare)
     classList.sort(compare)
 
 
+def clampScalar(value, a, b):
+    # calling this ought to be faster than calling both min and max
+    if a < b:
+        if value < a:
+            return a
+        elif value > b:
+            return b
+        else:
+            return value
+    else:
+        if value < b:
+            return b
+        elif value > a:
+            return a
+        else:
+            return value
+
 def weightedChoice(choiceList, rng=random.random, sum=None):
 def weightedChoice(choiceList, rng=random.random, sum=None):
     """given a list of (weight,item) pairs, chooses an item based on the
     """given a list of (weight,item) pairs, chooses an item based on the
     weights. rng must return 0..1. if you happen to have the sum of the
     weights. rng must return 0..1. if you happen to have the sum of the