added pivotScalar, rad90/180/270/360

This commit is contained in:
Darren Ranalli 2007-01-29 23:17:08 +00:00
parent ee9ea70f77
commit 9449c113df

View File

@ -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