mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2025-07-03 00:18:20 +00:00
lslbasefuncs: Rewrite some things in a different way.
Also some formatting changes. No functionality changes.
This commit is contained in:
parent
ea28e13e4a
commit
028b244a9e
1 changed files with 98 additions and 112 deletions
|
@ -388,15 +388,11 @@ def f2s(val, DP=6):
|
||||||
return sgn + new_s + u'0' * (dot + 1 + DP - i)
|
return sgn + new_s + u'0' * (dot + 1 + DP - i)
|
||||||
|
|
||||||
def vr2s(v, DP=6):
|
def vr2s(v, DP=6):
|
||||||
if type(v) == Vector:
|
assert len(v) == (3 if type(v) == Vector else 4)
|
||||||
return u'<'+f2s(v[0],DP)+u', '+f2s(v[1],DP)+u', '+f2s(v[2],DP)+u'>'
|
return u'<' + ', '.join(f2s(x, DP) for x in v) + u'>'
|
||||||
return u'<'+f2s(v[0],DP)+u', '+f2s(v[1],DP)+u', '+f2s(v[2],DP)+u', '+f2s(v[3],DP)+u'>'
|
|
||||||
|
|
||||||
|
|
||||||
def qnz(q):
|
def qnz(q):
|
||||||
if all(x == 0. for x in q):
|
return Quaternion((0.,0.,0.,1.)) if all(x == 0. for x in q) else q
|
||||||
return Quaternion((0.,0.,0.,1.))
|
|
||||||
return q
|
|
||||||
|
|
||||||
def qnorm(q):
|
def qnorm(q):
|
||||||
q = qnz(q)
|
q = qnz(q)
|
||||||
|
@ -590,12 +586,8 @@ def InternalGetDeleteSubSequence(val, start, end, isGet):
|
||||||
if end == -1: end += L
|
if end == -1: end += L
|
||||||
if (start+L if start < 0 else start) > (end+L if end < 0 else end):
|
if (start+L if start < 0 else start) > (end+L if end < 0 else end):
|
||||||
# Exclusion range - get/delete from end and start
|
# Exclusion range - get/delete from end and start
|
||||||
if isGet:
|
return val[:end+1] + val[start:] if isGet else val[end+1:start]
|
||||||
return val[:end+1] + val[start:]
|
return val[start:end+1] if isGet else val[:start] + val[end+1:]
|
||||||
return val[end+1:start]
|
|
||||||
if isGet:
|
|
||||||
return val[start:end+1]
|
|
||||||
return val[:start] + val[end+1:]
|
|
||||||
|
|
||||||
def typecast(val, out, InList=False, f32=True):
|
def typecast(val, out, InList=False, f32=True):
|
||||||
"""Type cast an item. Calls InternalList2Strings for lists and
|
"""Type cast an item. Calls InternalList2Strings for lists and
|
||||||
|
@ -680,8 +672,10 @@ def mul(a, b, f32=True):
|
||||||
if tb in (int, float):
|
if tb in (int, float):
|
||||||
if ta == tb == int:
|
if ta == tb == int:
|
||||||
return S32(a*b)
|
return S32(a*b)
|
||||||
if math.isnan(a) and math.isnan(b) and math.copysign(1, a) != math.copysign(1, b):
|
if math.isnan(a) and math.isnan(b):
|
||||||
return NaN
|
return (-NaN
|
||||||
|
if math.copysign(1, a) == math.copysign(1, b) == -1
|
||||||
|
else NaN)
|
||||||
return F32(ff(a)*ff(b), f32)
|
return F32(ff(a)*ff(b), f32)
|
||||||
if tb != Vector:
|
if tb != Vector:
|
||||||
# scalar * quat is not defined
|
# scalar * quat is not defined
|
||||||
|
@ -803,15 +797,13 @@ def compare(a, b, Eq = True):
|
||||||
ret = a == b
|
ret = a == b
|
||||||
else:
|
else:
|
||||||
ret = ff(a) == ff(b)
|
ret = ff(a) == ff(b)
|
||||||
return int(ret) if Eq else 1-ret
|
return int(ret == Eq)
|
||||||
if ta in (unicode, Key) and tb in (unicode, Key):
|
if ta in (unicode, Key) and tb in (unicode, Key):
|
||||||
ret = 0 if a == b else 1 if a > b or not lslcommon.LSO else -1
|
ret = 0 if a == b else 1 if not lslcommon.LSO or a > b else -1
|
||||||
return int(not ret) if Eq else ret
|
return int(not ret) if Eq else ret
|
||||||
if ta == tb in (Vector, Quaternion):
|
if ta == tb in (Vector, Quaternion):
|
||||||
for ae,be in zip(a,b):
|
ret = not any(ae != be for ae, be in zip(a, b))
|
||||||
if ae != be:
|
return int(ret == Eq)
|
||||||
return int(not Eq)
|
|
||||||
return int(Eq)
|
|
||||||
if ta == tb == list:
|
if ta == tb == list:
|
||||||
ret = len(a) - len(b)
|
ret = len(a) - len(b)
|
||||||
return int(not ret) if Eq else ret
|
return int(not ret) if Eq else ret
|
||||||
|
@ -887,12 +879,10 @@ def llAtan2(y, x):
|
||||||
y = ff(y)
|
y = ff(y)
|
||||||
x = ff(x)
|
x = ff(x)
|
||||||
if math.isnan(x) and math.isnan(y):
|
if math.isnan(x) and math.isnan(y):
|
||||||
if math.copysign(1, x) == -1 and math.copysign(1, y) == -1:
|
return mul(x, y)
|
||||||
return -NaN
|
if math.isnan(x):
|
||||||
return NaN
|
|
||||||
elif math.isnan(x):
|
|
||||||
return x
|
return x
|
||||||
elif math.isnan(y):
|
if math.isnan(y):
|
||||||
return y
|
return y
|
||||||
return F32(math.atan2(y, x))
|
return F32(math.atan2(y, x))
|
||||||
|
|
||||||
|
@ -934,7 +924,6 @@ def llAxes2Rot(fwd, left, up):
|
||||||
mag = math.sqrt(math.fsum((q[0]*q[0], q[1]*q[1], q[2]*q[2], q[3]*q[3])))
|
mag = math.sqrt(math.fsum((q[0]*q[0], q[1]*q[1], q[2]*q[2], q[3]*q[3])))
|
||||||
return Quaternion(F32((q[0]/mag, q[1]/mag, q[2]/mag, q[3]/mag)))
|
return Quaternion(F32((q[0]/mag, q[1]/mag, q[2]/mag, q[3]/mag)))
|
||||||
|
|
||||||
|
|
||||||
def llAxisAngle2Rot(axis, angle):
|
def llAxisAngle2Rot(axis, angle):
|
||||||
axis = v2f(axis)
|
axis = v2f(axis)
|
||||||
angle = ff(angle)
|
angle = ff(angle)
|
||||||
|
@ -1165,8 +1154,7 @@ def llGenerateKey():
|
||||||
s = hashlib.md5((u'%.17g %f %f' % (time.time(), random.random(),
|
s = hashlib.md5((u'%.17g %f %f' % (time.time(), random.random(),
|
||||||
random.random())).encode('utf8')
|
random.random())).encode('utf8')
|
||||||
).hexdigest()
|
).hexdigest()
|
||||||
return Key(s[:8] + '-' + s[8:12] + '-' + s[12:16] + '-' + s[16:20]
|
return Key('-'.join((s[:8], s[8:12], s[12:16], s[16:20], s[20:32])))
|
||||||
+ '-' + s[20:32])
|
|
||||||
|
|
||||||
# Can't give a concrete value
|
# Can't give a concrete value
|
||||||
raise ELSLCantCompute
|
raise ELSLCantCompute
|
||||||
|
@ -1200,7 +1188,8 @@ def llInsertString(s, pos, src):
|
||||||
|
|
||||||
def llIntegerToBase64(x):
|
def llIntegerToBase64(x):
|
||||||
x = fi(x)
|
x = fi(x)
|
||||||
return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255) + chr(x&255)).decode('utf8')
|
return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255)
|
||||||
|
+ chr(x&255)).decode('utf8')
|
||||||
|
|
||||||
def llList2CSV(lst):
|
def llList2CSV(lst):
|
||||||
lst = fl(lst)
|
lst = fl(lst)
|
||||||
|
@ -1551,12 +1540,9 @@ def llModPow(base, exp, mod):
|
||||||
if exp == 0:
|
if exp == 0:
|
||||||
return 1
|
return 1
|
||||||
# Convert all numbers to unsigned
|
# Convert all numbers to unsigned
|
||||||
if base < 0:
|
base &= 0xFFFFFFFF
|
||||||
base += 4294967296
|
exp &= 0xFFFFFFFF
|
||||||
if exp < 0:
|
mod &= 0xFFFFFFFF
|
||||||
exp += 4294967296
|
|
||||||
if mod < 0:
|
|
||||||
mod += 4294967296
|
|
||||||
prod = base
|
prod = base
|
||||||
ret = 1
|
ret = 1
|
||||||
while True:
|
while True:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue