2016-06-27 19:59:39 +02:00
|
|
|
# (C) Copyright 2015-2016 Sei Lisa. All rights reserved.
|
2015-03-05 23:18:41 +01:00
|
|
|
#
|
|
|
|
|
# This file is part of LSL PyOptimizer.
|
|
|
|
|
#
|
|
|
|
|
# LSL PyOptimizer is free software: you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License as
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# LSL PyOptimizer is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
|
# along with LSL PyOptimizer. If not, see <http://www.gnu.org/licenses/>.
|
2014-07-26 02:43:44 +02:00
|
|
|
|
2015-03-05 23:18:41 +01:00
|
|
|
# This module is used by the optimizer for resolving constant values.
|
|
|
|
|
#
|
|
|
|
|
# The functions it implements are all functions that always return the same
|
|
|
|
|
# result when given the same input, and that have no side effects.
|
|
|
|
|
#
|
2016-12-22 01:05:21 +01:00
|
|
|
# For example, llAbs() is here, but llGetPos() is not, because it doesn't
|
|
|
|
|
# always return the same result.
|
2015-03-05 23:18:41 +01:00
|
|
|
#
|
|
|
|
|
# This implies that functions present in this module can be precomputed if
|
|
|
|
|
# their arguments are constants.
|
|
|
|
|
#
|
|
|
|
|
# In some instances, the result can't be computed; in these cases the function
|
|
|
|
|
# raises a LSLCantCompute exception that is caught by the optimizer to leave
|
|
|
|
|
# the expression unchanged. For example, llBase64ToInteger("AA") returns
|
|
|
|
|
# unpredictable garbage in the low bytes in LSL, so it is left unchanged.
|
|
|
|
|
#
|
|
|
|
|
# The JSON functions have been separated to their own module.
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
import re
|
|
|
|
|
from lslcommon import *
|
|
|
|
|
import lslcommon
|
|
|
|
|
from ctypes import c_float
|
|
|
|
|
import math
|
|
|
|
|
import hashlib
|
|
|
|
|
from base64 import b64encode, b64decode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Regular expressions used along the code. They are needed mainly because
|
|
|
|
|
# Python lacks a C-like strtod/strtol (it comes close, but it is very picky
|
|
|
|
|
# with what it accepts). We need to extract the number part of a string, or
|
|
|
|
|
# Python will complain.
|
|
|
|
|
# Also, Base64 needs the correct count of characters (len mod 4 can't be = 1).
|
|
|
|
|
# The RE helps both in isolating the Base64 section and in trimming out the
|
|
|
|
|
# offending characters; it just doesn't help with padding, with which Python is
|
2017-01-19 03:31:02 +01:00
|
|
|
# also picky. We deal with that in the code by padding with '='*(-length & 3).
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# Despite what http://www.gnu.org/software/libc/manual/html_node/Parsing-of-Floats.html#Parsing-of-Floats
|
|
|
|
|
# says, NaN(chars) does not work in LSL (which is relevant in vectors).
|
|
|
|
|
# Note infinity vs. inf is necessary for parsing vectors & rotations,
|
|
|
|
|
# e.g. (vector)"<1,inf,infix>" is not valid but (vector)"<1,inf,infinity>" is
|
|
|
|
|
# as is (vector)"<1,inf,info>". The 1st gives <0,0,0>, the others <1,inf,inf>.
|
|
|
|
|
# The lookahead (?!i) is essential for parsing them that way without extra code.
|
|
|
|
|
# Note that '|' in REs is order-sensitive.
|
|
|
|
|
float_re = re.compile(ur'^\s*[+-]?(?:0(x)(?:[0-9a-f]+(?:\.[0-9a-f]*)?|\.[0-9a-f]+)(?:p[+-]?[0-9]+)?'
|
2015-02-28 17:34:26 +01:00
|
|
|
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|inf|nan)',
|
|
|
|
|
re.I)
|
|
|
|
|
vfloat_re = re.compile(ur'^\s*[+-]?(?:0(x)(?:[0-9a-f]+(?:\.[0-9a-f]*)?|\.[0-9a-f]+)(?:p[+-]?[0-9]+)?'
|
2014-07-26 02:43:44 +02:00
|
|
|
ur'|(?:[0-9]+(?:\.[0-9]*)?|\.[0-9]+)(?:e[+-]?[0-9]+)?|infinity|inf(?!i)|nan)',
|
|
|
|
|
re.I)
|
|
|
|
|
|
|
|
|
|
int_re = re.compile(ur'^0(x)[0-9a-f]+|^\s*[+-]?[0-9]+', re.I)
|
|
|
|
|
|
|
|
|
|
key_re = re.compile(ur'^[0-9a-f]{8}(?:-[0-9a-f]{4}){4}[0-9a-f]{8}$', re.I)
|
|
|
|
|
|
|
|
|
|
b64_re = re.compile(ur'^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2,3})?')
|
|
|
|
|
|
|
|
|
|
ZERO_VECTOR = Vector((0.0, 0.0, 0.0))
|
|
|
|
|
ZERO_ROTATION = Quaternion((0.0, 0.0, 0.0, 1.0))
|
2014-07-26 23:50:49 +02:00
|
|
|
NULL_KEY = u'00000000-0000-0000-0000-000000000000'
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
Infinity = float('inf')
|
2015-09-07 02:56:44 +02:00
|
|
|
Indet = Infinity * 0
|
2016-12-22 06:05:47 +01:00
|
|
|
NaN = -Indet # Don't use float("nan") - Windows gets upset.
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
class ELSLTypeMismatch(Exception):
|
|
|
|
|
def __init__(self):
|
2016-12-20 19:22:48 +01:00
|
|
|
super(ELSLTypeMismatch, self).__init__(u"Type mismatch")
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
class ELSLMathError(Exception):
|
|
|
|
|
def __init__(self):
|
2016-12-20 19:22:48 +01:00
|
|
|
super(ELSLMathError, self).__init__(u"Math Error")
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
class ELSLInvalidType(Exception):
|
|
|
|
|
def __init__(self):
|
2016-12-20 19:22:48 +01:00
|
|
|
super(ELSLInvalidType, self).__init__(u"Internal error: Invalid type")
|
2015-02-11 05:43:13 +01:00
|
|
|
|
|
|
|
|
class ELSLCantCompute(Exception):
|
|
|
|
|
pass
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# LSL types are translated to Python types as follows:
|
|
|
|
|
# * LSL string -> Python unicode
|
|
|
|
|
# * LSL key -> Key (class derived from unicode, no significant changes except __repr__)
|
|
|
|
|
# * LSL integer -> Python int (should never be long)
|
|
|
|
|
# * LSL float -> Python float
|
|
|
|
|
# * LSL vector -> Vector (class derived from Python tuple) of 3 numbers (float)
|
|
|
|
|
# * LSL rotation -> Quaternion (class derived from Python tuple) of 4 numbers (float)
|
|
|
|
|
# * LSL list -> Python list
|
|
|
|
|
|
|
|
|
|
Types = {
|
|
|
|
|
int: 1, # TYPE_INTEGER
|
|
|
|
|
float: 2, # TYPE_FLOAT
|
|
|
|
|
unicode: 3, # TYPE_STRING
|
|
|
|
|
Key: 4, # TYPE_KEY
|
|
|
|
|
Vector: 5, # TYPE_VECTOR
|
|
|
|
|
Quaternion: 6, # TYPE_ROTATION
|
2017-01-20 01:18:13 +01:00
|
|
|
list: 0, # TYPE_INVALID
|
2014-07-26 02:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Utility functions
|
|
|
|
|
|
|
|
|
|
def F32(f, f32=True):
|
|
|
|
|
"""Truncate a float to have a precision equivalent to IEEE single"""
|
|
|
|
|
|
|
|
|
|
if not f32: # don't truncate
|
|
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
if isinstance(f, tuple): # vector, quaternion
|
|
|
|
|
return f.__class__(F32(i) for i in f)
|
|
|
|
|
|
|
|
|
|
# Alternative to the big blurb below. This relies on the machine using IEEE-754, though.
|
|
|
|
|
|
|
|
|
|
# Using array:
|
|
|
|
|
#from array import array
|
|
|
|
|
#return array('f',(f,))[0]
|
|
|
|
|
|
2015-03-05 23:18:41 +01:00
|
|
|
# Using struct:
|
|
|
|
|
#from struct import pack, unpack
|
|
|
|
|
#return unpack('f', pack('f', f))[0]
|
|
|
|
|
|
2016-05-21 01:59:05 +02:00
|
|
|
# Using numpy:
|
|
|
|
|
#import numpy
|
|
|
|
|
#return float(numpy.float32(f))
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
# Using ctypes:
|
|
|
|
|
#from ctypes import c_float
|
|
|
|
|
return c_float(f).value
|
|
|
|
|
|
2015-03-05 23:18:41 +01:00
|
|
|
# These are other approaches that are not fully debugged:
|
|
|
|
|
|
2016-05-06 20:11:41 +02:00
|
|
|
# This one is tested against c_float, but not carefully verified:
|
|
|
|
|
# if math.isnan(f) or math.isinf(f) or f == 0.0:
|
|
|
|
|
# return f
|
|
|
|
|
#
|
|
|
|
|
# m, x = math.frexp(abs(f))
|
|
|
|
|
#
|
|
|
|
|
# if x > 128:
|
|
|
|
|
# return math.copysign(Infinity, f)
|
|
|
|
|
#
|
|
|
|
|
# if x < -125:
|
|
|
|
|
# m = math.ldexp(m, x + 149)
|
|
|
|
|
# x = -125
|
|
|
|
|
# else:
|
|
|
|
|
# m = m * 0x1000000
|
|
|
|
|
#
|
|
|
|
|
# frac = m % 1
|
|
|
|
|
# m -= frac
|
|
|
|
|
# assert m.is_integer()
|
|
|
|
|
# m = int(m)
|
|
|
|
|
#
|
|
|
|
|
# # Round to even
|
|
|
|
|
# if frac > 0.5 or frac == 0.5 and (m & 1):
|
|
|
|
|
# m += 1
|
|
|
|
|
# if m == 0x1000000:
|
|
|
|
|
# m = 0x800000
|
|
|
|
|
# x += 1
|
|
|
|
|
#
|
|
|
|
|
# # re-check for overflow
|
|
|
|
|
# if x > 128:
|
|
|
|
|
# return math.copysign(Infinity, f)
|
|
|
|
|
#
|
|
|
|
|
# if m == 0:
|
|
|
|
|
# return math.copysign(0.0, f)
|
|
|
|
|
#
|
|
|
|
|
# return math.ldexp(math.copysign(m/16777216.0, f), x)
|
|
|
|
|
|
|
|
|
|
# # Another alternative.
|
2014-07-26 02:43:44 +02:00
|
|
|
# m, x = math.frexp(abs(f))
|
|
|
|
|
# if x > 128:
|
|
|
|
|
# return math.copysign(Infinity, f)
|
|
|
|
|
# if x < -149:
|
|
|
|
|
# return math.copysign(0.0, f)
|
|
|
|
|
# if x < -125:
|
|
|
|
|
# e = 1<<(x+149)
|
|
|
|
|
# else:
|
|
|
|
|
# e = 16777216.0
|
|
|
|
|
# # Special corner case with rounding near the maximum float (e.g. 3.4028236e38 gets rounded up, going out of range for a F32)
|
|
|
|
|
# if m*e >= 16777215.5 and x == 128:
|
|
|
|
|
# return math.copysign(Infinity, f)
|
|
|
|
|
# return math.ldexp(math.copysign(math.floor(m*e+0.5)/e, f), x)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# # Original old-fashioned strategy (watch out for the 16777215.5 bug above):
|
|
|
|
|
#
|
|
|
|
|
# if math.isinf(f) or math.isnan(f) or f==0:
|
|
|
|
|
# return f
|
|
|
|
|
# s = math.copysign(1, f)
|
|
|
|
|
# # This number may not be precise enough if Python had infinite precision, but it works for us.
|
|
|
|
|
# if f < 0.0000000000000000000000000000000000000000000007006492321624086132496:
|
|
|
|
|
# return math.copysign(0.0, s)
|
|
|
|
|
# f = abs(f)
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# # TO DO: Check this boundary (this is 2^128)
|
|
|
|
|
# if f >= 340282366920938463463374607431768211456.0:
|
|
|
|
|
# return math.copysign(Infinity, s)
|
|
|
|
|
#
|
|
|
|
|
# # TO DO: Check this boundary (2^-126; hopefully there's some overlap and the precision can be cut)
|
|
|
|
|
# if f < 0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625:
|
|
|
|
|
# # Denormal range
|
|
|
|
|
# f *= 713623846352979940529142984724747568191373312.0
|
|
|
|
|
# e = 0.00000000000000000000000000000000000000000000140129846432481707092372958328991613128026194187651577175706828388979108268586060148663818836212158203125 # 2^-149
|
|
|
|
|
# else:
|
|
|
|
|
# e = 1.0
|
|
|
|
|
# # This first loop is an optimization to get closer to the destination faster for very small numbers
|
|
|
|
|
# while f < 1.0:
|
|
|
|
|
# f *= 16777216.0
|
|
|
|
|
# e *= 0.000000059604644775390625
|
|
|
|
|
# # Go bit by bit
|
|
|
|
|
# while f < 8388608.0:
|
|
|
|
|
# f *= 2.0
|
|
|
|
|
# e *= 0.5
|
|
|
|
|
#
|
|
|
|
|
# #This first loop is an optimization to get closer to the destination faster for very big numbers
|
|
|
|
|
# while f >= 140737488355328.0:
|
|
|
|
|
# f *= 0.000000059604644775390625
|
|
|
|
|
# e *= 16777216.0
|
|
|
|
|
# # Go bit by bit
|
|
|
|
|
# while f >= 16777216.0:
|
|
|
|
|
# f *= 0.5
|
|
|
|
|
# e *= 2.0
|
|
|
|
|
#
|
|
|
|
|
# return math.copysign(math.floor(f+0.5)*e, s)
|
|
|
|
|
|
|
|
|
|
def S32(val):
|
|
|
|
|
"""Return a signed integer truncated to 32 bits (must deal with longs too)"""
|
|
|
|
|
if -2147483648 <= val <= 2147483647:
|
|
|
|
|
return int(val)
|
|
|
|
|
val &= 0xFFFFFFFF
|
|
|
|
|
if val > 2147483647:
|
|
|
|
|
return int(val - 4294967296)
|
|
|
|
|
return int(val)
|
|
|
|
|
|
|
|
|
|
def zstr(s):
|
|
|
|
|
if not isinstance(s, unicode):
|
|
|
|
|
raise ELSLInvalidType
|
|
|
|
|
|
|
|
|
|
zi = s.find(u'\0')
|
|
|
|
|
if zi < 0:
|
|
|
|
|
return s
|
|
|
|
|
return s.__class__(s[:zi])
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def ff(x):
|
|
|
|
|
"""Force x to be a float"""
|
2016-05-21 03:10:31 +02:00
|
|
|
if type(x) != float:
|
2016-12-21 06:01:03 +01:00
|
|
|
x = float(x)
|
|
|
|
|
return F32(x)
|
|
|
|
|
|
|
|
|
|
def fk(k):
|
|
|
|
|
"""Force k to be a key"""
|
|
|
|
|
if type(k) != Key:
|
|
|
|
|
k = Key(k)
|
|
|
|
|
return k
|
|
|
|
|
|
|
|
|
|
def fs(s):
|
|
|
|
|
"""Force s to be a string"""
|
|
|
|
|
if type(s) != unicode:
|
|
|
|
|
s = unicode(s)
|
|
|
|
|
return s
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
|
|
|
|
|
def q2f(q):
|
|
|
|
|
if type(q[0]) == type(q[1]) == type(q[2]) == type(q[3]) == float:
|
|
|
|
|
return q
|
|
|
|
|
return Quaternion((ff(q[0]), ff(q[1]), ff(q[2]), ff(q[3])))
|
|
|
|
|
|
|
|
|
|
def v2f(v):
|
|
|
|
|
if type(v[0]) == type(v[1]) == type(v[2]) == float:
|
|
|
|
|
return v
|
|
|
|
|
return Vector((ff(v[0]), ff(v[1]), ff(v[2])))
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
def f2s(val, DP=6):
|
|
|
|
|
if math.isinf(val):
|
|
|
|
|
return u'Infinity' if val > 0 else u'-Infinity'
|
|
|
|
|
if math.isnan(val):
|
|
|
|
|
return u'NaN'
|
|
|
|
|
if lslcommon.LSO or val == 0.:
|
|
|
|
|
return u'%.*f' % (DP, val) # deals with -0.0 too
|
|
|
|
|
|
|
|
|
|
# Format according to Mono rules (7 decimals after the DP, found experimentally)
|
|
|
|
|
s = u'%.*f' % (DP+7, val)
|
|
|
|
|
|
|
|
|
|
if s[:DP+3] == u'-0.' + '0'*DP and s[DP+3] < u'5':
|
|
|
|
|
return u'0.' + '0'*DP # underflown negatives return 0.0 except for -0.0 dealt with above
|
|
|
|
|
|
|
|
|
|
# Separate the sign
|
|
|
|
|
sgn = u'-' if s[0] == u'-' else u''
|
|
|
|
|
if sgn: s = s[1:]
|
|
|
|
|
|
|
|
|
|
# Look for position of first nonzero from the left
|
|
|
|
|
i = 0
|
|
|
|
|
while s[i] in u'0.':
|
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
|
|
dot = s.index(u'.')
|
|
|
|
|
|
|
|
|
|
# Find rounding point. It's either the 7th digit after the first significant one,
|
|
|
|
|
# or the (DP+1)-th decimal after the period, whichever comes first.
|
|
|
|
|
digits = 0
|
|
|
|
|
while digits < 7:
|
|
|
|
|
if i >= dot+1+DP:
|
|
|
|
|
break
|
|
|
|
|
if i == dot:
|
|
|
|
|
i += 1
|
|
|
|
|
i += 1
|
|
|
|
|
digits += 1
|
|
|
|
|
|
2015-09-24 22:02:46 +02:00
|
|
|
if s[i if i != dot else i+1] >= u'5':
|
|
|
|
|
# Rounding - increment s[:i] storing result into new_s
|
2014-07-26 02:43:44 +02:00
|
|
|
new_s = u''
|
|
|
|
|
ci = i-1 # carry index
|
|
|
|
|
while ci >= 0 and s[ci] == u'9':
|
|
|
|
|
new_s = u'0' + new_s
|
|
|
|
|
ci -= 1
|
|
|
|
|
if ci == dot:
|
|
|
|
|
ci -= 1 # skip over the dot
|
|
|
|
|
new_s = u'.' + new_s # but add it to new_s
|
|
|
|
|
if ci < 0:
|
|
|
|
|
new_s = u'1' + new_s # 9...9 -> 10...0
|
|
|
|
|
else:
|
|
|
|
|
# increment s[ci] e.g. 43999 -> 44000
|
|
|
|
|
new_s = s[:ci] + chr(ord(s[ci])+1) + new_s
|
|
|
|
|
else:
|
|
|
|
|
new_s = s[:i]
|
|
|
|
|
|
|
|
|
|
if i <= dot:
|
|
|
|
|
return sgn + new_s + u'0'*(dot-i) + u'.' + u'0'*DP
|
|
|
|
|
return sgn + new_s + u'0'*(dot+1+DP-i)
|
|
|
|
|
|
|
|
|
|
def vr2s(v, DP=6):
|
|
|
|
|
if type(v) == Vector:
|
|
|
|
|
return u'<'+f2s(v[0],DP)+u', '+f2s(v[1],DP)+u', '+f2s(v[2],DP)+u'>'
|
|
|
|
|
return u'<'+f2s(v[0],DP)+u', '+f2s(v[1],DP)+u', '+f2s(v[2],DP)+u', '+f2s(v[3],DP)+u'>'
|
|
|
|
|
|
|
|
|
|
def InternalTypecast(val, out, InList, f32):
|
|
|
|
|
"""Type cast val to out, following LSL rules.
|
|
|
|
|
|
|
|
|
|
To avoid mutual recursion, it deals with everything except lists. That way
|
|
|
|
|
it does not need to call InternalList2Strings which needs to call it.
|
|
|
|
|
"""
|
|
|
|
|
tval = type(val)
|
|
|
|
|
# The case tval == list is handled in typecast() below.
|
|
|
|
|
if out == list:
|
|
|
|
|
return [val]
|
|
|
|
|
|
|
|
|
|
if tval == int: # integer
|
|
|
|
|
val = S32(val)
|
|
|
|
|
if out == int: return val
|
|
|
|
|
if out == float: return F32(val, f32)
|
|
|
|
|
if out == unicode: return unicode(val)
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
if tval == float:
|
|
|
|
|
val = F32(val, f32)
|
|
|
|
|
if out == int: return S32(int(val)) if val >= -2147483648.0 and val < 2147483648.0 else -2147483648
|
|
|
|
|
if out == float: return val
|
|
|
|
|
if out == unicode: return f2s(val, 6)
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
if tval == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
val = v2f(val)
|
2014-07-26 02:43:44 +02:00
|
|
|
if out == Vector: return val
|
|
|
|
|
if out == unicode: return vr2s(val, 6 if InList else 5)
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
if tval == Quaternion:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
val = q2f(val)
|
2014-07-26 02:43:44 +02:00
|
|
|
if out == Quaternion: return val
|
|
|
|
|
if out == unicode: return vr2s(val, 6 if InList else 5)
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
if tval == Key: # key
|
|
|
|
|
if out == Key: return zstr(val)
|
|
|
|
|
if out == unicode: return zstr(unicode(val))
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
if tval == unicode:
|
|
|
|
|
val = zstr(val)
|
|
|
|
|
if out == unicode: return val
|
|
|
|
|
if out == Key: return Key(val)
|
|
|
|
|
if out == float:
|
|
|
|
|
# Clean up the string for Picky Python
|
2016-06-26 22:33:10 +02:00
|
|
|
match = float_re.search(val)
|
2014-07-26 02:43:44 +02:00
|
|
|
if match is None:
|
|
|
|
|
return 0.0
|
|
|
|
|
if match.group(1):
|
2015-09-21 21:15:48 +02:00
|
|
|
ret = F32(float.fromhex(match.group(0)), f32)
|
|
|
|
|
else:
|
2017-01-12 03:29:38 +01:00
|
|
|
if match.group(0).lower() == '-nan':
|
|
|
|
|
# (float)"-nan" produces NaN instead of Indet, even though
|
|
|
|
|
# (vector)"<-nan,0,0>" produces <Indet, 0., 0.>. Go figure.
|
|
|
|
|
ret = NaN
|
|
|
|
|
else:
|
|
|
|
|
ret = F32(float(match.group(0)), f32)
|
2015-09-21 21:15:48 +02:00
|
|
|
if not lslcommon.LSO and abs(ret) < 1.1754943508222875e-38:
|
|
|
|
|
# Mono doesn't return denormals when using (float)"val"
|
|
|
|
|
# (but it returns them when using (vector)"<val,...>")
|
2015-09-22 14:14:26 +02:00
|
|
|
ret = 0.0
|
2015-09-21 21:15:48 +02:00
|
|
|
return ret
|
2014-07-26 02:43:44 +02:00
|
|
|
if out == int:
|
2016-06-26 22:33:10 +02:00
|
|
|
match = int_re.search(val)
|
2014-07-26 02:43:44 +02:00
|
|
|
if match is None:
|
|
|
|
|
return 0
|
|
|
|
|
val = match.group(0)
|
|
|
|
|
if match.group(1):
|
|
|
|
|
val = int(val, 0)
|
|
|
|
|
else:
|
|
|
|
|
val = int(val)
|
|
|
|
|
if -4294967295 <= val <= 4294967295:
|
|
|
|
|
return S32(val)
|
|
|
|
|
return -1
|
|
|
|
|
if out in (Vector, Quaternion):
|
|
|
|
|
Z,dim = (ZERO_VECTOR,3) if out == Vector else (ZERO_ROTATION,4)
|
|
|
|
|
ret = []
|
|
|
|
|
if val[0:1] != u'<':
|
|
|
|
|
return Z
|
|
|
|
|
val = val[1:]
|
|
|
|
|
for _ in range(dim):
|
2016-06-26 22:33:10 +02:00
|
|
|
match = vfloat_re.search(val)
|
2014-07-26 02:43:44 +02:00
|
|
|
if match is None:
|
|
|
|
|
return Z
|
|
|
|
|
if match.group(1):
|
|
|
|
|
ret.append(F32(float.fromhex(match.group(0)), f32))
|
|
|
|
|
else:
|
|
|
|
|
ret.append(F32(float(match.group(0)), f32))
|
|
|
|
|
if len(ret) < dim:
|
|
|
|
|
i = match.end()
|
|
|
|
|
if val[i:i+1] != u',':
|
|
|
|
|
return Z
|
|
|
|
|
val = val[i+1:]
|
|
|
|
|
return out(ret) # convert type
|
|
|
|
|
|
|
|
|
|
# To avoid mutual recursion, this was moved:
|
|
|
|
|
#if tval == list: # etc.
|
|
|
|
|
|
|
|
|
|
raise ELSLInvalidType
|
|
|
|
|
|
|
|
|
|
def InternalList2Strings(val):
|
|
|
|
|
"""Convert a list of misc.items to a list of strings."""
|
|
|
|
|
ret = []
|
|
|
|
|
for elem in val:
|
|
|
|
|
ret.append(InternalTypecast(elem, unicode, InList=True, f32=True))
|
|
|
|
|
return ret
|
|
|
|
|
|
2014-07-26 21:06:53 +02:00
|
|
|
def InternalUTF8toString(s):
|
|
|
|
|
# Note Mono and LSO behave differently here.
|
|
|
|
|
# LSO *CAN* store invalid UTF-8.
|
|
|
|
|
# For example, llEscapeURL(llUnescapeURL("%80%C3")) gives "%80%C3" in LSO.
|
|
|
|
|
# (But llEscapeURL(llUnescapeURL("%80%00%C3")) still gives "%80")
|
|
|
|
|
# We don't emulate it, we've built this with Unicode strings in mind.
|
|
|
|
|
|
|
|
|
|
# decode(..., 'replace') replaces invalid chars with U+FFFD which is not
|
|
|
|
|
# what LSL does (LSL replaces with '?'). Since U+FFFD must be preserved if
|
|
|
|
|
# present, we need to write our own algorithm.
|
|
|
|
|
|
|
|
|
|
# Problem: Aliases are not valid UTF-8 for LSL, and code points above
|
|
|
|
|
# U+10FFFF are not supported. Both things complicate the alg a bit.
|
|
|
|
|
|
|
|
|
|
ret = u''
|
|
|
|
|
partialchar = b''
|
|
|
|
|
pending = 0
|
|
|
|
|
for c in s:
|
|
|
|
|
o = ord(c)
|
|
|
|
|
if partialchar:
|
|
|
|
|
if 0x80 <= o < 0xC0 and (
|
|
|
|
|
partialchar[1:2]
|
2016-12-13 03:10:01 +01:00
|
|
|
or b'\xC2' <= partialchar < b'\xF4' and partialchar not in b'\xE0\xED\xF0'
|
2014-07-26 21:06:53 +02:00
|
|
|
or partialchar == b'\xE0' and o >= 0xA0
|
2016-12-13 03:10:01 +01:00
|
|
|
or partialchar == b'\xED' and o < 0xA0
|
2014-07-26 21:06:53 +02:00
|
|
|
or partialchar == b'\xF0' and o >= 0x90
|
|
|
|
|
or partialchar == b'\xF4' and o < 0x90
|
|
|
|
|
):
|
|
|
|
|
partialchar += c
|
|
|
|
|
pending -= 1
|
|
|
|
|
if pending == 0:
|
|
|
|
|
ret += partialchar.decode('utf8')
|
|
|
|
|
partialchar = b''
|
|
|
|
|
c = c
|
|
|
|
|
# NOTE: Without the above line, the following one hits a bug in
|
|
|
|
|
# python-coverage. It IS executed but not detected.
|
|
|
|
|
continue
|
2016-12-21 00:22:49 +01:00
|
|
|
if lslcommon.LSO:
|
2016-12-20 19:22:48 +01:00
|
|
|
raise ELSONotSupported(u"Byte strings not supported")
|
2014-07-26 21:06:53 +02:00
|
|
|
ret += u'?' * len(partialchar)
|
|
|
|
|
partialchar = b''
|
|
|
|
|
# fall through to process current character
|
|
|
|
|
if o >= 0xC2 and o <= 0xF4:
|
|
|
|
|
partialchar = c
|
|
|
|
|
pending = 1 if o < 0xE0 else 2 if o < 0xF0 else 3
|
|
|
|
|
elif o >= 0x80:
|
2016-12-21 00:22:49 +01:00
|
|
|
if lslcommon.LSO:
|
2016-12-20 19:22:48 +01:00
|
|
|
raise ELSONotSupported(u"Byte strings not supported")
|
2014-07-26 21:06:53 +02:00
|
|
|
ret += u'?'
|
|
|
|
|
else:
|
|
|
|
|
ret += c.decode('utf8')
|
|
|
|
|
|
|
|
|
|
if partialchar:
|
2016-12-21 00:22:49 +01:00
|
|
|
if lslcommon.LSO:
|
2016-12-20 19:22:48 +01:00
|
|
|
raise ELSONotSupported(u"Byte strings not supported")
|
2014-07-26 21:06:53 +02:00
|
|
|
ret += u'?' * len(partialchar)
|
|
|
|
|
|
|
|
|
|
return zstr(ret)
|
|
|
|
|
|
|
|
|
|
# The code of llDeleteSubList and llDeleteSubString is identical except for the type check
|
|
|
|
|
def InternalDeleteSubSequence(val, start, end):
|
|
|
|
|
assert isinteger(start)
|
|
|
|
|
assert isinteger(end)
|
|
|
|
|
L = len(val)
|
|
|
|
|
if L == 0:
|
|
|
|
|
return val[:]
|
|
|
|
|
|
|
|
|
|
# Python does much of the same thing here, which helps a lot
|
|
|
|
|
if (start+L if start < 0 else start) <= (end+L if end < 0 else end):
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return val[:start] + val[end+1:]
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return val[end+1:start] # Exclusion range
|
|
|
|
|
|
|
|
|
|
# The code of llGetSubString and llList2List is identical except for the type check
|
|
|
|
|
def InternalGetSubSequence(val, start, end):
|
|
|
|
|
assert isinteger(start)
|
|
|
|
|
assert isinteger(end)
|
|
|
|
|
L = len(val)
|
|
|
|
|
if L == 0:
|
|
|
|
|
return val[:]
|
|
|
|
|
|
|
|
|
|
# Python does much of the same thing as LSL here, which helps a lot
|
|
|
|
|
if start < 0: start += L
|
|
|
|
|
if end < 0: end += L
|
|
|
|
|
if start > end:
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return val[:end+1] + val[start:] # Exclusion range
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return val[start:end+1]
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
def typecast(val, out, InList=False, f32=True):
|
|
|
|
|
"""Type cast an item. Calls InternalList2Strings for lists and
|
|
|
|
|
defers the rest to InternalTypecast.
|
|
|
|
|
"""
|
|
|
|
|
if type(val) == list:
|
|
|
|
|
if out == list:
|
|
|
|
|
return val # NOTE: We're not duplicating it here.
|
|
|
|
|
if out == unicode:
|
|
|
|
|
return u''.join(InternalList2Strings(val))
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
return InternalTypecast(val, out, InList, f32)
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def neg(val):
|
2014-07-26 02:43:44 +02:00
|
|
|
if type(val) in (int, float):
|
|
|
|
|
if type(val) == int and val == -2147483648:
|
|
|
|
|
return val
|
|
|
|
|
return -val
|
|
|
|
|
if isinstance(val, tuple):
|
|
|
|
|
return val.__class__(-f for f in val)
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
def add(a, b, f32=True):
|
|
|
|
|
# defined for:
|
|
|
|
|
# scalar+scalar
|
|
|
|
|
# vector+vector
|
|
|
|
|
# rotation+rotation
|
|
|
|
|
# string+string
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# (our extension:) key+string, string+key
|
2014-07-26 02:43:44 +02:00
|
|
|
# list+any
|
|
|
|
|
# any+list
|
|
|
|
|
ta=type(a)
|
|
|
|
|
tb=type(b)
|
|
|
|
|
if ta in (int, float) and tb in (int, float):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
if ta == tb == int:
|
2014-07-26 02:43:44 +02:00
|
|
|
return S32(a+b)
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(ff(a)+ff(b), f32)
|
|
|
|
|
|
|
|
|
|
if ta == tb in (list, unicode):
|
|
|
|
|
return a + b
|
|
|
|
|
# string + key, key + string are allowed here
|
2014-07-31 19:18:26 +02:00
|
|
|
if ta in (unicode, Key) and tb in (unicode, Key) and not (ta == tb == Key):
|
2014-07-26 02:43:44 +02:00
|
|
|
return a + b
|
|
|
|
|
if ta == list:
|
|
|
|
|
return a + [b]
|
|
|
|
|
if tb == list:
|
|
|
|
|
return [a] + b
|
|
|
|
|
if ta == tb in (Vector, Quaternion):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(ta(ff(a[i])+ff(b[i]) for i in range(len(a))), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
def sub(a, b, f32=True):
|
|
|
|
|
# defined for:
|
|
|
|
|
# scalar+scalar
|
|
|
|
|
# vector+vector
|
|
|
|
|
# rotation+rotation
|
|
|
|
|
ta=type(a)
|
|
|
|
|
tb=type(b)
|
|
|
|
|
if ta in (int, float) and tb in (int, float):
|
|
|
|
|
if ta == tb == int:
|
|
|
|
|
return S32(a-b)
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(ff(a)-ff(b), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
if ta == tb in (Vector, Quaternion):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(ta(ff(a[i])-ff(b[i]) for i in range(len(a))), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
def mul(a, b, f32=True):
|
|
|
|
|
# defined for:
|
|
|
|
|
# scalar*scalar
|
|
|
|
|
# scalar*vector
|
|
|
|
|
# vector*scalar
|
|
|
|
|
# vector*vector
|
|
|
|
|
# vector*rotation
|
|
|
|
|
# rotation*rotation
|
|
|
|
|
ta = type(a)
|
|
|
|
|
tb = type(b)
|
|
|
|
|
# If either type is string, list, or key, error
|
|
|
|
|
if ta in (unicode, list, Key) or tb in (unicode, list, Key):
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
# only int, float, vector, quaternion here
|
|
|
|
|
if ta in (int, float):
|
|
|
|
|
if tb in (int, float):
|
|
|
|
|
if ta == tb == int:
|
|
|
|
|
return S32(a*b)
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(ff(a)*ff(b), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
if tb != Vector:
|
|
|
|
|
# scalar * quat is not defined
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
# scalar * vector
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = ff(a)
|
|
|
|
|
b = v2f(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
return Vector(F32((a*b[0], a*b[1], a*b[2]), f32))
|
|
|
|
|
|
|
|
|
|
if ta == Quaternion:
|
|
|
|
|
# quat * scalar and quat * vector are not defined
|
|
|
|
|
if tb != Quaternion:
|
|
|
|
|
raise ELSLTypeMismatch
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = q2f(a)
|
|
|
|
|
b = q2f(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
# quaternion product - product formula reversed
|
|
|
|
|
return Quaternion(F32((a[0] * b[3] + a[3] * b[0] + a[2] * b[1] - a[1] * b[2],
|
|
|
|
|
a[1] * b[3] - a[2] * b[0] + a[3] * b[1] + a[0] * b[2],
|
|
|
|
|
a[2] * b[3] + a[1] * b[0] - a[0] * b[1] + a[3] * b[2],
|
|
|
|
|
a[3] * b[3] - a[0] * b[0] - a[1] * b[1] - a[2] * b[2]), f32))
|
|
|
|
|
|
|
|
|
|
if ta != Vector:
|
|
|
|
|
raise ELSLInvalidType # Should never happen at this point
|
|
|
|
|
|
|
|
|
|
if tb in (int, float):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
|
|
|
|
b = ff(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
return Vector(F32((a[0]*b, a[1]*b, a[2]*b), f32))
|
|
|
|
|
|
|
|
|
|
if tb == Vector:
|
|
|
|
|
# scalar product
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
|
|
|
|
b = v2f(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
return F32(math.fsum((a[0]*b[0], a[1]*b[1], a[2]*b[2])), f32)
|
|
|
|
|
|
|
|
|
|
if tb != Quaternion:
|
|
|
|
|
raise ELSLInvalidType # Should never happen at this point
|
|
|
|
|
|
|
|
|
|
# vector * quaternion: perform conjugation
|
|
|
|
|
#v = mul(Quaternion((-b[0], -b[1], -b[2], b[3])), mul(Quaternion((a[0], a[1], a[2], 0.0)), b, f32=False))
|
|
|
|
|
#return Vector((v[0], v[1], v[2]))
|
|
|
|
|
# this is more precise as it goes directly to the gist of it:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
|
|
|
|
b = q2f(b)
|
|
|
|
|
return Vector(F32((
|
|
|
|
|
math.fsum(( a[0]*(b[0]*b[0]-b[1]*b[1]-b[2]*b[2]+b[3]*b[3]),
|
|
|
|
|
a[1]*2*(b[0]*b[1]-b[2]*b[3]),
|
|
|
|
|
a[2]*2*(b[0]*b[2]+b[1]*b[3]))),
|
|
|
|
|
math.fsum(( a[0]*2*(b[0]*b[1]+b[2]*b[3]),
|
|
|
|
|
-a[1]*(b[0]*b[0]-b[1]*b[1]+b[2]*b[2]-b[3]*b[3]), # notice minus sign
|
|
|
|
|
a[2]*2*(b[1]*b[2]-b[0]*b[3]))),
|
|
|
|
|
math.fsum(( a[0]*2*(b[0]*b[2]-b[1]*b[3]),
|
|
|
|
|
a[1]*2*(b[1]*b[2]+b[0]*b[3]),
|
|
|
|
|
-a[2]*(b[0]*b[0]+b[1]*b[1]-b[2]*b[2]-b[3]*b[3]))) # notice minus sign
|
|
|
|
|
), f32))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def div(a, b, f32=True):
|
|
|
|
|
# defined for:
|
|
|
|
|
# scalar/scalar
|
|
|
|
|
# vector/scalar
|
|
|
|
|
# vector/rotation
|
|
|
|
|
# rotation/rotation
|
|
|
|
|
ta = type(a)
|
|
|
|
|
tb = type(b)
|
|
|
|
|
if tb in (int, float):
|
|
|
|
|
if b == 0:
|
|
|
|
|
raise ELSLMathError
|
|
|
|
|
if ta in (int, float):
|
|
|
|
|
if ta == int and tb == int:
|
|
|
|
|
# special case
|
|
|
|
|
if a == -2147483648 and b == -1:
|
|
|
|
|
return a # this could be handled by using S32 but it's probably faster this way
|
|
|
|
|
if (a < 0) ^ (b < 0):
|
|
|
|
|
# signs differ - Python rounds towards -inf, we need rounding towards 0
|
2016-11-06 04:09:43 +01:00
|
|
|
return -(a//-b)
|
2014-07-26 02:43:44 +02:00
|
|
|
return a//b
|
2016-05-15 18:21:24 +02:00
|
|
|
ret = F32(ff(a)/ff(b), f32)
|
2016-05-15 18:44:45 +02:00
|
|
|
if math.isnan(ret): # A NaN result gives a math error.
|
2016-05-15 18:21:24 +02:00
|
|
|
raise ELSLMathError
|
|
|
|
|
return ret
|
2014-07-26 02:43:44 +02:00
|
|
|
if ta == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
|
|
|
|
b = ff(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
return Vector(F32((a[0]/b, a[1]/b, a[2]/b), f32))
|
|
|
|
|
if tb == Quaternion: # division by a rotation is multiplication by the conjugate of the rotation
|
|
|
|
|
# defer the remaining type checks to mul()
|
2015-02-11 05:43:13 +01:00
|
|
|
return mul(a, Quaternion((-b[0],-b[1],-b[2],b[3])), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
|
|
|
|
def mod(a, b, f32=True):
|
|
|
|
|
# defined only for integers and vectors
|
|
|
|
|
if type(a) == type(b) == int:
|
2015-02-11 05:43:13 +01:00
|
|
|
if b == 0:
|
|
|
|
|
raise ELSLMathError
|
2014-07-26 02:43:44 +02:00
|
|
|
if a < 0:
|
|
|
|
|
return int(-((-a) % abs(b)))
|
|
|
|
|
return int(a % abs(b))
|
|
|
|
|
if type(a) == type(b) == Vector:
|
|
|
|
|
# cross product
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
|
|
|
|
b = v2f(b)
|
2017-01-17 02:22:10 +01:00
|
|
|
return Vector(F32((a[1]*b[2]-a[2]*b[1],
|
|
|
|
|
a[2]*b[0]-a[0]*b[2],
|
|
|
|
|
a[0]*b[1]-a[1]*b[0]), f32))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
raise ELSLTypeMismatch
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def compare(a, b, Eq = True):
|
|
|
|
|
"""Calculate a == b when Eq is True, or a != b when not"""
|
2014-07-26 02:43:44 +02:00
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Defined for all types as long as there's one that can be cast to the other
|
|
|
|
|
ta = type(a)
|
|
|
|
|
tb = type(b)
|
|
|
|
|
if ta in (int, float) and tb in (int, float):
|
|
|
|
|
# we trust that NaN == NaN is False
|
2017-01-17 02:38:52 +01:00
|
|
|
if ta == tb == int:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
ret = a == b
|
2017-01-17 02:38:52 +01:00
|
|
|
else:
|
|
|
|
|
ret = ff(a) == ff(b)
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return int(ret) if Eq else 1-ret
|
2015-02-11 05:43:13 +01:00
|
|
|
if ta in (unicode, Key) and tb in (unicode, Key):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
ret = 0 if a == b else 1 if a > b or not lslcommon.LSO else -1
|
|
|
|
|
return int(not ret) if Eq else ret
|
|
|
|
|
if ta == tb in (Vector, Quaternion):
|
|
|
|
|
for ae,be in zip(a,b):
|
|
|
|
|
if ae != be:
|
|
|
|
|
return int(not Eq)
|
|
|
|
|
return int(Eq)
|
|
|
|
|
if ta == tb == list:
|
|
|
|
|
ret = len(a) - len(b)
|
|
|
|
|
return int(not ret) if Eq else ret
|
|
|
|
|
raise ELSLTypeMismatch
|
2014-07-26 02:43:44 +02:00
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def less(a, b):
|
|
|
|
|
"""Calculate a < b. The rest can be derived by swapping components and by
|
|
|
|
|
negating: a > b is less(b,a); a <= b is 1-less(b,a); a >= b is 1-less(a,b).
|
|
|
|
|
"""
|
|
|
|
|
if type(a) == type(b) == int:
|
|
|
|
|
return int(a < b)
|
|
|
|
|
if type(a) in (int, float) and type(b) in (int, float):
|
|
|
|
|
return int(ff(a) < ff(b))
|
|
|
|
|
raise ELSLTypeMismatch
|
2014-07-26 02:43:44 +02:00
|
|
|
|
2014-07-26 23:50:49 +02:00
|
|
|
def cond(x):
|
|
|
|
|
"""Test whether x evaluates to True in a condition (if, while, for, ...)"""
|
|
|
|
|
tx = type(x)
|
|
|
|
|
if tx == Key:
|
|
|
|
|
if x == NULL_KEY or len(x) != 36:
|
|
|
|
|
return False
|
2016-06-26 22:33:10 +02:00
|
|
|
return bool(key_re.search(x))
|
2014-07-26 23:50:49 +02:00
|
|
|
if tx == Vector:
|
|
|
|
|
return bool(compare(x, ZERO_VECTOR, Eq=False))
|
|
|
|
|
if tx == Quaternion:
|
|
|
|
|
return bool(compare(x, ZERO_ROTATION, Eq=False))
|
2017-01-04 01:05:34 +01:00
|
|
|
if lslcommon.LSO and tx == list:
|
|
|
|
|
# SVC-689: lists of 1 element count as false
|
|
|
|
|
return len(x) > 1
|
2014-07-26 23:50:49 +02:00
|
|
|
return bool(x) # works fine for int, float, string, list
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def isinteger(x):
|
|
|
|
|
return type(x) == int
|
2014-07-26 02:43:44 +02:00
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def isfloat(x):
|
2016-12-21 06:01:03 +01:00
|
|
|
return type(x) == float
|
2014-07-26 02:43:44 +02:00
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def isvector(x):
|
|
|
|
|
return type(x) == Vector and len(x) == 3 and type(x[0]) == type(x[1]) == type(x[2]) == float
|
2014-07-26 02:43:44 +02:00
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def isrotation(x):
|
|
|
|
|
return type(x) == Quaternion and len(x) == 4 and type(x[0]) == type(x[1]) == type(x[2]) == type(x[3]) == float
|
|
|
|
|
|
|
|
|
|
def isstring(x):
|
2015-02-11 18:17:01 +01:00
|
|
|
return type(x) == unicode
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
|
|
|
|
|
def iskey(x):
|
2015-02-11 18:17:01 +01:00
|
|
|
return type(x) == Key
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
|
|
|
|
|
def islist(x):
|
|
|
|
|
return type(x) == list
|
2014-07-26 02:43:44 +02:00
|
|
|
|
2016-05-21 03:56:27 +02:00
|
|
|
def reduce(t):
|
|
|
|
|
t = F32(t)
|
|
|
|
|
if not t.is_integer():
|
|
|
|
|
return t # Accurate-ish until big numbers come into play
|
|
|
|
|
return int(t * 18446744073709551616) % 115904311329233965478 / 18446744073709551616.
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
#
|
|
|
|
|
# LSL-compatible computation functions
|
|
|
|
|
#
|
|
|
|
|
|
|
|
|
|
def llAbs(i):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isinteger(i)
|
2017-01-18 00:50:59 +01:00
|
|
|
return abs(i) if i != -2147483648 else i
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llAcos(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
2016-12-21 06:01:03 +01:00
|
|
|
return F32(math.acos(f))
|
2014-07-26 02:43:44 +02:00
|
|
|
except ValueError:
|
|
|
|
|
return NaN
|
|
|
|
|
|
|
|
|
|
def llAngleBetween(r1, r2):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r1)
|
|
|
|
|
assert isrotation(r2)
|
2014-07-26 02:43:44 +02:00
|
|
|
return llRot2Angle(div(r1, r2, f32=False))
|
|
|
|
|
|
|
|
|
|
def llAsin(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
2016-12-21 06:01:03 +01:00
|
|
|
return F32(math.asin(f))
|
2014-07-26 02:43:44 +02:00
|
|
|
except ValueError:
|
|
|
|
|
return NaN
|
|
|
|
|
|
|
|
|
|
def llAtan2(y, x):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(y)
|
|
|
|
|
assert isfloat(x)
|
2016-12-22 01:08:07 +01:00
|
|
|
if math.isnan(x) and math.isnan(y):
|
|
|
|
|
if math.copysign(1, x) == -1 and math.copysign(1, y) == -1:
|
|
|
|
|
return -NaN
|
|
|
|
|
return NaN
|
|
|
|
|
elif math.isnan(x):
|
|
|
|
|
return x
|
|
|
|
|
elif math.isnan(y):
|
|
|
|
|
return y
|
2016-12-21 06:01:03 +01:00
|
|
|
return F32(math.atan2(y, x))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llAxes2Rot(fwd, left, up):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(fwd)
|
|
|
|
|
assert isvector(left)
|
|
|
|
|
assert isvector(up)
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
# One of the hardest.
|
|
|
|
|
|
|
|
|
|
t = math.fsum((fwd[0], left[1], up[2]))
|
|
|
|
|
if t >= 0.: # no danger of division by zero or negative roots
|
|
|
|
|
r = math.sqrt(1. + t)
|
|
|
|
|
s = 0.5/r
|
|
|
|
|
|
|
|
|
|
# For the case of ix+jy+kz > 0, it can return an unnormalized quaternion
|
|
|
|
|
return Quaternion((s*(left[2]-up[1]), s*(up[0]-fwd[2]), s*(fwd[1]-left[0]), r*0.5))
|
|
|
|
|
|
|
|
|
|
# Find a positive combo. LSL normalizes the result in these cases only, so we do the same.
|
|
|
|
|
|
|
|
|
|
if left[1] <= fwd[0] >= up[2]: # is fwd[0] the greatest?
|
|
|
|
|
r = math.sqrt(1. + fwd[0] - left[1] - up[2])
|
|
|
|
|
s = 0.5/r
|
|
|
|
|
q = (r*0.5, s*(fwd[1]+left[0]), s*(up[0]+fwd[2]), s*(left[2]-up[1]))
|
|
|
|
|
|
|
|
|
|
elif fwd[0] <= left[1] >= up[2]: # is left[1] the greatest?
|
|
|
|
|
r = math.sqrt(1. - fwd[0] + left[1] - up[2])
|
|
|
|
|
s = 0.5/r
|
|
|
|
|
q = (s*(fwd[1]+left[0]), r*0.5, s*(left[2]+up[1]), s*(up[0]-fwd[2]))
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
# Only one case remaining: up[2] is the greatest
|
|
|
|
|
r = math.sqrt(1. - fwd[0] - left[1] + up[2])
|
|
|
|
|
s = 0.5/r
|
|
|
|
|
q = (s*(up[0]+fwd[2]), s*(left[2]+up[1]), r*0.5, s*(fwd[1]-left[0]))
|
|
|
|
|
|
|
|
|
|
# Normalize
|
|
|
|
|
if q == (0.,0.,0.,0.):
|
|
|
|
|
return Quaternion((0.,0.,0.,1.))
|
|
|
|
|
mag = 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)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def llAxisAngle2Rot(axis, angle):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(axis)
|
|
|
|
|
assert isfloat(angle)
|
2015-02-11 18:17:01 +01:00
|
|
|
axis = llVecNorm(axis, f32=False)
|
2014-07-26 02:43:44 +02:00
|
|
|
if axis == ZERO_VECTOR:
|
|
|
|
|
angle = 0.
|
2016-12-21 06:01:03 +01:00
|
|
|
c = math.cos(angle*0.5)
|
|
|
|
|
s = math.sin(angle*0.5)
|
2014-07-26 02:43:44 +02:00
|
|
|
return Quaternion(F32((axis[0]*s, axis[1]*s, axis[2]*s, c)))
|
|
|
|
|
|
2015-02-11 05:43:13 +01:00
|
|
|
# NOTE: This one does not always return the same value in LSL. When it isn't
|
|
|
|
|
# deterministic, it raises ELSLCantCompute.
|
2014-07-26 02:43:44 +02:00
|
|
|
def llBase64ToInteger(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
if len(s) > 8:
|
|
|
|
|
return 0
|
2016-06-26 22:33:10 +02:00
|
|
|
s = b64_re.search(s).group()
|
2014-07-26 02:43:44 +02:00
|
|
|
i = len(s)
|
2015-02-11 05:43:13 +01:00
|
|
|
s = b64decode(s + u'='*(-i & 3))
|
|
|
|
|
if len(s) < 3:
|
|
|
|
|
# not computable deterministically
|
|
|
|
|
raise ELSLCantCompute
|
|
|
|
|
s = (s + b'\0')[:4]
|
2014-07-26 02:43:44 +02:00
|
|
|
i = ord(s[0]) if s[0] < b'\x80' else ord(s[0])-256
|
|
|
|
|
return (i<<24)+(ord(s[1])<<16)+(ord(s[2])<<8)+ord(s[3])
|
|
|
|
|
|
2016-12-13 15:04:02 +01:00
|
|
|
b64tos_re = re.compile(
|
|
|
|
|
b'('
|
|
|
|
|
# Those pass through and are caught by InternalUTF8toString:
|
|
|
|
|
b'\x00$' # NUL at last position (zstr removes it)
|
2017-01-19 07:00:06 +01:00
|
|
|
b'|[\x09\x0A\x0F\x1F-\x7F\xFE\xFF]|[\xC2-\xDF][\x80-\xBF]'
|
2016-12-13 15:04:02 +01:00
|
|
|
b'|(?:\xE0[\xA0-\xBF]|[\xE1-\xEF][\x80-\xBF])[\x80-\xBF]'
|
|
|
|
|
b'|(?:\xF0[\x90-\xBF]|[\xF1-\xF7][\x80-\xBF])[\x80-\xBF]{2}'
|
|
|
|
|
b'|(?:\xF8[\x88-\xBF]|[\xF9-\xFB][\x80-\xBF])[\x80-\xBF]{3}'
|
|
|
|
|
b'|(?:\xFC[\x84-\xBF]|\xFD[\x80-\xBF])[\x80-\xBF]{4}'
|
|
|
|
|
b')|('
|
|
|
|
|
# Those are caught here and substituted by a single "?"
|
|
|
|
|
# (greediness is important here):
|
2017-01-19 07:00:06 +01:00
|
|
|
b'[\x00-\x1F\x80-\xBF]'
|
2016-12-13 15:04:02 +01:00
|
|
|
b'|[\xC0-\xDF][\x80-\xBF]?'
|
|
|
|
|
b'|[\xE0-\xEF][\x80-\xBF]{0,2}'
|
|
|
|
|
b'|[\xF0-\xF7][\x80-\xBF]{0,3}'
|
|
|
|
|
b'|[\xF8-\xFB][\x80-\xBF]{0,4}'
|
|
|
|
|
b'|[\xFC-\xFD][\x80-\xBF]{0,5}'
|
|
|
|
|
b')|(.)' # should never be reached
|
|
|
|
|
)
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
def llBase64ToString(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2016-06-26 22:33:10 +02:00
|
|
|
s = b64_re.search(s).group(0)
|
2016-12-13 15:04:02 +01:00
|
|
|
|
|
|
|
|
# llUnescapeURL and llBase64ToString behave differently.
|
|
|
|
|
# llBase64ToString does a first check on the UTF-8 before the standard
|
|
|
|
|
# conversion, unlike llUnescapeURL. That makes it have a much more similar
|
|
|
|
|
# behaviour to LSO's than llUnescapeURL does. But LL being LL, the check
|
|
|
|
|
# is, of course, flawed, and some illegal sequences pass as good (but in
|
|
|
|
|
# Mono they are fortunately stopped on the conversion to UTF-8 instead).
|
|
|
|
|
# The check that llBase64ToString does has the quirk that the invalid
|
|
|
|
|
# sequences that it catches are treated as 1 single bad character instead
|
|
|
|
|
# of as many as the sequence has. The latter is what normal conversion to
|
|
|
|
|
# UTF-8 does. This causes inconsistencies in the number of ?'s returned.
|
|
|
|
|
|
|
|
|
|
# In llBase64ToString, trailing NUL is stripped, and embedded NULs are
|
2017-01-19 07:00:06 +01:00
|
|
|
# converted to "?". In addition, characters in range 00-1F are also
|
|
|
|
|
# converted to "?" except for \x09, \x0A, \x0F, \x1F.
|
2016-12-13 15:04:02 +01:00
|
|
|
|
2017-01-19 03:31:02 +01:00
|
|
|
byteseq = bytearray(b64decode(s + u'=' * (-len(s) & 3)))
|
2016-12-13 15:04:02 +01:00
|
|
|
|
|
|
|
|
pos = 0
|
|
|
|
|
match = b64tos_re.search(byteseq, pos)
|
|
|
|
|
while match is not None:
|
|
|
|
|
assert match.group(3) is None, 'Fail in b64tos_re: ' + match.group(3)
|
|
|
|
|
L = len(match.group(2) or '')
|
|
|
|
|
if L:
|
|
|
|
|
byteseq[pos:pos+L] = b'?'
|
|
|
|
|
pos = match.end(2) - L + 1
|
|
|
|
|
else:
|
|
|
|
|
pos = match.end(1)
|
|
|
|
|
|
|
|
|
|
match = b64tos_re.search(byteseq, pos)
|
|
|
|
|
|
|
|
|
|
return InternalUTF8toString(bytes(byteseq))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llCSV2List(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
bracketlevel = 0
|
2016-03-25 20:52:48 +01:00
|
|
|
lastwascomma = True # first space is eaten!!!
|
2014-07-26 02:43:44 +02:00
|
|
|
lastidx = 0
|
|
|
|
|
i = 0
|
|
|
|
|
ret = []
|
|
|
|
|
for c in s:
|
|
|
|
|
if bracketlevel:
|
|
|
|
|
# ignore ',', focus on nesting level
|
|
|
|
|
if c == u'<':
|
|
|
|
|
bracketlevel += 1
|
|
|
|
|
elif c == u'>':
|
|
|
|
|
bracketlevel -= 1
|
|
|
|
|
elif lastwascomma and c == u' ': # eat space after comma
|
|
|
|
|
lastwascomma = False
|
|
|
|
|
lastidx = i+1
|
|
|
|
|
else:
|
2016-03-25 20:44:59 +01:00
|
|
|
lastwascomma = False
|
2014-07-26 02:43:44 +02:00
|
|
|
if c == u',':
|
|
|
|
|
lastwascomma = True
|
|
|
|
|
ret.append(s[lastidx:i])
|
|
|
|
|
lastidx = i+1
|
|
|
|
|
elif c == u'<':
|
|
|
|
|
bracketlevel += 1
|
|
|
|
|
i += 1
|
|
|
|
|
ret.append(s[lastidx:i])
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def llCeil(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isnan(f) or math.isinf(f) or f >= 2147483648.0 or f < -2147483648.0:
|
|
|
|
|
return -2147483648
|
|
|
|
|
return int(math.ceil(f))
|
|
|
|
|
|
|
|
|
|
def llCos(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isinf(f):
|
2015-09-07 02:56:44 +02:00
|
|
|
return Indet
|
2016-05-21 02:50:55 +02:00
|
|
|
if -9223372036854775808.0 < f < 9223372036854775808.0:
|
2016-05-21 04:16:34 +02:00
|
|
|
return F32(math.cos(reduce(f)))
|
2014-07-26 02:43:44 +02:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
def llDeleteSubList(lst, start, end):
|
|
|
|
|
# This acts as llList2List if there's wraparound
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
2014-07-26 02:43:44 +02:00
|
|
|
return InternalDeleteSubSequence(lst, start, end)
|
|
|
|
|
|
|
|
|
|
def llDeleteSubString(s, start, end):
|
|
|
|
|
# This acts as llGetSubString if there's wraparound
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
return InternalDeleteSubSequence(s, start, end)
|
|
|
|
|
|
|
|
|
|
def llDumpList2String(lst, sep):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isstring(sep)
|
2014-07-26 02:43:44 +02:00
|
|
|
return sep.join(InternalList2Strings(lst))
|
|
|
|
|
|
|
|
|
|
def llEscapeURL(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
s = s.encode('utf8') # get bytes
|
|
|
|
|
ret = u''
|
|
|
|
|
for c in s:
|
|
|
|
|
if b'A' <= c <= b'Z' or b'a' <= c <= b'z' or b'0' <= c <= b'9':
|
|
|
|
|
ret += c.encode('utf8')
|
|
|
|
|
else:
|
|
|
|
|
ret += u'%%%02X' % ord(c)
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def llEuler2Rot(v):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(v)
|
2014-07-26 02:43:44 +02:00
|
|
|
c0 = math.cos(v[0]*0.5)
|
|
|
|
|
s0 = math.sin(v[0]*0.5)
|
|
|
|
|
c1 = math.cos(v[1]*0.5)
|
|
|
|
|
s1 = math.sin(v[1]*0.5)
|
|
|
|
|
c2 = math.cos(v[2]*0.5)
|
|
|
|
|
s2 = math.sin(v[2]*0.5)
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return Quaternion(F32((s0 * c1 * c2 + c0 * s1 * s2,
|
|
|
|
|
c0 * s1 * c2 - s0 * c1 * s2,
|
|
|
|
|
c0 * c1 * s2 + s0 * s1 * c2,
|
|
|
|
|
c0 * c1 * c2 - s0 * s1 * s2)))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llFabs(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2016-12-21 06:01:03 +01:00
|
|
|
return math.fabs(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llFloor(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isnan(f) or math.isinf(f) or f >= 2147483648.0 or f < -2147483648.0:
|
|
|
|
|
return -2147483648
|
|
|
|
|
return int(math.floor(f))
|
|
|
|
|
|
2016-12-22 01:05:21 +01:00
|
|
|
def llFrand(lim):
|
|
|
|
|
assert isfloat(lim)
|
2017-01-16 20:37:11 +01:00
|
|
|
if math.isinf(lim):
|
2016-12-22 01:05:21 +01:00
|
|
|
return 0.
|
2017-01-16 20:37:11 +01:00
|
|
|
if abs(lim) < float.fromhex('0x1p-126'):
|
|
|
|
|
return -0. if lim < 0 else 0.
|
2016-12-22 01:05:21 +01:00
|
|
|
if math.isnan(lim):
|
|
|
|
|
return lim
|
|
|
|
|
|
|
|
|
|
if lslcommon.IsCalc:
|
|
|
|
|
import random
|
2016-12-21 01:18:25 +01:00
|
|
|
val = random.random() * lim
|
|
|
|
|
# Truncate, rather than rounding
|
|
|
|
|
m, e = math.frexp(val)
|
2016-12-22 01:05:21 +01:00
|
|
|
val = F32(math.ldexp(int(m * 16777216.) * .000000059604644775390625, e))
|
2016-12-21 01:18:25 +01:00
|
|
|
if val == lim:
|
2016-12-22 01:05:21 +01:00
|
|
|
# this should never happen
|
|
|
|
|
# (it can happen on denormals, but these cause output of 0.0)
|
2017-01-20 01:40:19 +01:00
|
|
|
val = 0. # pragma: no cover
|
2016-12-21 01:18:25 +01:00
|
|
|
return val
|
|
|
|
|
|
2016-12-22 01:05:21 +01:00
|
|
|
# Can't give a concrete value
|
|
|
|
|
raise ELSLCantCompute
|
|
|
|
|
|
|
|
|
|
def llGenerateKey():
|
|
|
|
|
if lslcommon.IsCalc:
|
|
|
|
|
import time
|
|
|
|
|
import random
|
|
|
|
|
|
2016-12-21 02:45:17 +01:00
|
|
|
s = hashlib.md5((u'%.17g %f %f' % (time.time(), random.random(),
|
|
|
|
|
random.random())).encode('utf8')
|
2016-12-21 06:01:03 +01:00
|
|
|
).hexdigest()
|
2016-12-21 01:32:54 +01:00
|
|
|
return Key(s[:8] + '-' + s[8:12] + '-' + s[12:16] + '-' + s[16:20]
|
|
|
|
|
+ '-' + s[20:32])
|
2016-12-21 01:18:25 +01:00
|
|
|
|
2016-12-22 01:05:21 +01:00
|
|
|
# Can't give a concrete value
|
|
|
|
|
raise ELSLCantCompute
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llGetListEntryType(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
2017-01-19 04:46:11 +01:00
|
|
|
return Types[type(lst[pos])]
|
2014-07-26 02:43:44 +02:00
|
|
|
except IndexError:
|
|
|
|
|
return 0 # TYPE_INVALID
|
|
|
|
|
except KeyError:
|
|
|
|
|
raise ELSLInvalidType
|
|
|
|
|
|
|
|
|
|
def llGetListLength(lst):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
2014-07-26 02:43:44 +02:00
|
|
|
return len(lst)
|
|
|
|
|
|
|
|
|
|
def llGetSubString(s, start, end):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
return InternalGetSubSequence(s, start, end)
|
|
|
|
|
|
|
|
|
|
def llInsertString(s, pos, src):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isinteger(pos)
|
|
|
|
|
assert isstring(src)
|
2014-07-26 02:43:44 +02:00
|
|
|
if pos < 0: pos = 0 # llInsertString does not support negative indices
|
|
|
|
|
return s[:pos] + src + s[pos:]
|
|
|
|
|
|
|
|
|
|
def llIntegerToBase64(x):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isinteger(x)
|
2014-07-26 02:43:44 +02:00
|
|
|
return b64encode(chr((x>>24)&255) + chr((x>>16)&255) + chr((x>>8)&255) + chr(x&255)).decode('utf8')
|
|
|
|
|
|
|
|
|
|
def llList2CSV(lst):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
2014-07-26 21:25:06 +02:00
|
|
|
ret = []
|
2014-07-31 19:18:26 +02:00
|
|
|
for elem in lst:
|
2014-07-26 21:25:06 +02:00
|
|
|
# This always uses LSO rules for float to string.
|
|
|
|
|
if type(elem) == float:
|
2016-05-15 19:55:45 +02:00
|
|
|
if math.isnan(elem) and math.copysign(1.0, elem) < 0:
|
2015-09-07 02:56:44 +02:00
|
|
|
ret.append(u'-nan')
|
|
|
|
|
else:
|
|
|
|
|
ret.append(u'%.6f' % elem)
|
2014-07-26 21:25:06 +02:00
|
|
|
elif type(elem) in (Vector, Quaternion):
|
2015-09-09 18:14:27 +02:00
|
|
|
ret.append(u'<' + llList2CSV(list(elem)) + u'>')
|
2014-07-26 21:25:06 +02:00
|
|
|
else:
|
|
|
|
|
ret.append(InternalTypecast(elem, unicode, InList=True, f32=True))
|
|
|
|
|
ret = u', '.join(ret)
|
2014-07-26 02:43:44 +02:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def llList2Float(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
elem = lst[pos]
|
|
|
|
|
if type(elem) == float:
|
|
|
|
|
return elem
|
|
|
|
|
if type(elem) in (int, unicode):
|
|
|
|
|
return InternalTypecast(elem, float, InList=True, f32=True)
|
|
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
|
|
def llList2Integer(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
elem = lst[pos]
|
|
|
|
|
if type(elem) == int:
|
|
|
|
|
return elem
|
|
|
|
|
if type(elem) in (float, unicode):
|
|
|
|
|
return InternalTypecast(elem, int, InList=True, f32=True)
|
|
|
|
|
return 0
|
|
|
|
|
except IndexError:
|
|
|
|
|
return 0
|
|
|
|
|
|
|
|
|
|
def llList2Key(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
elem = lst[pos]
|
|
|
|
|
if type(elem) == Key:
|
|
|
|
|
return elem
|
|
|
|
|
if type(elem) == unicode:
|
|
|
|
|
return Key(elem)
|
|
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
if lslcommon.LSO:
|
2014-07-26 23:50:49 +02:00
|
|
|
return Key(NULL_KEY)
|
2014-07-26 02:43:44 +02:00
|
|
|
return Key(u'')
|
|
|
|
|
|
|
|
|
|
def llList2List(lst, start, end):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(start)
|
|
|
|
|
assert isinteger(end)
|
2014-07-26 02:43:44 +02:00
|
|
|
return InternalGetSubSequence(lst, start, end)
|
|
|
|
|
|
|
|
|
|
def llList2ListStrided(lst, start, end, stride):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(start)
|
|
|
|
|
assert isinteger(end)
|
|
|
|
|
assert isinteger(stride)
|
2014-07-26 02:43:44 +02:00
|
|
|
stride = abs(stride) if stride != 0 else 1
|
|
|
|
|
L = len(lst)
|
|
|
|
|
if start < 0: start += L
|
|
|
|
|
if end < 0: end += L
|
|
|
|
|
if start > end:
|
|
|
|
|
start = 0
|
|
|
|
|
end = L-1
|
|
|
|
|
# start is rounded up to ceil(start/stride)*stride
|
|
|
|
|
start = ((start+stride-1)/stride)*stride
|
|
|
|
|
# end is rounded down to floor(start/stride)*stride
|
|
|
|
|
end = (end/stride)*stride
|
|
|
|
|
|
|
|
|
|
return lst[start:end+1:stride]
|
|
|
|
|
|
|
|
|
|
def llList2Rot(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
elem = lst[pos]
|
|
|
|
|
if type(elem) == Quaternion:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# The list should not contain integer quaternion components, but
|
|
|
|
|
# we don't control that here. Instead we return the integer-less
|
|
|
|
|
# quaternion when asked.
|
|
|
|
|
return q2f(elem)
|
2014-07-26 02:43:44 +02:00
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
return ZERO_ROTATION
|
|
|
|
|
|
|
|
|
|
def llList2String(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
return InternalTypecast(lst[pos], unicode, InList=True, f32=True)
|
|
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
return u''
|
|
|
|
|
|
|
|
|
|
def llList2Vector(lst, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
elem = lst[pos]
|
|
|
|
|
if type(elem) == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# The list should not contain integer vector components, but
|
|
|
|
|
# we don't control that here. Instead we return the integer-less
|
|
|
|
|
# vector when asked.
|
2015-02-11 05:43:13 +01:00
|
|
|
return v2f(elem)
|
2014-07-26 02:43:44 +02:00
|
|
|
except IndexError:
|
|
|
|
|
pass
|
|
|
|
|
return ZERO_VECTOR
|
|
|
|
|
|
|
|
|
|
def llListFindList(lst, elems):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert islist(elems)
|
2014-07-26 02:43:44 +02:00
|
|
|
# NaN is found in floats, but not in vectors
|
|
|
|
|
L1 = len(lst)
|
|
|
|
|
L2 = len(elems)
|
|
|
|
|
if L2 > L1:
|
|
|
|
|
return -1 # can't find a sublist longer than the original list
|
|
|
|
|
if L2 == 0:
|
2015-05-24 04:22:31 +02:00
|
|
|
# empty list is always found at position 0 in Mono,
|
|
|
|
|
# and in LSO if the first list isn't empty
|
|
|
|
|
return -1 if lslcommon.LSO and L1 == 0 else 0
|
2014-07-26 02:43:44 +02:00
|
|
|
for i in xrange(L1-L2+1):
|
|
|
|
|
for j in xrange(L2):
|
|
|
|
|
e1 = lst[i+j]
|
|
|
|
|
e2 = elems[j]
|
|
|
|
|
if type(e1) == type(e2) == float:
|
|
|
|
|
if e1 == e2:
|
|
|
|
|
continue
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Exceptionally, NaN equals NaN
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isnan(e1) and math.isnan(e2):
|
|
|
|
|
continue
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Mismatch
|
2014-07-26 02:43:44 +02:00
|
|
|
break
|
|
|
|
|
elif type(e1) == type(e2) in (Vector, Quaternion):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Act as if the list's vector/quat was all floats, even if not
|
|
|
|
|
if type(e1) == Vector:
|
|
|
|
|
e1 = v2f(e1)
|
|
|
|
|
e2 = v2f(e2)
|
|
|
|
|
else:
|
|
|
|
|
e1 = q2f(e1)
|
|
|
|
|
e2 = q2f(e2)
|
2014-07-26 02:43:44 +02:00
|
|
|
# Unfortunately, Python fails to consider (NaN,) != (NaN,) sometimes
|
|
|
|
|
# so we need to implement our own test
|
|
|
|
|
for e1e,e2e in zip(e1,e2):
|
|
|
|
|
if e1e != e2e: # NaNs are considered different to themselves here as normal
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Mismatch in vector/quaternion sub-element
|
2014-07-26 02:43:44 +02:00
|
|
|
break
|
|
|
|
|
else:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# No mismatch in any sub-element, try next list element
|
|
|
|
|
continue
|
2014-07-26 02:43:44 +02:00
|
|
|
break # discrepancy found
|
|
|
|
|
elif type(e1) != type(e2) or e1 != e2:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
break # mismatch
|
2014-07-26 02:43:44 +02:00
|
|
|
else:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# no mismatch
|
2014-07-26 02:43:44 +02:00
|
|
|
return i
|
|
|
|
|
return -1
|
|
|
|
|
|
|
|
|
|
def llListInsertList(lst, elems, pos):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert islist(elems)
|
|
|
|
|
assert isinteger(pos)
|
2014-07-26 02:43:44 +02:00
|
|
|
# Unlike llInsertString, this function does support negative indices.
|
|
|
|
|
return lst[:pos] + elems + lst[pos:]
|
|
|
|
|
|
|
|
|
|
# not implemented as it does not give the same output for the same input
|
|
|
|
|
#def llListRandomize(x):
|
|
|
|
|
|
|
|
|
|
def llListReplaceList(lst, elems, start, end):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert islist(elems)
|
|
|
|
|
assert isinteger(start)
|
|
|
|
|
assert isinteger(end)
|
2014-07-26 02:43:44 +02:00
|
|
|
L = len(lst)
|
2015-03-04 00:31:55 +01:00
|
|
|
if start < -L:
|
|
|
|
|
# llListReplaceList([0,1,2,3],[5],-5,-5) should return [0,1,2,3]
|
|
|
|
|
# llListReplaceList([0,1,2,3],[5],-5,-4) should return [1,2,3]
|
|
|
|
|
# llListReplaceList([0,1,2,3],[5],-5,-7) should return []
|
|
|
|
|
elems = []
|
2014-07-26 02:43:44 +02:00
|
|
|
if (start + L if start < 0 else start) > (end + L if end < 0 else end):
|
|
|
|
|
# Exclusion range. Appends elems at 'start' i.e. at end :)
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return lst[end+1:start] + elems
|
|
|
|
|
if end == -1: end += L
|
|
|
|
|
return lst[:start] + elems + lst[end+1:]
|
|
|
|
|
|
|
|
|
|
def llListSort(lst, stride, asc):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert islist(lst)
|
|
|
|
|
assert isinteger(stride)
|
|
|
|
|
assert isinteger(asc)
|
2014-07-26 02:43:44 +02:00
|
|
|
lst = lst[:] # make a copy
|
|
|
|
|
L = len(lst)
|
2016-12-22 05:31:03 +01:00
|
|
|
broken = u'\ufb1a' > u'\U0001d41a' # that happens on Windows
|
2014-07-26 02:43:44 +02:00
|
|
|
if stride < 1: stride = 1
|
|
|
|
|
if L % stride:
|
|
|
|
|
return lst
|
|
|
|
|
for i in xrange(0, L-stride, stride):
|
|
|
|
|
# Optimized by caching the element in the outer loop AND after swapping.
|
|
|
|
|
a = lst[i]
|
|
|
|
|
ta = type(a)
|
|
|
|
|
if ta == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a) # list should contain vectors made only of floats
|
2014-07-26 02:43:44 +02:00
|
|
|
a = a[0]*a[0] + a[1]*a[1] + a[2]*a[2]
|
2016-12-22 05:31:03 +01:00
|
|
|
if broken and ta in (unicode, Key):
|
|
|
|
|
# Note this breaks type consistency between a and ta!
|
|
|
|
|
# It should be OK because only equal types are compared.
|
2017-01-22 01:32:50 +01:00
|
|
|
a = a.encode('utf-32-be') # pragma: no cover
|
2014-07-26 02:43:44 +02:00
|
|
|
for j in xrange(i+stride, L, stride):
|
|
|
|
|
b = lst[j]
|
|
|
|
|
tb = type(b)
|
|
|
|
|
gt = False
|
|
|
|
|
if ta == tb:
|
|
|
|
|
if tb == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
b = v2f(b)
|
2014-07-26 02:43:44 +02:00
|
|
|
gt = not (a <= b[0]*b[0] + b[1]*b[1] + b[2]*b[2])
|
2017-01-17 02:53:26 +01:00
|
|
|
# (note NaNs compare as > thus the reversed condition!)
|
2014-07-26 02:43:44 +02:00
|
|
|
elif tb != Quaternion:
|
2016-12-22 05:31:03 +01:00
|
|
|
if broken and tb in (unicode, Key):
|
2017-01-22 01:32:50 +01:00
|
|
|
b = b.encode('utf-32-be') # pragma: no cover
|
2017-01-17 02:53:26 +01:00
|
|
|
gt = not (a <= b) # float, integer, string, key all take this branch
|
|
|
|
|
# (note NaNs compare as > thus the reversed condition!)
|
2014-07-26 02:43:44 +02:00
|
|
|
if gt ^ (asc != 1):
|
|
|
|
|
# swap
|
|
|
|
|
lst[i:i+stride],lst[j:j+stride] = lst[j:j+stride],lst[i:i+stride]
|
|
|
|
|
# Re-cache
|
|
|
|
|
a = lst[i]
|
|
|
|
|
ta = type(a)
|
|
|
|
|
if ta == Vector:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
a = v2f(a)
|
2014-07-26 02:43:44 +02:00
|
|
|
a = a[0]*a[0] + a[1]*a[1] + a[2]*a[2]
|
2016-12-22 05:31:03 +01:00
|
|
|
if broken and ta in (unicode, Key):
|
2017-01-22 01:32:50 +01:00
|
|
|
a = a.encode('utf-32-be') # pragma: no cover
|
2014-07-26 02:43:44 +02:00
|
|
|
return lst
|
|
|
|
|
|
|
|
|
|
def llListStatistics(op, lst):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isinteger(op)
|
|
|
|
|
assert islist(lst)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
nums = []
|
|
|
|
|
# Extract numbers in reverse order. LIST_STAT_MEDIAN uses that.
|
|
|
|
|
for elem in lst:
|
|
|
|
|
if type(elem) in (int, float):
|
|
|
|
|
nums.insert(0, float(elem))
|
|
|
|
|
|
|
|
|
|
if nums == []:
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
|
|
if op == 8: # LIST_STAT_NUM_COUNT
|
|
|
|
|
return float(len(nums))
|
|
|
|
|
|
|
|
|
|
if op in (0, 1, 2) : # LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX
|
|
|
|
|
min = None
|
|
|
|
|
for elem in nums:
|
|
|
|
|
if min is None:
|
|
|
|
|
min = max = elem
|
|
|
|
|
else:
|
|
|
|
|
if elem < min:
|
|
|
|
|
min = elem
|
|
|
|
|
if elem > max:
|
|
|
|
|
max = elem
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(max - min if op == 0 else min if op == 1 else max)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
if op == 4: # LIST_STAT_MEDIAN requires special treatment
|
|
|
|
|
# The function behaves very strangely with NaNs. This seems to reproduce it:
|
|
|
|
|
|
|
|
|
|
# llListSort seems to do the right thing with NaNs as needed by the median.
|
|
|
|
|
nums = llListSort(nums, 1, 1)
|
|
|
|
|
L = len(nums)
|
|
|
|
|
if L & 1:
|
|
|
|
|
return F32(nums[L>>1])
|
|
|
|
|
return F32((nums[(L>>1)-1] + nums[L>>1])*0.5)
|
|
|
|
|
|
|
|
|
|
if op in (3, 5, 6, 7): # LIST_STAT_MEAN, STD_DEV, SUM, SUM_SQUARES
|
|
|
|
|
sum = 0.
|
|
|
|
|
sumsq = 0.
|
|
|
|
|
mean = 0.
|
|
|
|
|
N = 0.
|
|
|
|
|
M2 = 0.
|
|
|
|
|
for elem in nums:
|
|
|
|
|
N += 1.
|
|
|
|
|
sum += elem
|
|
|
|
|
sumsq += elem*elem
|
|
|
|
|
delta = elem - mean
|
|
|
|
|
mean += delta/N
|
|
|
|
|
M2 += delta*(elem-mean)
|
|
|
|
|
|
|
|
|
|
if op == 5: # LIST_STAT_STD_DEV
|
|
|
|
|
return 0. if N == 1. else F32(math.sqrt(M2/(N-1.)))
|
|
|
|
|
if op == 6: # LIST_STAT_SUM
|
|
|
|
|
return F32(sum)
|
|
|
|
|
if op == 7: # LIST_STAT_SUM_SQUARES
|
|
|
|
|
return F32(sumsq)
|
|
|
|
|
return F32(mean)
|
|
|
|
|
|
|
|
|
|
if op == 9: # LIST_STAT_GEOMETRIC_MEAN
|
|
|
|
|
N = 0.
|
|
|
|
|
GMlog = 0.
|
|
|
|
|
for elem in nums:
|
|
|
|
|
if elem <= 0.:
|
|
|
|
|
return 0.
|
|
|
|
|
N += 1.
|
|
|
|
|
delta = math.log(elem) - GMlog
|
|
|
|
|
GMlog += delta/N
|
|
|
|
|
return F32(math.exp(GMlog))
|
|
|
|
|
|
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
|
|
def llLog(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isinf(f) and f < 0 or math.isnan(f) or f <= 0.0:
|
|
|
|
|
return 0.0
|
|
|
|
|
return F32(math.log(f))
|
|
|
|
|
|
|
|
|
|
def llLog10(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isinf(f) and f < 0 or math.isnan(f) or f <= 0.0:
|
|
|
|
|
return 0.0
|
|
|
|
|
return F32(math.log10(f))
|
|
|
|
|
|
|
|
|
|
def llMD5String(s, salt):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isinteger(salt)
|
2014-07-26 02:43:44 +02:00
|
|
|
return hashlib.md5(zstr(s).encode('utf8') + b':' + bytes(salt)).hexdigest().decode('utf8')
|
|
|
|
|
|
2017-01-07 20:46:14 +01:00
|
|
|
def llModPow(base, exp, mod):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isinteger(base)
|
|
|
|
|
assert isinteger(exp)
|
|
|
|
|
assert isinteger(mod)
|
2017-01-07 20:46:14 +01:00
|
|
|
if not lslcommon.IsCalc:
|
|
|
|
|
# This function has a delay, therefore it's not safe to compute it
|
|
|
|
|
# unless in calculator mode.
|
|
|
|
|
raise ELSLCantCompute
|
2014-07-26 02:43:44 +02:00
|
|
|
# With some luck, this works fully with native ints on 64 bit machines.
|
|
|
|
|
if mod in (0, 1):
|
|
|
|
|
return 0
|
|
|
|
|
if exp == 0:
|
|
|
|
|
return 1
|
|
|
|
|
# Convert all numbers to unsigned
|
|
|
|
|
if base < 0:
|
|
|
|
|
base += 4294967296
|
|
|
|
|
if exp < 0:
|
|
|
|
|
exp += 4294967296
|
|
|
|
|
if mod < 0:
|
|
|
|
|
mod += 4294967296
|
|
|
|
|
prod = base
|
|
|
|
|
ret = 1
|
|
|
|
|
while True:
|
|
|
|
|
if exp & 1:
|
|
|
|
|
ret = ((ret * prod) & 0xFFFFFFFF) % mod
|
|
|
|
|
exp = exp >> 1
|
|
|
|
|
if exp == 0:
|
|
|
|
|
break
|
|
|
|
|
prod = ((prod * prod) & 0xFFFFFFFF) % mod
|
|
|
|
|
|
|
|
|
|
return S32(ret)
|
|
|
|
|
|
|
|
|
|
def llParseString2List(s, exc, inc, KeepNulls=False):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert islist(exc)
|
|
|
|
|
assert islist(inc)
|
2014-07-26 02:43:44 +02:00
|
|
|
if s == u'' and KeepNulls:
|
|
|
|
|
return [s]
|
|
|
|
|
exc = exc[:8]
|
|
|
|
|
inc = inc[:8]
|
|
|
|
|
regex = u''
|
|
|
|
|
for i in exc:
|
|
|
|
|
if i != u'':
|
|
|
|
|
regex += u'|' + re.escape(i)
|
|
|
|
|
for i in inc:
|
|
|
|
|
if i != u'':
|
|
|
|
|
regex += u'|' + re.escape(i)
|
|
|
|
|
if regex == u'':
|
|
|
|
|
split = [s]
|
|
|
|
|
else:
|
|
|
|
|
regex = u'(' + regex[1:] + u')'
|
|
|
|
|
split = re.split(regex, s)
|
|
|
|
|
return [i for i in split if (KeepNulls or i != u'') and i not in exc]
|
|
|
|
|
|
|
|
|
|
def llParseStringKeepNulls(s, exc, inc):
|
|
|
|
|
return llParseString2List(s, exc, inc, KeepNulls=True)
|
|
|
|
|
|
|
|
|
|
def llPow(base, exp):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(base)
|
|
|
|
|
assert isfloat(exp)
|
2014-07-26 02:43:44 +02:00
|
|
|
try:
|
|
|
|
|
# Python corner cases and LSL corner cases differ
|
|
|
|
|
|
|
|
|
|
# Python matches these two, but we don't want to get trapped by our own checks.
|
|
|
|
|
if math.isnan(base) or math.isnan(exp):
|
|
|
|
|
return NaN
|
|
|
|
|
if exp == 0.0:
|
|
|
|
|
return 1.0
|
|
|
|
|
|
|
|
|
|
if base == 0.0: # Python gives exception on these, LSL returns stuff
|
|
|
|
|
if math.isinf(exp) and exp < 0:
|
|
|
|
|
return Infinity # llPow(0.0, -inf) = inf
|
|
|
|
|
|
|
|
|
|
if exp < 0.0:
|
|
|
|
|
# Negative finite exponent cases
|
|
|
|
|
if math.copysign(1, base) < 0 and exp.is_integer() and not (exp/2.).is_integer():
|
|
|
|
|
return -Infinity # llPow(-0.0, -odd_integer) = -inf
|
|
|
|
|
return Infinity
|
|
|
|
|
|
|
|
|
|
elif abs(base) == 1.0 and math.isinf(exp):
|
|
|
|
|
return NaN # Python says 1.0
|
|
|
|
|
|
|
|
|
|
f = F32(math.pow(base, exp))
|
|
|
|
|
return 0.0 if f == 0.0 else f # don't return -0.0
|
|
|
|
|
except ValueError: # should happen only with negative base and noninteger exponent
|
2015-09-07 02:56:44 +02:00
|
|
|
return Indet
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llRot2Angle(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
|
|
|
|
# Used by llAngleBetween.
|
2014-07-26 02:43:44 +02:00
|
|
|
# Version based on research by Moon Metty, Miranda Umino and Strife Onizuka
|
|
|
|
|
return F32(2.*math.atan2(math.sqrt(math.fsum((r[0]*r[0], r[1]*r[1], r[2]*r[2]))), abs(r[3])));
|
|
|
|
|
|
|
|
|
|
def llRot2Axis(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
2016-01-22 20:54:43 +01:00
|
|
|
if r[3] < 0:
|
|
|
|
|
return llVecNorm(Vector((-r[0], -r[1], -r[2])))
|
2015-02-11 05:43:13 +01:00
|
|
|
return llVecNorm(Vector((r[0], r[1], r[2])))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llRot2Euler(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# Another one of the hardest. The formula for Z angle in the
|
|
|
|
|
# singularity case was inspired by the viewer code.
|
|
|
|
|
y = 2*(r[0]*r[2] + r[1]*r[3])
|
|
|
|
|
|
|
|
|
|
# Check gimbal lock conditions
|
|
|
|
|
if abs(y) > 0.99999:
|
|
|
|
|
return (0., math.asin(y), math.atan2(2.*(r[2]*r[3]+r[0]*r[1]),
|
|
|
|
|
1.-2.*(r[0]*r[0]+r[2]*r[2])))
|
|
|
|
|
|
|
|
|
|
qy2 = r[1]*r[1]
|
2015-09-08 03:47:00 +02:00
|
|
|
return Vector((
|
2014-07-26 02:43:44 +02:00
|
|
|
math.atan2(2.*(r[0]*r[3]-r[1]*r[2]), 1.-2.*(r[0]*r[0]+qy2)),
|
|
|
|
|
math.asin(y),
|
|
|
|
|
math.atan2(2.*(r[2]*r[3]-r[0]*r[1]), 1.-2.*(r[2]*r[2]+qy2))
|
2015-09-08 03:47:00 +02:00
|
|
|
))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llRot2Fwd(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
2016-12-22 03:06:56 +01:00
|
|
|
v = Vector((1., 0., 0.))
|
2014-07-26 02:43:44 +02:00
|
|
|
if r == (0., 0., 0., 0.):
|
|
|
|
|
return v
|
|
|
|
|
return llVecNorm(mul(v, r, f32=False))
|
|
|
|
|
|
|
|
|
|
def llRot2Left(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
2016-12-22 03:06:56 +01:00
|
|
|
v = Vector((0., 1., 0.))
|
2014-07-26 02:43:44 +02:00
|
|
|
if r == (0., 0., 0., 0.):
|
|
|
|
|
return v
|
|
|
|
|
return llVecNorm(mul(v, r, f32=False))
|
|
|
|
|
|
|
|
|
|
def llRot2Up(r):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isrotation(r)
|
2016-12-22 03:06:56 +01:00
|
|
|
v = Vector((0., 0., 1.))
|
2014-07-26 02:43:44 +02:00
|
|
|
if r == (0., 0., 0., 0.):
|
|
|
|
|
return v
|
|
|
|
|
return llVecNorm(mul(v, r, f32=False))
|
|
|
|
|
|
|
|
|
|
def llRotBetween(v1, v2):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(v1)
|
|
|
|
|
assert isvector(v2)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
aabb = math.sqrt(mul(v1, v1, f32=False) * mul(v2, v2, f32=False)) # product of the squared lengths of the arguments
|
|
|
|
|
if aabb == 0.:
|
|
|
|
|
return ZERO_ROTATION # the arguments are too small, return zero rotation
|
|
|
|
|
ab = mul(v1, v2, f32=False) / aabb # normalized dotproduct of the arguments (cosine)
|
|
|
|
|
c = Vector(((v1[1] * v2[2] - v1[2] * v2[1]) / aabb, # normalized crossproduct of the arguments
|
|
|
|
|
(v1[2] * v2[0] - v1[0] * v2[2]) / aabb,
|
|
|
|
|
(v1[0] * v2[1] - v1[1] * v2[0]) / aabb))
|
|
|
|
|
cc = mul(c, c, f32=False) # squared length of the normalized crossproduct (sine)
|
|
|
|
|
if cc != 0.: # test if the arguments are (anti)parallel
|
|
|
|
|
if ab > -0.7071067811865476: # test if the angle is smaller than 3/4 PI
|
|
|
|
|
s = 1. + ab # use the cosine to adjust the s-element
|
|
|
|
|
else:
|
|
|
|
|
s = cc / (1. + math.sqrt(1. - cc)); # use the sine to adjust the s-element
|
|
|
|
|
m = math.sqrt(cc + s * s) # the magnitude of the quaternion
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return Quaternion(F32((c[0] / m, c[1] / m, c[2] / m, s / m))) # return the normalized quaternion
|
2014-07-26 02:43:44 +02:00
|
|
|
if ab > 0.: # test if the angle is smaller than PI/2
|
|
|
|
|
return ZERO_ROTATION # the arguments are parallel
|
|
|
|
|
m = math.sqrt(v1[0] * v1[0] + v1[1] * v1[1]) # the length of one argument projected on the XY-plane
|
|
|
|
|
if m != 0.:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return Quaternion(F32((v1[1] / m, -v1[0] / m, 0., 0.))) # return rotation with the axis in the XY-plane
|
2014-07-26 02:43:44 +02:00
|
|
|
return Quaternion((0., 0., 1., 0.)) # rotate around the Z-axis
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
# Algorithm by Moon Metty (for reference)
|
2014-07-26 02:43:44 +02:00
|
|
|
dot = mul(v1, v2, f32=False)
|
|
|
|
|
cross = mod(v1, v2, f32=False)
|
|
|
|
|
csq = mul(cross, cross, f32=False)
|
|
|
|
|
|
|
|
|
|
ddc2 = dot*dot + csq
|
|
|
|
|
|
2017-01-16 23:33:49 +01:00
|
|
|
DenormalStart = float.fromhex('0x1p-149')
|
|
|
|
|
if ddc2 >= DenormalStart:
|
|
|
|
|
if csq >= DenormalStart:
|
2014-07-26 02:43:44 +02:00
|
|
|
s = math.sqrt(ddc2) + dot;
|
|
|
|
|
m = math.sqrt(csq + s*s);
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return Quaternion(F32((cross[0]/m, cross[1]/m, cross[2]/m, s/m)))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# Deal with degenerate cases here
|
|
|
|
|
if dot > 0:
|
|
|
|
|
return ZERO_ROTATION
|
|
|
|
|
m = math.sqrt(v1[0]*v1[0] + v1[1]*v1[1])
|
2017-01-16 23:33:49 +01:00
|
|
|
if m >= DenormalStart:
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return Quaternion(F32((v1[1]/m, -v1[0]/m, 0., 0.)))
|
2014-07-26 02:43:44 +02:00
|
|
|
return Quaternion((1., 0., 0., 0.))
|
|
|
|
|
return ZERO_ROTATION
|
|
|
|
|
|
|
|
|
|
def llRound(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isnan(f) or math.isinf(f) or f >= 2147483647.5 or f < -2147483648.0:
|
|
|
|
|
return -2147483648
|
|
|
|
|
return int(math.floor(f+0.5))
|
|
|
|
|
|
|
|
|
|
def llSHA1String(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
return hashlib.sha1(s.encode('utf8')).hexdigest().decode('utf8')
|
|
|
|
|
|
|
|
|
|
def llSin(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isinf(f):
|
2015-09-07 02:56:44 +02:00
|
|
|
return Indet
|
2016-05-21 02:50:55 +02:00
|
|
|
if -9223372036854775808.0 < f < 9223372036854775808.0:
|
2016-05-21 04:16:34 +02:00
|
|
|
return F32(math.sin(reduce(f)))
|
2014-07-26 02:43:44 +02:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
def llSqrt(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if f < 0.0:
|
2015-09-07 02:56:44 +02:00
|
|
|
return Indet
|
2014-07-26 02:43:44 +02:00
|
|
|
# LSL and Python both produce -0.0 when the input is -0.0.
|
2015-06-16 04:41:36 +02:00
|
|
|
return F32(math.sqrt(f))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llStringLength(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
return len(s)
|
|
|
|
|
|
|
|
|
|
def llStringToBase64(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
return b64encode(s.encode('utf8')).decode('utf8')
|
|
|
|
|
|
|
|
|
|
def llStringTrim(s, mode):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isinteger(mode)
|
2014-07-26 02:43:44 +02:00
|
|
|
head = 0
|
|
|
|
|
length = len(s)
|
|
|
|
|
tail = length-1
|
|
|
|
|
if mode & 1: # STRING_TRIM_HEAD
|
|
|
|
|
while head < length and s[head] in u'\x09\x0a\x0b\x0c\x0d\x20':
|
|
|
|
|
head += 1
|
|
|
|
|
if mode & 2: # STRING_TRIM_TAIL
|
|
|
|
|
while tail >= head and s[tail] in u'\x09\x0a\x0b\x0c\x0d\x20':
|
|
|
|
|
tail -= 1
|
|
|
|
|
return s[head:tail+1]
|
|
|
|
|
|
|
|
|
|
def llSubStringIndex(s, pattern):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isstring(pattern)
|
2014-07-26 02:43:44 +02:00
|
|
|
return s.find(pattern)
|
|
|
|
|
|
|
|
|
|
def llTan(f):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isfloat(f)
|
2014-07-26 02:43:44 +02:00
|
|
|
if math.isinf(f):
|
2015-09-07 02:56:44 +02:00
|
|
|
return Indet
|
2016-05-21 02:50:55 +02:00
|
|
|
if -9223372036854775808.0 < f < 9223372036854775808.0:
|
2016-05-21 04:16:34 +02:00
|
|
|
return F32(math.tan(reduce(f)))
|
2014-07-26 02:43:44 +02:00
|
|
|
return f
|
|
|
|
|
|
|
|
|
|
def llToLower(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
if lslcommon.LSO:
|
|
|
|
|
return zstr(re.sub(u'[A-Z]', lambda x: x.group().lower(), s))
|
|
|
|
|
return zstr(s.lower())
|
|
|
|
|
|
|
|
|
|
def llToUpper(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
if lslcommon.LSO:
|
|
|
|
|
return zstr(re.sub(u'[a-z]', lambda x: x.group().upper(), s))
|
|
|
|
|
return zstr(s.upper())
|
|
|
|
|
|
|
|
|
|
def llUnescapeURL(s):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
2014-07-26 02:43:44 +02:00
|
|
|
ret = b''
|
|
|
|
|
L = len(s)
|
|
|
|
|
i = 0
|
|
|
|
|
while i < L:
|
|
|
|
|
c = s[i]
|
|
|
|
|
i += 1
|
|
|
|
|
if c != u'%':
|
|
|
|
|
ret += c.encode('utf8')
|
|
|
|
|
continue
|
|
|
|
|
if i >= L:
|
|
|
|
|
break
|
|
|
|
|
c = s[i] # First digit
|
|
|
|
|
i += 1
|
|
|
|
|
if i >= L:
|
|
|
|
|
break
|
|
|
|
|
v = 0
|
|
|
|
|
if u'0' <= c <= u'9' or u'A' <= c <= u'F' or u'a' <= c <= u'f':
|
|
|
|
|
v = int(c, 16)<<4
|
|
|
|
|
c = s[i] # Second digit
|
|
|
|
|
if c == u'%':
|
|
|
|
|
ret += chr(v)
|
2017-01-20 01:59:59 +01:00
|
|
|
i += 1
|
2014-07-26 02:43:44 +02:00
|
|
|
continue
|
|
|
|
|
i += 1
|
|
|
|
|
if u'0' <= c <= u'9' or u'A' <= c <= u'F' or u'a' <= c <= u'f':
|
|
|
|
|
v += int(c, 16)
|
|
|
|
|
ret += chr(v)
|
|
|
|
|
return InternalUTF8toString(ret)
|
|
|
|
|
|
|
|
|
|
def llVecDist(v1, v2):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(v1)
|
|
|
|
|
assert isvector(v2)
|
2015-02-11 05:43:13 +01:00
|
|
|
# For improved accuracy, do the intermediate calcs as doubles
|
|
|
|
|
vx = v1[0]-v2[0]
|
|
|
|
|
vy = v1[1]-v2[1]
|
|
|
|
|
vz = v1[2]-v2[2]
|
|
|
|
|
return F32(math.sqrt(math.fsum((vx*vx, vy*vy, vz*vz))))
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llVecMag(v):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isvector(v)
|
2014-07-26 02:43:44 +02:00
|
|
|
return F32(math.sqrt(math.fsum((v[0]*v[0], v[1]*v[1], v[2]*v[2]))))
|
|
|
|
|
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
def llVecNorm(v, f32 = True):
|
|
|
|
|
assert isvector(v)
|
2014-07-26 02:43:44 +02:00
|
|
|
if v == ZERO_VECTOR:
|
|
|
|
|
return v
|
|
|
|
|
f = math.sqrt(math.fsum((v[0]*v[0], v[1]*v[1], v[2]*v[2])))
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
return F32(Vector((v[0]/f,v[1]/f,v[2]/f)), f32)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
def llXorBase64(s, xor):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isstring(xor)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# Xor the underlying bytes.
|
|
|
|
|
|
|
|
|
|
if xor == u'':
|
|
|
|
|
return s
|
|
|
|
|
|
2016-06-26 22:33:10 +02:00
|
|
|
s = b64_re.search(s).group(0)
|
2014-07-26 02:43:44 +02:00
|
|
|
L1 = len(s)
|
2016-06-26 22:33:10 +02:00
|
|
|
xor = b64_re.search(xor).group(0)
|
2014-07-26 02:43:44 +02:00
|
|
|
L2 = len(xor)
|
|
|
|
|
|
|
|
|
|
if L2 == 0:
|
2015-02-11 05:43:13 +01:00
|
|
|
# The input xor string starts with zero or one valid Base64 characters.
|
|
|
|
|
# This produces garbage bytes (the first byte is zero though).
|
2017-01-19 02:58:42 +01:00
|
|
|
if L1 > 2:
|
|
|
|
|
# We don't produce a result in this case.
|
|
|
|
|
raise ELSLCantCompute
|
|
|
|
|
L2 = 2
|
|
|
|
|
xor = u'AA'
|
|
|
|
|
|
|
|
|
|
s = b64decode(s + u'=' * (-L1 & 3))
|
|
|
|
|
xor = b64decode(xor + u'=' * (-L2 & 3))
|
2014-07-26 02:43:44 +02:00
|
|
|
L2 = len(xor)
|
|
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
ret = b''
|
|
|
|
|
|
|
|
|
|
Bug3763 = 3763 in Bugs
|
|
|
|
|
# BUG-3763 consists of the binary string having an extra NULL every time after the second repetition of
|
2016-11-14 03:10:29 +01:00
|
|
|
# the XOR pattern. For example, if the XOR binary string is b'pqr' and the input string is
|
2014-07-26 02:43:44 +02:00
|
|
|
# b'12345678901234567890', the XOR binary string behaves as if it was b'pqrpqr\0pqr\0pqr\0pqr\0pq'.
|
|
|
|
|
# We emulate that by adding the zero and increasing the length the first time.
|
|
|
|
|
for c in s:
|
|
|
|
|
ret += chr(ord(c) ^ ord(xor[i]))
|
|
|
|
|
i += 1
|
|
|
|
|
if i >= L2:
|
|
|
|
|
i = 0
|
|
|
|
|
if Bug3763:
|
|
|
|
|
Bug3763 = False
|
|
|
|
|
xor = xor + b'\x00'
|
|
|
|
|
L2 += 1
|
|
|
|
|
return b64encode(ret).decode('utf8')
|
|
|
|
|
|
2017-01-07 20:46:14 +01:00
|
|
|
def llXorBase64Strings(s, xor):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isstring(xor)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
2017-01-07 20:46:14 +01:00
|
|
|
if not lslcommon.IsCalc:
|
|
|
|
|
# This function has a delay, therefore it's not safe to compute it
|
|
|
|
|
# unless in calculator mode.
|
|
|
|
|
raise ELSLCantCompute
|
|
|
|
|
|
2014-07-26 02:43:44 +02:00
|
|
|
if xor == u'':
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
B64 = u'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
|
|
|
|
|
|
|
|
|
|
# Special case when the first character is not a Base64 one. (LL's ways are inextricable)
|
|
|
|
|
base = B64.find(xor[0])
|
|
|
|
|
if base < 0:
|
|
|
|
|
if xor[0] == u'=':
|
|
|
|
|
xor = u'+' + xor[1:]
|
|
|
|
|
base = 62
|
|
|
|
|
else:
|
|
|
|
|
xor = u'/' + xor[1:]
|
|
|
|
|
base = 63
|
|
|
|
|
|
|
|
|
|
ret = u''
|
|
|
|
|
i = 0
|
|
|
|
|
L = len(xor)
|
|
|
|
|
for c1 in s:
|
|
|
|
|
val1 = B64.find(c1)
|
|
|
|
|
val2 = B64.find(xor[i])
|
|
|
|
|
i += 1
|
|
|
|
|
if i >= L:
|
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
|
|
if val1 < 0:
|
|
|
|
|
ret += u'='
|
|
|
|
|
else:
|
|
|
|
|
if val2 < 0:
|
|
|
|
|
val2 = base
|
|
|
|
|
i = 1
|
|
|
|
|
ret += B64[val1 ^ val2]
|
|
|
|
|
return ret
|
|
|
|
|
|
|
|
|
|
def llXorBase64StringsCorrect(s, xor):
|
Thorough review of lslbasefuncs and associated files, adding new stuff.
- Scratch TODO item: Change shouldbeXXX to asserts.
- shoudlbeXXX(x) has been turned into assert isXXX(x). Affects lsl2json too.
- New base functions:
- compare (for == and !=)
- less (for <, >, <=, >=)
- minus() renamed to neg() for consistency. Affects testfuncs too.
- add() now supports key+string and string+key.
- Allow integers in place of floats. That has caused the addition of three utility functions:
- ff (force float)
- v2f (force floats in all components of a vector)
- q2f (force floats in all components of a quaternion)
Used everywhere where necessary.
Special care was taken in a few funcs (llListFindList and maybe others) to ensure that lists containing vectors or quaternions which in turn contain integer components, behave as if they were floats, because LSL lists can not physically hold integer values as components of vectors/quats.
This also fixes a case where if a large integer had more precision than a F32 (e.g. 16777217), the product/division would be more precise than what LSL returns.
- Fix bugs of missing F32() in some places (llRotBetween, llEuler2Rot).
- Some functions marked for moving in an incoming commit.
- llList2CSV marked with a warning that it is not thread safe. That's a future TODO.
- Document llListFindList better.
- Make llListStatistics Use a more orthodox method to return the result for LIST_STAT_RANGE, LIST_STAT_MIN, LIST_STAT_MAX.
- Make llAxisAngle2Rot use more precision from llVecNorm, by adding an optional truncation parameter in the latter.
- Change order of some F32(Quaternion(...)) to not force so much instancing.
- Bugfix: llVecNorm did not return a Vector.
2014-07-26 20:54:01 +02:00
|
|
|
assert isstring(s)
|
|
|
|
|
assert isstring(xor)
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
# Xor the underlying bytes but repeating the xor parameter pattern at the first zero (SCR-35).
|
|
|
|
|
|
|
|
|
|
if xor == u'':
|
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
|
|
2016-06-26 22:33:10 +02:00
|
|
|
s = b64_re.search(s).group(0)
|
2014-07-26 02:43:44 +02:00
|
|
|
L1 = len(s)
|
2016-06-26 22:33:10 +02:00
|
|
|
xor = b64_re.search(xor).group(0)
|
2014-07-26 02:43:44 +02:00
|
|
|
L2 = len(xor)
|
|
|
|
|
|
|
|
|
|
if L2 == 0:
|
2015-02-11 05:43:13 +01:00
|
|
|
# The input xor string starts with zero or one valid Base64 characters.
|
|
|
|
|
# This produces garbage bytes (the first byte is zero though).
|
2017-01-19 02:58:42 +01:00
|
|
|
if L1 > 2:
|
|
|
|
|
# We don't produce a result in this case.
|
|
|
|
|
raise ELSLCantCompute
|
|
|
|
|
L2 = 2
|
|
|
|
|
xor = u'AA'
|
|
|
|
|
|
|
|
|
|
s = b64decode(s + u'=' * (-L1 & 3))
|
|
|
|
|
xor = b64decode(xor + u'=' * (-L2 & 3)) + b'\x00'
|
2014-07-26 02:43:44 +02:00
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
ret = b''
|
|
|
|
|
|
|
|
|
|
for c in s:
|
|
|
|
|
ret += chr(ord(c) ^ ord(xor[i]))
|
|
|
|
|
i += 1
|
|
|
|
|
if xor[i] == b'\x00':
|
|
|
|
|
i = 0
|
|
|
|
|
return b64encode(ret).decode('utf8')
|