From 9449c113df58af37f4754069826ebdbf4e3d7549 Mon Sep 17 00:00:00 2001 From: Darren Ranalli Date: Mon, 29 Jan 2007 23:17:08 +0000 Subject: [PATCH] added pivotScalar, rad90/180/270/360 --- direct/src/showbase/PythonUtil.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/direct/src/showbase/PythonUtil.py b/direct/src/showbase/PythonUtil.py index 11497cd652..60d33d0088 100644 --- a/direct/src/showbase/PythonUtil.py +++ b/direct/src/showbase/PythonUtil.py @@ -25,7 +25,7 @@ __all__ = ['enumerate', 'unique', 'indent', 'nonRepeatingRandomList', 'printNumberedTyped', 'DelayedCall', 'DelayedFunctor', 'FrameDelayedCallback', 'ArgumentEater', 'ClassTree', 'getBase', 'superFlattenShip','HotkeyBreaker','logMethodCalls','GoldenRatio', -'GoldenRectangle'] +'GoldenRectangle', 'pivotScalar', 'rad90', 'rad180', 'rad270', 'rad360'] import types import string @@ -667,6 +667,11 @@ def replace(list, old, new, all=0): list[i] = new return numReplaced +rad90 = math.pi / 2. +rad180 = math.pi +rad270 = 1.5 * math.pi +rad360 = 2. * math.pi + def reduceAngle(deg): """ Reduces an angle (in degrees) to a value in [-180..180) @@ -1742,6 +1747,16 @@ def clampScalar(value, a, b): else: return value +def pivotScalar(scalar, pivot): + # reflect scalar about pivot; see tests below + return pivot + (pivot - scalar) + +if __debug__: + assert pivotScalar(1, 0) == -1 + assert pivotScalar(-1, 0) == 1 + assert pivotScalar(3, 5) == 7 + assert pivotScalar(10, 1) == -8 + def weightedChoice(choiceList, rng=random.random, sum=None): """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 @@ -2665,3 +2680,7 @@ __builtin__.notNone = notNone __builtin__.clampScalar = clampScalar __builtin__.makeList = makeList __builtin__.makeTuple = makeTuple +__builtin__.rad90 = rad90 +__builtin__.rad180 = rad180 +__builtin__.rad270 = rad270 +__builtin__.rad360 = rad360