Added tranform.centered_cosine(...).
This commit is contained in:
parent
9177195a37
commit
f0e1ef97d7
@ -132,6 +132,16 @@
|
|||||||
<td class="summary">Performs a linear transform on the given value to transform the value from the range -10/10 to 0/1.</td>
|
<td class="summary">Performs a linear transform on the given value to transform the value from the range -10/10 to 0/1.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#transform.centered">transform.centered</a> (value, transformation, min, max, new_min, new_max)</td>
|
||||||
|
<td class="summary">Performs the given transformation on the given value with the peak in center of the min and max values.</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
|
<tr>
|
||||||
|
<td class="name" nowrap><a href="#transform.centered_cosine">transform.centered_cosine</a> (value, min, max, new_min, new_max)</td>
|
||||||
|
<td class="summary">Performs a cosine transformation on the given value with the peak in center of the min and max values.</td>
|
||||||
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="name" nowrap><a href="#transform.centered_linear">transform.centered_linear</a> (value, min, max, new_min, new_max)</td>
|
<td class="name" nowrap><a href="#transform.centered_linear">transform.centered_linear</a> (value, min, max, new_min, new_max)</td>
|
||||||
<td class="summary">Performs a linear transformation on the given value with the peak in center of the min and max values.</td>
|
<td class="summary">Performs a linear transformation on the given value with the peak in center of the min and max values.</td>
|
||||||
@ -197,6 +207,100 @@ Performs a linear transform on the given value to transform the value from the r
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Return value:</h3>
|
||||||
|
The transformed value.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dt><a name="transform.centered"></a><strong>transform.centered</strong> (value, transformation, min, max, new_min, new_max)</dt>
|
||||||
|
<dd>
|
||||||
|
Performs the given transformation on the given value with the peak in center of the min and max values.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters</h3>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
value: The value to transform.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
transformation: The transformation function, assumed to accept five values.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
min: Optional. The original minimum value, defaults to -1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
max: Optional. The original maximum value, default to 1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
new_min: Optional. The minimum value for the new range, defaults to 0.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
new_max: Optional. The maximum value for the new range, defaults to 1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Return value:</h3>
|
||||||
|
The transformed value.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</dd>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<dt><a name="transform.centered_cosine"></a><strong>transform.centered_cosine</strong> (value, min, max, new_min, new_max)</dt>
|
||||||
|
<dd>
|
||||||
|
Performs a cosine transformation on the given value with the peak in center of the min and max values.
|
||||||
|
|
||||||
|
|
||||||
|
<h3>Parameters</h3>
|
||||||
|
<ul>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
value: The value to transform.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
min: Optional. The original minimum value, defaults to -1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
max: Optional. The original maximum value, default to 1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
new_min: Optional. The minimum value for the new range, defaults to 0.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
new_max: Optional. The maximum value for the new range, defaults to 1.
|
||||||
|
</li>
|
||||||
|
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<h3>Return value:</h3>
|
<h3>Return value:</h3>
|
||||||
The transformed value.
|
The transformed value.
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
dofile("./utils/test.lua")
|
dofile("./utils/test.lua")
|
||||||
|
|
||||||
-- Load the file for testing.
|
-- Load the file for testing.
|
||||||
|
dofile("./utils/interpolate.lua")
|
||||||
dofile("./utils/transform.lua")
|
dofile("./utils/transform.lua")
|
||||||
dofile("./utils/mathutil.lua")
|
dofile("./utils/mathutil.lua")
|
||||||
|
|
||||||
|
@ -40,6 +40,43 @@ function transform.big_linear(value, new_min, new_max)
|
|||||||
return transform.linear(value, -10, 10, new_min, new_max)
|
return transform.linear(value, -10, 10, new_min, new_max)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Performs the given transformation on the given value with the peak in center
|
||||||
|
-- of the min and max values.
|
||||||
|
--
|
||||||
|
-- @param value The value to transform.
|
||||||
|
-- @param transformation The transformation function, assumed to accept five
|
||||||
|
-- values.
|
||||||
|
-- @param min Optional. The original minimum value, defaults to -1.
|
||||||
|
-- @param max Optional. The original maximum value, default to 1.
|
||||||
|
-- @param new_min Optional. The minimum value for the new range, defaults to 0.
|
||||||
|
-- @param new_max Optional. The maximum value for the new range, defaults to 1.
|
||||||
|
-- @return The transformed value.
|
||||||
|
function transform.centered(value, transformation, min, max, new_min, new_max)
|
||||||
|
min = min or -1
|
||||||
|
max = max or 1
|
||||||
|
|
||||||
|
local center = (min + max) / 2
|
||||||
|
|
||||||
|
if value < center then
|
||||||
|
return transformation(value, min, center, new_min, new_max)
|
||||||
|
else
|
||||||
|
return transformation(value, max, center, new_min, new_max)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Performs a cosine transformation on the given value with the peak in center
|
||||||
|
-- of the min and max values.
|
||||||
|
--
|
||||||
|
-- @param value The value to transform.
|
||||||
|
-- @param min Optional. The original minimum value, defaults to -1.
|
||||||
|
-- @param max Optional. The original maximum value, default to 1.
|
||||||
|
-- @param new_min Optional. The minimum value for the new range, defaults to 0.
|
||||||
|
-- @param new_max Optional. The maximum value for the new range, defaults to 1.
|
||||||
|
-- @return The transformed value.
|
||||||
|
function transform.centered_cosine(value, min, max, new_min, new_max)
|
||||||
|
return transform.centered(value, transform.cosine, min, max, new_min, new_max)
|
||||||
|
end
|
||||||
|
|
||||||
--- Performs a linear transformation on the given value with the peak in center
|
--- Performs a linear transformation on the given value with the peak in center
|
||||||
-- of the min and max values.
|
-- of the min and max values.
|
||||||
--
|
--
|
||||||
@ -49,16 +86,7 @@ end
|
|||||||
-- @param new_min Optional. The minimum value for the new range, defaults to 0.
|
-- @param new_min Optional. The minimum value for the new range, defaults to 0.
|
||||||
-- @param new_max Optional. The maximum value for the new range, defaults to 1.
|
-- @param new_max Optional. The maximum value for the new range, defaults to 1.
|
||||||
function transform.centered_linear(value, min, max, new_min, new_max)
|
function transform.centered_linear(value, min, max, new_min, new_max)
|
||||||
min = min or -1
|
return transform.centered(value, transform.linear, min, max, new_min, new_max)
|
||||||
max = max or 1
|
|
||||||
|
|
||||||
local center = (min + max) / 2
|
|
||||||
|
|
||||||
if value < center then
|
|
||||||
return transform.linear(value, min, center, new_min, new_max)
|
|
||||||
else
|
|
||||||
return transform.linear(value, max, center, new_min, new_max)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Performs a cosine transform on the given value to transform the value
|
--- Performs a cosine transform on the given value to transform the value
|
||||||
|
Loading…
x
Reference in New Issue
Block a user