diff options
author | Jose Antonio Marquez | 2012-05-16 15:42:37 -0700 |
---|---|---|
committer | Jose Antonio Marquez | 2012-05-16 15:42:37 -0700 |
commit | 857aafee732b6a85fa155ff4a05d1b8fde48f09d (patch) | |
tree | e06d330caee280aa05aec46391979e9abdcf974c /node_modules/montage/ui/flow-bezier-spline.js | |
parent | 5cc5d29736d8bf253e3a168cdd6443e839ffb23c (diff) | |
parent | fd54dabad7cbc27a0efb0957155c00d578912909 (diff) | |
download | ninja-857aafee732b6a85fa155ff4a05d1b8fde48f09d.tar.gz |
Merge branch 'refs/heads/Ninja-DOM-Architecture' into Document
Diffstat (limited to 'node_modules/montage/ui/flow-bezier-spline.js')
-rwxr-xr-x | node_modules/montage/ui/flow-bezier-spline.js | 163 |
1 files changed, 105 insertions, 58 deletions
diff --git a/node_modules/montage/ui/flow-bezier-spline.js b/node_modules/montage/ui/flow-bezier-spline.js index 5f2a9e76..3475be8b 100755 --- a/node_modules/montage/ui/flow-bezier-spline.js +++ b/node_modules/montage/ui/flow-bezier-spline.js | |||
@@ -1,6 +1,14 @@ | |||
1 | var Montage = require("montage").Montage, | 1 | var Montage = require("montage").Montage, |
2 | FlowBezierSpline = exports.FlowBezierSpline = Montage.create(Montage, { | 2 | FlowBezierSpline = exports.FlowBezierSpline = Montage.create(Montage, { |
3 | 3 | ||
4 | init: { | ||
5 | value: function() { | ||
6 | this._densities = []; | ||
7 | this._densitySummation = []; | ||
8 | return this; | ||
9 | } | ||
10 | }, | ||
11 | |||
4 | knots: { | 12 | knots: { |
5 | get: function () { | 13 | get: function () { |
6 | if (!this._knots) { | 14 | if (!this._knots) { |
@@ -37,17 +45,20 @@ var Montage = require("montage").Montage, | |||
37 | } | 45 | } |
38 | }, | 46 | }, |
39 | 47 | ||
48 | _densities: { | ||
49 | enumerable: false, | ||
50 | value: null | ||
51 | }, | ||
52 | |||
40 | densities: { | 53 | densities: { |
41 | get: function () { | 54 | get: function () { |
42 | if (!this._densities) { | ||
43 | this._densities = []; | ||
44 | } | ||
45 | return this._densities; | 55 | return this._densities; |
46 | }, | 56 | }, |
47 | set: function (value) { | 57 | set: function (value) { |
48 | this._densities = value; | 58 | this._densities = value; |
49 | this._densitiesLength = this._densities.length; | 59 | this._densitiesLength = this._densities.length; |
50 | this._densitySummation = null; | 60 | this._densitySummation.wipe(); |
61 | this._maxTime = null; | ||
51 | } | 62 | } |
52 | }, | 63 | }, |
53 | 64 | ||
@@ -75,7 +86,7 @@ var Montage = require("montage").Montage, | |||
75 | parameters: { | 86 | parameters: { |
76 | get: function () { | 87 | get: function () { |
77 | if (!this._parameters) { | 88 | if (!this._parameters) { |
78 | this._parameters = []; | 89 | this._parameters = {}; |
79 | } | 90 | } |
80 | return this._parameters; | 91 | return this._parameters; |
81 | }, | 92 | }, |
@@ -122,9 +133,14 @@ var Montage = require("montage").Montage, | |||
122 | } | 133 | } |
123 | }, | 134 | }, |
124 | 135 | ||
136 | _maxTime: { | ||
137 | enumerable: false, | ||
138 | value: null | ||
139 | }, | ||
140 | |||
125 | maxTime: { | 141 | maxTime: { |
126 | get: function () { | 142 | get: function () { |
127 | if (!this._densitySummation) { | 143 | if ((this._densitySummation === null) || this._densitySummation.length) { |
128 | this._computeDensitySummation(); | 144 | this._computeDensitySummation(); |
129 | } | 145 | } |
130 | return this._densitySummation[this._densitySummation.length - 1]; | 146 | return this._densitySummation[this._densitySummation.length - 1]; |
@@ -132,41 +148,55 @@ var Montage = require("montage").Montage, | |||
132 | set: function () {} | 148 | set: function () {} |
133 | }, | 149 | }, |
134 | 150 | ||
151 | _densitySummation: { | ||
152 | enumerable: false, | ||
153 | value: null | ||
154 | }, | ||
155 | |||
135 | _computeDensitySummation: { | 156 | _computeDensitySummation: { |
136 | enumerable: false, | 157 | enumerable: false, |
137 | value: function () { | 158 | value: function () { |
138 | var length = this.densities.length - 1, | 159 | var densities = this.densities, length = densities.length - 1, |
139 | sum = 0, | 160 | sum = 0, |
140 | i; | 161 | i, |
162 | densitySummation = this._densitySummation; | ||
141 | 163 | ||
142 | this._densitySummation = []; | 164 | densitySummation.wipe(); |
143 | for (i = 0; i < length; i++) { | 165 | for (i = 0; i < length; i++) { |
144 | sum += (this._densities[i] + this._densities[i + 1]) / 2; | 166 | sum += (densities[i] + densities[i + 1]) / 2; |
145 | this._densitySummation[i] = sum; | 167 | densitySummation[i] = sum; |
146 | } | 168 | } |
147 | } | 169 | } |
148 | }, | 170 | }, |
149 | 171 | ||
150 | getPositionAtTime: { | 172 | getPositionAtTime: { |
151 | value: function (time) { | 173 | value: function (time, position, parameters) { |
152 | var p0, p1, p2, p3, | 174 | var p0, p1, p2, p3, |
153 | a, b, c, | 175 | a, b, c, |
154 | t, y, | 176 | t, y, |
155 | start, | 177 | start, |
156 | parameters = {}, | 178 | _parameters = this._parameters, |
157 | i, j; | 179 | i, j, |
180 | parameterKeys, | ||
181 | parameterKeyCount, | ||
182 | jParameter, | ||
183 | jParameterData, | ||
184 | densitySummation = this._densitySummation; | ||
185 | |||
186 | position.length = 0; | ||
187 | parameters.wipe(); | ||
158 | 188 | ||
159 | if ((time >= 0) && (time < this.maxTime)) { | 189 | if ((time >= 0) && (time < this.maxTime)) { |
160 | if (this._previousIndex && (time >= this._densitySummation[this._previousIndex - 1])) { | 190 | if (this._previousIndex && (time >= densitySummation[this._previousIndex - 1])) { |
161 | i = this._previousIndex; | 191 | i = this._previousIndex; |
162 | } else { | 192 | } else { |
163 | i = 0; | 193 | i = 0; |
164 | } | 194 | } |
165 | while (time >= this._densitySummation[i]) { | 195 | while (time >= densitySummation[i]) { |
166 | i++; | 196 | i++; |
167 | } | 197 | } |
168 | this._previousIndex = i; | 198 | this._previousIndex = i; |
169 | start = i ? this._densitySummation[i - 1] : 0; | 199 | start = i ? densitySummation[i - 1] : 0; |
170 | p0 = this._knots[i], | 200 | p0 = this._knots[i], |
171 | p1 = this._nextHandlers[i], | 201 | p1 = this._nextHandlers[i], |
172 | p2 = this._previousHandlers[i + 1], | 202 | p2 = this._previousHandlers[i + 1], |
@@ -181,24 +211,29 @@ var Montage = require("montage").Montage, | |||
181 | } | 211 | } |
182 | y = 1 - t; | 212 | y = 1 - t; |
183 | // TODO: Redo this and create getParametersAtTime or getPositionAndParametersAtTime | 213 | // TODO: Redo this and create getParametersAtTime or getPositionAndParametersAtTime |
184 | for (j in this._parameters) { | 214 | |
185 | if (this._parameters.hasOwnProperty(j)) { | 215 | parameterKeys = Object.keys(_parameters); |
186 | if ((typeof this._parameters[j].data[i] !== "undefined") && (typeof this._parameters[j].data[i + 1] !== "undefined")) { | 216 | parameterKeyCount = parameterKeys.length; |
187 | parameters[j] = (this._parameters[j].data[i] * y + this._parameters[j].data[i + 1] * t) + this._parameters[j].units; | 217 | |
188 | } else { | 218 | for (j = 0; j < parameterKeyCount; j++) { |
189 | parameters[j] = this._parameters[j].data[this._parameters[j].data.length - 1] + this._parameters[j].units; | 219 | jParameter = _parameters[parameterKeys[j]]; |
190 | } | 220 | jParameterData = jParameter.data; |
221 | if ((typeof jParameterData[i] !== "undefined") && (typeof jParameterData[i + 1] !== "undefined")) { | ||
222 | parameters[parameterKeys[j]] = (jParameterData[i] * y + jParameterData[i + 1] * t).toFixed(5) + jParameter.units; | ||
223 | } else { | ||
224 | parameters[parameterKeys[j]] = jParameterData[jParameterData.length - 1].toFixed(5) + jParameter.units; | ||
191 | } | 225 | } |
226 | |||
192 | } | 227 | } |
193 | return [ | 228 | |
194 | p0[0]*(y*y*y)+p1[0]*(y*y*t*3)+p2[0]*(y*t*t*3)+p3[0]*(t*t*t), | 229 | position.push(p0[0]*(y*y*y)+p1[0]*(y*y*t*3)+p2[0]*(y*t*t*3)+p3[0]*(t*t*t)); |
195 | p0[1]*(y*y*y)+p1[1]*(y*y*t*3)+p2[1]*(y*t*t*3)+p3[1]*(t*t*t), | 230 | position.push(p0[1]*(y*y*y)+p1[1]*(y*y*t*3)+p2[1]*(y*t*t*3)+p3[1]*(t*t*t)); |
196 | p0[2]*(y*y*y)+p1[2]*(y*y*t*3)+p2[2]*(y*t*t*3)+p3[2]*(t*t*t), | 231 | position.push(p0[2]*(y*y*y)+p1[2]*(y*y*t*3)+p2[2]*(y*t*t*3)+p3[2]*(t*t*t)); |
197 | parameters | 232 | position.push(parameters); |
198 | ]; | 233 | |
199 | } else { | ||
200 | return null; | ||
201 | } | 234 | } |
235 | |||
236 | return position; | ||
202 | } | 237 | } |
203 | }, | 238 | }, |
204 | 239 | ||
@@ -223,9 +258,10 @@ var Montage = require("montage").Montage, | |||
223 | 258 | ||
224 | transform: { | 259 | transform: { |
225 | value: function (matrix) { | 260 | value: function (matrix) { |
226 | var spline = Montage.create(FlowBezierSpline); | 261 | var spline = Montage.create(FlowBezierSpline).init(); |
227 | 262 | ||
228 | spline._densities = this._densities; | 263 | spline._densities = this._densities; |
264 | spline._densitySummation = this._densitySummation; | ||
229 | spline._knots = |