~ubuntu-sdk-team/ubuntu-ui-toolkit/utopic

« back to all changes in this revision

Viewing changes to modules/Ubuntu/Components/mathUtils.js

  • Committer: CI bot
  • Author(s): Zsombor Egri, Michael Sheldon, Zoltán Balogh, Christian Dywan, Tim Peeters
  • Date: 2014-10-07 12:09:27 UTC
  • mfrom: (1000.249.11 landing-0711)
  • Revision ID: ps-jenkins@lists.canonical.com-20141007120927-ucysonqxn60vu8gz
  [ Michael Sheldon ]
  * Removes the keyboard anchor animation as this is now implemented
    in the keyboard.

  [ Tim Peeters ]
  * PageStack push returns the pushed page. Fixes LP: #1361919
  * Add selection mode as a preset to the header configuration.
    Fixes LP: #1370146.

  [ Zsombor Egri ]
  * Fix Dialog foreground sizing. Fixes LP: #1337555, LP: #1337556.
  * Workaround for StateSaver to fall back to use qgetenv() when
    QStandardPaths fails to return XDG_RUNTIME_DIR path.
    Fixes LP: #1363112.

  [ Christian Dywan ]
  * Add unit tests for MathUtils API.
    Fixes LP: #1244685.
  * Text field hint should use the same font as the editor.
    Fixes LP: #1237400.
  * Read-only text fields mustn't have a clear button.
    Fixes LP: #1337257.
  * autopilot package should source-depend on QML plugin.
    Fixes LP: #1236085.
 

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
.pragma library
18
18
 
19
 
// FIXME(loicm) It would be better to have these functions available in a global
20
 
//     set of common native C++ functions.
21
 
 
 
19
// Ensure the value x is between min and max
22
20
function clamp(x, min, max) {
23
21
    if (min <= max) {
24
22
        return Math.max(min, Math.min(x, max));
28
26
    }
29
27
}
30
28
 
31
 
function lerp(x, a, b) {
32
 
    return ((1.0 - x) * a) + (x * b);
 
29
// Get the linear interpolation
 
30
function lerp(delta, from, to) {
 
31
    return ((1.0 - delta) * from) + (delta * to);
33
32
}
34
33
 
35
34
// Linearly project a value x from [xmin, xmax] into [ymin, ymax]
37
36
    return ((x - xmin) * ymax - (x - xmax) * ymin) / (xmax - xmin)
38
37
}
39
38
 
 
39
// Linearly project a value x, but in addition to projectValue it's clamped to xmin/xmax first
40
40
function clampAndProject(x, xmin, xmax, ymin, ymax) {
41
41
    return projectValue(clamp(x, xmin, xmax), xmin, xmax, ymin, ymax)
42
42
}