[0, Y] version, 174 bytes
Written by: Cherise Sorbet
Tweaked by: Void Singer
Smallest Code as of: 19, April, 2009 **
Fastest Code as of: 19, April, 2009 **
CODE
vector fVecRange0X( vector vVecRaw, float vFltMax ){
//-- conditionals evaluate to 0 or 1 in lsl, this is used to
//-- remove values outside our range and set them = 0.0
return <0.0 < vVecRaw.x && vVecRaw.x < vFltMax) * vVecRaw.x,
(0.0 < vVecRaw.y && vVecRaw.y < vFltMax) * vVecRaw.y,
(0.0 < vVecRaw.z && vVecRaw.z < vFltMax) * vVecRaw.z>
//-- reset values to = Max, that were > Max
+ <vVecRaw.x => vFltMax),
(vVecRaw.y => vFltMax),
(vVecRaw.z => vFltMax)> * vFltMax;
}
[X, 0] version, 174 Bytes
Written by: Cherise Sorbet
Tweaked by: Void Singer
Smallest Code as of: 19, April, 2009 **
Fastest Code as of: 19, April, 2009 **
CODE
vector fVecRangeX0( vector vVecRaw, float vFltMin ){
//-- conditionals evaluate to 0 or 1 in lsl, this is used to
//-- remove values outside our range and set them = 0.0
return <vFltMin < vVecRaw.x && vVecRaw.x < 0.0) * vVecRaw.x,
(vFltMin < vVecRaw.y && vVecRaw.y < 0.0) * vVecRaw.y,
(vFltMin < vVecRaw.z && vVecRaw.z < 0.0) * vVecRaw.z>
//-- reset values to = Min, that were < Min
+ <vVecRaw.x <= vFltMin),
(vVecRaw.y <= vFltMin),
(vVecRaw.z <= vFltMin)> * vFltMin;
}
[X, Y] version, 195 Bytes
Written by: Boreal Latte
Tweaked by: Void Singer
Smallest Code as of: 10, May, 2009 **
Fastest Code as of: 10, May, 2009 **
CODE
vector fVecRangeXY( vector vVecRaw, float vFltMin, float vFltMax ){
//-- conditionals evaluate to 0 or 1 in lsl, this is used to capture the
//-- difference in values outside our range and remove the difference
return vVecRaw
//-- add to get values to = Min, that were < Min
+ <vFltMin > vVecRaw.x) * (vFltMin - vVecRaw.x),
(vFltMin > vVecRaw.y) * (vFltMin - vVecRaw.y),
(vFltMin > vVecRaw.z) * (vFltMin - vVecRaw.z)>
//-- subtract to get values to = Max, that were > Max
- <vVecRaw.x > vFltMax) * (vVecRaw.x - vFltMax),
(vVecRaw.y > vFltMax) * (vVecRaw.y - vFltMax),
(vVecRaw.z > vFltMax) * (vVecRaw.z - vFltMax)>;
}
NOTE: using one of the above functions with vVecRaw +/- a value to get get one boundary to zero will use less byte code than using this version, but may be potentially slower.
Example:
CODE
//-- range is [-10, 10]
//-- for reference, modification of upper bound is llAbs( Min ) + Max
//-- for reference, addition/subtraction value is +/-(<1.0, 1.0, 1.0> * llAbs( Min))
//-- reverse values if use [X, 0] version
fVecRangeOY( <-20.0, 0.0, 20.0> + <10.0, 10.0, 10.0>, 20 ) - <10.0, 10.0, 10.0>;
**: size only as tested in LSO, as MONO gives inconsistent results from llGetFreeMemory at this time. Speed differences were too small to measure in MONO with the current method.
Improvements Welcome
TODO:
add Clipping Functions to get ranges of [0,max_float], [max_float,0], [X,max_float] and [max_float,Y]
TODO:
test integer clamping/clipping variations [llFloor, llRound, llCeil, and (integer), etc]
TODO:
add wrapping variations to clamps/clips.
0.0 < vVecRaw.x && vVecRaw.x < vFltMax) * vVecRaw.x,