diff options
Diffstat (limited to 'node_modules/montage/core/geometry')
-rwxr-xr-x | node_modules/montage/core/geometry/cubic-bezier.js | 158 | ||||
-rwxr-xr-x | node_modules/montage/core/geometry/point.js | 66 |
2 files changed, 224 insertions, 0 deletions
diff --git a/node_modules/montage/core/geometry/cubic-bezier.js b/node_modules/montage/core/geometry/cubic-bezier.js new file mode 100755 index 00000000..eb608744 --- /dev/null +++ b/node_modules/montage/core/geometry/cubic-bezier.js | |||
@@ -0,0 +1,158 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/core/geometry/cubic-bezier | ||
8 | @requires montage/core/core | ||
9 | @requires montage/core/geometry/point | ||
10 | */ | ||
11 | var Montage = require("montage").Montage; | ||
12 | var Point = require("core/geometry/point").Point; | ||
13 | /** | ||
14 | @class module:montage/core/geometry/cubic-bezier.CubicBezier | ||
15 | @extends module:montage/core/core.Montage | ||
16 | */ | ||
17 | |||
18 | var CubicBezier = exports.CubicBezier = Montage.create(Montage, /** @lends module:montage/core/geometry/cubic-bezier.CubicBezier# */{ | ||
19 | /** | ||
20 | @function | ||
21 | @param {Array} controlPoints Control points. | ||
22 | @returns itself | ||
23 | */ | ||
24 | init: { | ||
25 | enumerable: false, | ||
26 | value: function(controlPoints) { | ||
27 | if (controlPoints !== null) { | ||
28 | if (controlPoints.length === 2) { | ||
29 | this.p1 = controlPoints[0]; | ||
30 | this.p2 = controlPoints[1]; | ||
31 | } else if (controlPoints.length === 4) { | ||
32 | this.p0 = controlPoints[0]; | ||
33 | this.p1 = controlPoints[1]; | ||
34 | this.p2 = controlPoints[2]; | ||
35 | this.p3 = controlPoints[3]; | ||
36 | } | ||
37 | } | ||
38 | return this; | ||
39 | } | ||
40 | }, | ||
41 | /** | ||
42 | @function | ||
43 | @param {Number} t Control point. | ||
44 | @returns itself or Montage.create(Point).init(this.p0.x * b1 + this.p1.x * b2 + this.p2.x * b3 + this.p3.x * b4, | ||
45 | this.p0.y * b1 + this.p1.y * b2 + this.p2.y * b3 + this.p3.y * b4) | ||
46 | */ | ||
47 | position: { | ||
48 | enumerable: false, | ||
49 | value: function(t) { | ||
50 | if (t < 0 || t > 1) { | ||
51 | return; | ||
52 | } | ||
53 | |||
54 | t = 1 - t; | ||
55 | |||
56 | var b1 = t * t * t, | ||
57 | b2 = 3 * t * t * (1 - t), | ||
58 | b3 = 3 * t * (1 - t) * (1 - t), | ||
59 | b4 = (1 - t) * (1 - t) * (1 - t); | ||
60 | return Montage.create(Point).init(this.p0.x * b1 + this.p1.x * b2 + this.p2.x * b3 + this.p3.x * b4, | ||
61 | this.p0.y * b1 + this.p1.y * b2 + this.p2.y * b3 + this.p3.y * b4); | ||
62 | } | ||
63 | }, | ||
64 | /** | ||
65 | @function | ||
66 | @param {Number} t Control point. | ||
67 | @returns CubicBezier.create(CubicBezier).init([this.p0, this.p01, this.p012, this.p0123]) | ||
68 | */ | ||
69 | split: { | ||
70 | enumerable: false, | ||
71 | value: function(t) { | ||
72 | this.makeScaffolding(t); | ||
73 | return CubicBezier.create(CubicBezier).init([this.p0, this.p01, this.p012, this.p0123]); | ||
74 | } | ||
75 | }, | ||
76 | /** | ||
77 | @function | ||
78 | @param {Number} t Control point. | ||
79 | @returns CubicBezier.create(CubicBezier).init([Montage.create(Point).init(this.p01.x / xScale, this.p01.y / yScale), Montage.create(Point).init(this.p012.x / xScale, this.p012.y / yScale)]) | ||
80 | */ | ||
81 | splitToTimingFunction: { | ||
82 | enumerable: false, | ||
83 | value: function(t) { | ||
84 | this.makeScaffolding(t); | ||
85 | // p0123 x and y are the scale | ||
86 | var xScale = this.p0123.x, | ||
87 | yScale = this.p0123.y; | ||
88 | return CubicBezier.create(CubicBezier).init([Montage.create(Point).init(this.p01.x / xScale, this.p01.y / yScale), Montage.create(Point).init(this.p012.x / xScale, this.p012.y / yScale)]); | ||
89 | } | ||
90 | }, | ||
91 | /** | ||
92 | @function | ||
93 | @param {Number} t Control point. | ||
94 | */ | ||
95 | makeScaffolding: { | ||
96 | enumerable: false, | ||
97 | value: function(t) { | ||
98 | |||
99 | t = 1 - t; | ||
100 | |||
101 | var precision = 1000000; | ||
102 | Montage.defineProperty(this, 'p01', { | ||
103 | value: Point.interpolate(t, this.p0, this.p1, precision) | ||
104 | }); | ||
105 | Montage.defineProperty(this, 'p12', { | ||
106 | value: Point.interpolate(t, this.p1, this.p2, precision) | ||
107 | }); | ||
108 | Montage.defineProperty(this, 'p23', { | ||
109 | value: Point.interpolate(t, this.p2, this.p3, precision) | ||
110 | }); | ||
111 | Montage.defineProperty(this, 'p012', { | ||
112 | value: Point.interpolate(t, this.p01, this.p12, precision) | ||
113 | }); | ||
114 | Montage.defineProperty(this, 'p123', { | ||
115 | value: Point.interpolate(t, this.p12, this.p23, precision) | ||
116 | }); | ||
117 | Montage.defineProperty(this, 'p0123', { | ||
118 | value: Point.interpolate(t, this.p012, this.p123, precision) | ||
119 | }); | ||
120 | } | ||
121 | }, | ||
122 | /** | ||
123 | First control point in bezier curve. | ||
124 | @type {Property} | ||
125 | @default {Number} Montage.create(Point).init(0, 0) | ||
126 | */ | ||
127 | p0: { | ||
128 | enumerable: true, | ||
129 | value: Montage.create(Point).init(0, 0) | ||
130 | }, | ||
131 | /** | ||
132 | Second control point in bezier curve. | ||
133 | @type {Property} | ||
134 | @default {Number} Montage.create(Point).init(0, 0) | ||
135 | */ | ||
136 | p1: { | ||
137 | enumerable: true, | ||
138 | value: Montage.create(Point).init(0, 0) | ||
139 | }, | ||
140 | /** | ||
141 | Third control point in bezier curve. | ||
142 | @type {Property} | ||
143 | @default {Number} Montage.create(Point).init(1, 1) | ||
144 | */ | ||
145 | p2: { | ||
146 | enumerable: true, | ||
147 | value: Montage.create(Point).init(1, 1) | ||
148 | }, | ||
149 | /** | ||
150 | Fourth control point in bezier curve. | ||
151 | @type {Property} | ||
152 | @default {Number}M ontage.create(Point).init(1, 1) | ||
153 | */ | ||
154 | p3: { | ||
155 | enumerable: true, | ||
156 | value: Montage.create(Point).init(1, 1) | ||
157 | } | ||
158 | }); | ||
diff --git a/node_modules/montage/core/geometry/point.js b/node_modules/montage/core/geometry/point.js new file mode 100755 index 00000000..cec433be --- /dev/null +++ b/node_modules/montage/core/geometry/point.js | |||
@@ -0,0 +1,66 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | /** | ||
7 | @module montage/core/geometry/point | ||
8 | @requires montage/core/core | ||
9 | */ | ||
10 | var Montage = require("montage").Montage; | ||
11 | /** | ||
12 | @class module:montage/core/geometry/point.Point | ||
13 | @extends module:montage/core/core.Montage | ||
14 | */ | ||
15 | |||
16 | exports.Point = Montage.create(Montage, /** @lends module:montage/core/geometry/point.Point# */ { | ||
17 | init: { | ||
18 | enumerable: false, | ||
19 | value: function(x, y) { | ||
20 | this.x = x === null ? 0 : x; | ||
21 | this.y = y === null ? 0 : y; | ||
22 | return this; | ||
23 | } | ||
24 | }, | ||
25 | /** | ||
26 | Interpolates between two points. | ||
27 | @function | ||
28 | @param {Axis} percent The interpolation percentage. | ||
29 | @param {Axis} point0 The 0 interpolation point. | ||
30 | @param {Axis} point1 The 1 interpolation point. | ||
31 | @param {Axis} precision The interpolation precision. | ||
32 | @returns Montage.create(Point).init(xValue, yValue) | ||
33 | */ | ||
34 | interpolate: { | ||
35 | enumerable: false, | ||
36 | value: function(percent, point0, point1, precision) { | ||
37 | var xValue, | ||
38 | yValue; | ||
39 | xValue = point0.x + (point1.x - point0.x) * percent; | ||
40 | yValue = point0.y + (point1.y - point0.y) * percent; | ||
41 | if (precision > 0) { | ||
42 | xValue = Math.round(xValue * precision) / precision; | ||
43 | yValue = Math.round(yValue * precision) / precision; | ||
44 | } | ||
45 | return exports.Point.create().init(xValue, yValue); | ||
46 | } | ||
47 | }, | ||
48 | /** | ||
49 | The x axis point. | ||
50 | @type {Number} | ||
51 | @default 0 | ||
52 | */ | ||
53 | x: { | ||
54 | enumerable: true, | ||
55 | value: 0 | ||
56 | }, | ||
57 | /** | ||
58 | The y axis point. | ||
59 | @type {Number} | ||
60 | @default 0 | ||
61 | */ | ||
62 | y: { | ||