aboutsummaryrefslogtreecommitdiff
path: root/node_modules/montage-user/core/geometry/cubic-bezier.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/montage-user/core/geometry/cubic-bezier.js')
-rwxr-xr-xnode_modules/montage-user/core/geometry/cubic-bezier.js158
1 files changed, 158 insertions, 0 deletions
diff --git a/node_modules/montage-user/core/geometry/cubic-bezier.js b/node_modules/montage-user/core/geometry/cubic-bezier.js
new file mode 100755
index 00000000..eb608744
--- /dev/null
+++ b/node_modules/montage-user/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*/
11var Montage = require("montage").Montage;
12var 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
18var 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});