linearConversion: Difference between revisions

From Bohemia Interactive Community
Jump to navigation Jump to search
(example)
(description, syntax, example, seealso)
Line 7: Line 7:
____________________________________________________________________________________________
____________________________________________________________________________________________


| Converts value in interval [min, max] to {{Inline code|newMin + a * (max - min) / (newMax - newMin)}}, potentially clamps the final value.  |= Description
| Converts given value from given "from" range to wanted "to" range. If clipping is set to [[true]], the resulting value is guaranteed to be within "to" range no matter what.<br><br> Say given range is 0 to 1 and wanted range is 0 to 100 (percent calculation). Given value 0.55 then will be <br><tt>[[linearConversion]] [0,1,0.55,0,100]; //55</tt><br> but if given value is 1.1<br><tt>[[linearConversion]] [0,1,1.1,0,100,[[false]]]; //110</tt><br> or if clipping is [[true]] <br><tt>[[linearConversion]] [0,1,1.1,0,100,[[true]]]; //100</tt>|= Description
____________________________________________________________________________________________
____________________________________________________________________________________________


| '''linearConversion''' [min, max, value, newMin, newMax, clamp] |= Syntax
| '''linearConversion''' [minFrom, maxFrom, value, minTo, maxTo, clip] |= Syntax


|p1= [min, max, value, newMin, newMax, clamp]: [[Array]]  |= PARAMETER1  
|p1= [minFrom, maxFrom, value, minTo, maxTo, clip]: [[Array]]  |= PARAMETER1  


|p2= min: [[Number]] |= PARAMETER2  
|p2= minFrom: [[Number]] - start "from" range |= PARAMETER2  


|p3= max: [[Number]] |= PARAMETER3  
|p3= maxFrom: [[Number]] - end "from" range |= PARAMETER3  


|p4= value: [[Number]] |= PARAMETER4  
|p4= value: [[Number]] - given value from "from" range |= PARAMETER4  


|p5= newMin: [[Number]] |= PARAMETER5  
|p5= minTo: [[Number]] - start "to" range |= PARAMETER5  


|p6= newMax: [[Number]]  |= PARAMETER6  
|p6= maxTo: [[Number]]  - end "to" range |= PARAMETER6  


|p7= clamp (optional): [[Boolean]] (Default is false|= PARAMETER7  
|p7= clip (Optional): [[Boolean]] - if [[true]], resulting value cannot leave "to" range. Default: [[false]]|= PARAMETER7  


| [[Number]] |= RETURNVALUE  
| [[Number]] - respectful value from "to" range|= RETURNVALUE  




Line 45: Line 45:
____________________________________________________________________________________________
____________________________________________________________________________________________


| |= SEEALSO  
| [[round]], [[floor]], [[ceil]]|= SEEALSO  


|  |= MPBEHAVIOUR  
|  |= MPBEHAVIOUR  

Revision as of 23:59, 20 March 2016

Hover & click on the images for description

Description

Description:
Converts given value from given "from" range to wanted "to" range. If clipping is set to true, the resulting value is guaranteed to be within "to" range no matter what.

Say given range is 0 to 1 and wanted range is 0 to 100 (percent calculation). Given value 0.55 then will be
linearConversion [0,1,0.55,0,100]; //55
but if given value is 1.1
linearConversion [0,1,1.1,0,100,false]; //110
or if clipping is true
linearConversion [0,1,1.1,0,100,true]; //100
Groups:
Uncategorised

Syntax

Syntax:
linearConversion [minFrom, maxFrom, value, minTo, maxTo, clip]
Parameters:
[minFrom, maxFrom, value, minTo, maxTo, clip]: Array
minFrom: Number - start "from" range
maxFrom: Number - end "from" range
value: Number - given value from "from" range
minTo: Number - start "to" range
maxTo: Number - end "to" range
clip (Optional): Boolean - if true, resulting value cannot leave "to" range. Default: false
Return Value:
Number - respectful value from "to" range

Examples

Example 1:
linearConversion [4, 8, 5, 0, 1, false];
Example 2:
Calculate days from 1/1/1970: fnc_daysFromEpoc = { private _year = param [0]; private _days = 0; for "_i" from 1970 to _year - 1 do { _days = _days + round linearConversion [0, 1, dateToNumber [_i, 12, 31, 23, 59], 0, 365, false]; }; _days + linearConversion [0, 1, dateToNumber _this, 0, 365, false]; }; hint str (date call fnc_daysFromEpoc);

Additional Information

See also:
roundfloorceil

Notes

Report bugs on the Feedback Tracker and/or discuss them on the Arma Discord or on the Forums.
Only post proven facts here! Add Note

Notes

Posted on Mar 29, 2014 - 09:39
ffur2007slx2_5
(A3 0.50) It is recommended to use linearConversion instead of BIS_fnc_linearConversion: linearConversion [0,100,50,0,50,true ]; //same as [[0,100],50,[0,50]] call BIS_fnc_linearConversion As for clamp, true will disable new value out of its range while false won't: linearConversion [0,100,150,0,50,true ]; //return 50 linearConversion [0,100,150,0,50,false ]; //return 75

Bottom Section