Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(328)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/Geometry.js

Issue 2466123002: DevTools: reformat front-end code to match chromium style. (Closed)
Patch Set: all done Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer 11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the 12 * in the documentation and/or other materials provided with the
13 * distribution. 13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its 14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from 15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission. 16 * this software without specific prior written permission.
17 * 17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30
31 WebInspector.Geometry = {}; 30 WebInspector.Geometry = {};
32 31
33 /** 32 /**
34 * @type {number} 33 * @type {number}
35 */ 34 */
36 WebInspector.Geometry._Eps = 1e-5; 35 WebInspector.Geometry._Eps = 1e-5;
37 36
38 /** 37 /**
39 * @constructor 38 * @unrestricted
40 * @param {number} x 39 */
41 * @param {number} y 40 WebInspector.Geometry.Vector = class {
42 * @param {number} z 41 /**
43 */ 42 * @param {number} x
44 WebInspector.Geometry.Vector = function(x, y, z) 43 * @param {number} y
45 { 44 * @param {number} z
45 */
46 constructor(x, y, z) {
46 this.x = x; 47 this.x = x;
47 this.y = y; 48 this.y = y;
48 this.z = z; 49 this.z = z;
49 }; 50 }
50 51
51 WebInspector.Geometry.Vector.prototype = { 52 /**
52 /** 53 * @return {number}
53 * @return {number} 54 */
54 */ 55 length() {
55 length: function() 56 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
56 { 57 }
57 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); 58
58 }, 59 normalize() {
59 60 var length = this.length();
60 normalize: function() 61 if (length <= WebInspector.Geometry._Eps)
61 { 62 return;
62 var length = this.length(); 63
63 if (length <= WebInspector.Geometry._Eps) 64 this.x /= length;
64 return; 65 this.y /= length;
65 66 this.z /= length;
66 this.x /= length; 67 }
67 this.y /= length; 68 };
68 this.z /= length; 69
69 } 70 /**
70 }; 71 * @unrestricted
71 72 */
72 /** 73 WebInspector.Geometry.Point = class {
73 * @constructor 74 /**
74 * @param {number} x 75 * @param {number} x
75 * @param {number} y 76 * @param {number} y
76 */ 77 */
77 WebInspector.Geometry.Point = function(x, y) { 78 constructor(x, y) {
78 this.x = x; 79 this.x = x;
79 this.y = y; 80 this.y = y;
80 }; 81 }
81 82
82 WebInspector.Geometry.Point.prototype = { 83 /**
83 /** 84 * @param {!WebInspector.Geometry.Point} p
84 * @param {!WebInspector.Geometry.Point} p 85 * @return {number}
85 * @return {number} 86 */
86 */ 87 distanceTo(p) {
87 distanceTo: function(p) 88 return Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2));
88 { 89 }
89 return Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2)); 90
90 }, 91 /**
91 92 * @param {!WebInspector.Geometry.Point} line
92 /** 93 * @return {!WebInspector.Geometry.Point}
93 * @param {!WebInspector.Geometry.Point} line 94 */
94 * @return {!WebInspector.Geometry.Point} 95 projectOn(line) {
95 */ 96 if (line.x === 0 && line.y === 0)
96 projectOn: function(line) 97 return new WebInspector.Geometry.Point(0, 0);
97 { 98 return line.scale((this.x * line.x + this.y * line.y) / (Math.pow(line.x, 2) + Math.pow(line.y, 2)));
98 if (line.x === 0 && line.y === 0) 99 }
99 return new WebInspector.Geometry.Point(0, 0); 100
100 return line.scale((this.x * line.x + this.y * line.y) / (Math.pow(line.x , 2) + Math.pow(line.y, 2))); 101 /**
101 }, 102 * @param {number} scalar
102 103 * @return {!WebInspector.Geometry.Point}
103 /** 104 */
104 * @param {number} scalar 105 scale(scalar) {
105 * @return {!WebInspector.Geometry.Point} 106 return new WebInspector.Geometry.Point(this.x * scalar, this.y * scalar);
106 */ 107 }
107 scale: function(scalar) 108
108 { 109 /**
109 return new WebInspector.Geometry.Point(this.x * scalar, this.y * scalar) ; 110 * @override
110 }, 111 * @return {string}
111 112 */
112 /** 113 toString() {
113 * @override 114 return Math.round(this.x * 100) / 100 + ', ' + Math.round(this.y * 100) / 10 0;
114 * @return {string} 115 }
115 */ 116 };
116 toString: function() 117
117 { 118 /**
118 return Math.round(this.x * 100) / 100 + ", " + Math.round(this.y * 100) / 100; 119 * @unrestricted
119 } 120 */
120 }; 121 WebInspector.Geometry.CubicBezier = class {
121 122 /**
122 /** 123 * @param {!WebInspector.Geometry.Point} point1
123 * @constructor 124 * @param {!WebInspector.Geometry.Point} point2
124 * @param {!WebInspector.Geometry.Point} point1 125 */
125 * @param {!WebInspector.Geometry.Point} point2 126 constructor(point1, point2) {
126 */
127 WebInspector.Geometry.CubicBezier = function(point1, point2)
128 {
129 this.controlPoints = [point1, point2]; 127 this.controlPoints = [point1, point2];
130 }; 128 }
131 129
132 /** @type {!RegExp} */ 130 /**
133 WebInspector.Geometry.CubicBezier.Regex = /((cubic-bezier\([^)]+\))|\b(linear|ea se-in-out|ease-in|ease-out|ease)\b)/g; 131 * @param {string} text
134 132 * @return {?WebInspector.Geometry.CubicBezier}
135 WebInspector.Geometry.CubicBezier.KeywordValues = { 133 */
136 "linear": "cubic-bezier(0, 0, 1, 1)", 134 static parse(text) {
137 "ease": "cubic-bezier(0.25, 0.1, 0.25, 1)",
138 "ease-in": "cubic-bezier(0.42, 0, 1, 1)",
139 "ease-in-out": "cubic-bezier(0.42, 0, 0.58, 1)",
140 "ease-out": "cubic-bezier(0, 0, 0.58, 1)"
141 };
142
143 /**
144 * @param {string} text
145 * @return {?WebInspector.Geometry.CubicBezier}
146 */
147 WebInspector.Geometry.CubicBezier.parse = function(text)
148 {
149 var keywordValues = WebInspector.Geometry.CubicBezier.KeywordValues; 135 var keywordValues = WebInspector.Geometry.CubicBezier.KeywordValues;
150 var value = text.toLowerCase().replace(/\s+/g, ""); 136 var value = text.toLowerCase().replace(/\s+/g, '');
151 if (Object.keys(keywordValues).indexOf(value) !== -1) 137 if (Object.keys(keywordValues).indexOf(value) !== -1)
152 return WebInspector.Geometry.CubicBezier.parse(keywordValues[value]); 138 return WebInspector.Geometry.CubicBezier.parse(keywordValues[value]);
153 var bezierRegex = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^,]+)\)$/; 139 var bezierRegex = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^,]+)\)$/;
154 var match = value.match(bezierRegex); 140 var match = value.match(bezierRegex);
155 if (match) { 141 if (match) {
156 var control1 = new WebInspector.Geometry.Point(parseFloat(match[1]), par seFloat(match[2])); 142 var control1 = new WebInspector.Geometry.Point(parseFloat(match[1]), parse Float(match[2]));
157 var control2 = new WebInspector.Geometry.Point(parseFloat(match[3]), par seFloat(match[4])); 143 var control2 = new WebInspector.Geometry.Point(parseFloat(match[3]), parse Float(match[4]));
158 return new WebInspector.Geometry.CubicBezier(control1, control2); 144 return new WebInspector.Geometry.CubicBezier(control1, control2);
159 } 145 }
160 return null; 146 return null;
161 }; 147 }
162 148
163 149 /**
164 WebInspector.Geometry.CubicBezier.prototype = { 150 * @param {number} t
151 * @return {!WebInspector.Geometry.Point}
152 */
153 evaluateAt(t) {
165 /** 154 /**
155 * @param {number} v1
156 * @param {number} v2
166 * @param {number} t 157 * @param {number} t
167 * @return {!WebInspector.Geometry.Point}
168 */ 158 */
169 evaluateAt: function(t) 159 function evaluate(v1, v2, t) {
170 { 160 return 3 * (1 - t) * (1 - t) * t * v1 + 3 * (1 - t) * t * t * v2 + Math.po w(t, 3);
171 /**
172 * @param {number} v1
173 * @param {number} v2
174 * @param {number} t
175 */
176 function evaluate(v1, v2, t)
177 {
178 return 3 * (1 - t) * (1 - t) * t * v1 + 3 * (1 - t) * t * t * v2 + M ath.pow(t, 3);
179 }
180
181 var x = evaluate(this.controlPoints[0].x, this.controlPoints[1].x, t);
182 var y = evaluate(this.controlPoints[0].y, this.controlPoints[1].y, t);
183 return new WebInspector.Geometry.Point(x, y);
184 },
185
186 /**
187 * @return {string}
188 */
189 asCSSText: function()
190 {
191 var raw = "cubic-bezier(" + this.controlPoints.join(", ") + ")";
192 var keywordValues = WebInspector.Geometry.CubicBezier.KeywordValues;
193 for (var keyword in keywordValues) {
194 if (raw === keywordValues[keyword])
195 return keyword;
196 }
197 return raw;
198 } 161 }
199 }; 162
200 163 var x = evaluate(this.controlPoints[0].x, this.controlPoints[1].x, t);
201 /** 164 var y = evaluate(this.controlPoints[0].y, this.controlPoints[1].y, t);
202 * @constructor 165 return new WebInspector.Geometry.Point(x, y);
203 * @param {number} alpha 166 }
204 * @param {number} beta 167
205 * @param {number} gamma 168 /**
206 */ 169 * @return {string}
207 WebInspector.Geometry.EulerAngles = function(alpha, beta, gamma) 170 */
208 { 171 asCSSText() {
172 var raw = 'cubic-bezier(' + this.controlPoints.join(', ') + ')';
173 var keywordValues = WebInspector.Geometry.CubicBezier.KeywordValues;
174 for (var keyword in keywordValues) {
175 if (raw === keywordValues[keyword])
176 return keyword;
177 }
178 return raw;
179 }
180 };
181
182 /** @type {!RegExp} */
183 WebInspector.Geometry.CubicBezier.Regex = /((cubic-bezier\([^)]+\))|\b(linear|ea se-in-out|ease-in|ease-out|ease)\b)/g;
184
185 WebInspector.Geometry.CubicBezier.KeywordValues = {
186 'linear': 'cubic-bezier(0, 0, 1, 1)',
187 'ease': 'cubic-bezier(0.25, 0.1, 0.25, 1)',
188 'ease-in': 'cubic-bezier(0.42, 0, 1, 1)',
189 'ease-in-out': 'cubic-bezier(0.42, 0, 0.58, 1)',
190 'ease-out': 'cubic-bezier(0, 0, 0.58, 1)'
191 };
192
193
194 /**
195 * @unrestricted
196 */
197 WebInspector.Geometry.EulerAngles = class {
198 /**
199 * @param {number} alpha
200 * @param {number} beta
201 * @param {number} gamma
202 */
203 constructor(alpha, beta, gamma) {
209 this.alpha = alpha; 204 this.alpha = alpha;
210 this.beta = beta; 205 this.beta = beta;
211 this.gamma = gamma; 206 this.gamma = gamma;
212 }; 207 }
213 208
214 /** 209 /**
215 * @param {!CSSMatrix} rotationMatrix 210 * @param {!CSSMatrix} rotationMatrix
216 * @return {!WebInspector.Geometry.EulerAngles} 211 * @return {!WebInspector.Geometry.EulerAngles}
217 */ 212 */
218 WebInspector.Geometry.EulerAngles.fromRotationMatrix = function(rotationMatrix) 213 static fromRotationMatrix(rotationMatrix) {
219 {
220 var beta = Math.atan2(rotationMatrix.m23, rotationMatrix.m33); 214 var beta = Math.atan2(rotationMatrix.m23, rotationMatrix.m33);
221 var gamma = Math.atan2(-rotationMatrix.m13, Math.sqrt(rotationMatrix.m11 * r otationMatrix.m11 + rotationMatrix.m12 * rotationMatrix.m12)); 215 var gamma = Math.atan2(
216 -rotationMatrix.m13,
217 Math.sqrt(rotationMatrix.m11 * rotationMatrix.m11 + rotationMatrix.m12 * rotationMatrix.m12));
222 var alpha = Math.atan2(rotationMatrix.m12, rotationMatrix.m11); 218 var alpha = Math.atan2(rotationMatrix.m12, rotationMatrix.m11);
223 return new WebInspector.Geometry.EulerAngles(WebInspector.Geometry.radiansTo Degrees(alpha), WebInspector.Geometry.radiansToDegrees(beta), WebInspector.Geome try.radiansToDegrees(gamma)); 219 return new WebInspector.Geometry.EulerAngles(
224 }; 220 WebInspector.Geometry.radiansToDegrees(alpha), WebInspector.Geometry.rad iansToDegrees(beta),
225 221 WebInspector.Geometry.radiansToDegrees(gamma));
226 WebInspector.Geometry.EulerAngles.prototype = { 222 }
227 /** 223
228 * @return {string} 224 /**
229 */ 225 * @return {string}
230 toRotate3DString: function() 226 */
231 { 227 toRotate3DString() {
232 var gammaAxisY = -Math.sin(WebInspector.Geometry.degreesToRadians(this.b eta)); 228 var gammaAxisY = -Math.sin(WebInspector.Geometry.degreesToRadians(this.beta) );
233 var gammaAxisZ = Math.cos(WebInspector.Geometry.degreesToRadians(this.be ta)); 229 var gammaAxisZ = Math.cos(WebInspector.Geometry.degreesToRadians(this.beta)) ;
234 var axis = { 230 var axis = {alpha: [0, 1, 0], beta: [-1, 0, 0], gamma: [0, gammaAxisY, gamma AxisZ]};
235 alpha: [0, 1, 0], 231 return 'rotate3d(' + axis.alpha.join(',') + ',' + this.alpha + 'deg) ' +
236 beta: [-1, 0, 0], 232 'rotate3d(' + axis.beta.join(',') + ',' + this.beta + 'deg) ' +
237 gamma: [0, gammaAxisY, gammaAxisZ] 233 'rotate3d(' + axis.gamma.join(',') + ',' + this.gamma + 'deg)';
238 }; 234 }
239 return "rotate3d(" + axis.alpha.join(",") + "," + this.alpha + "deg) " 235 };
240 + "rotate3d(" + axis.beta.join(",") + "," + this.beta + "deg) " 236
241 + "rotate3d(" + axis.gamma.join(",") + "," + this.gamma + "deg)";
242 }
243 };
244 237
245 /** 238 /**
246 * @param {!WebInspector.Geometry.Vector} u 239 * @param {!WebInspector.Geometry.Vector} u
247 * @param {!WebInspector.Geometry.Vector} v 240 * @param {!WebInspector.Geometry.Vector} v
248 * @return {number} 241 * @return {number}
249 */ 242 */
250 WebInspector.Geometry.scalarProduct = function(u, v) 243 WebInspector.Geometry.scalarProduct = function(u, v) {
251 { 244 return u.x * v.x + u.y * v.y + u.z * v.z;
252 return u.x * v.x + u.y * v.y + u.z * v.z; 245 };
253 }; 246
254 247 /**
255 /**
256 * @param {!WebInspector.Geometry.Vector} u 248 * @param {!WebInspector.Geometry.Vector} u
257 * @param {!WebInspector.Geometry.Vector} v 249 * @param {!WebInspector.Geometry.Vector} v
258 * @return {!WebInspector.Geometry.Vector} 250 * @return {!WebInspector.Geometry.Vector}
259 */ 251 */
260 WebInspector.Geometry.crossProduct = function(u, v) 252 WebInspector.Geometry.crossProduct = function(u, v) {
261 { 253 var x = u.y * v.z - u.z * v.y;
262 var x = u.y * v.z - u.z * v.y; 254 var y = u.z * v.x - u.x * v.z;
263 var y = u.z * v.x - u.x * v.z; 255 var z = u.x * v.y - u.y * v.x;
264 var z = u.x * v.y - u.y * v.x; 256 return new WebInspector.Geometry.Vector(x, y, z);
265 return new WebInspector.Geometry.Vector(x, y, z);
266 }; 257 };
267 258
268 /** 259 /**
269 * @param {!WebInspector.Geometry.Vector} u 260 * @param {!WebInspector.Geometry.Vector} u
270 * @param {!WebInspector.Geometry.Vector} v 261 * @param {!WebInspector.Geometry.Vector} v
271 * @return {!WebInspector.Geometry.Vector} 262 * @return {!WebInspector.Geometry.Vector}
272 */ 263 */
273 WebInspector.Geometry.subtract = function(u, v) 264 WebInspector.Geometry.subtract = function(u, v) {
274 { 265 var x = u.x - v.x;
275 var x = u.x - v.x; 266 var y = u.y - v.y;
276 var y = u.y - v.y; 267 var z = u.z - v.z;
277 var z = u.z - v.z; 268 return new WebInspector.Geometry.Vector(x, y, z);
278 return new WebInspector.Geometry.Vector(x, y, z);
279 }; 269 };
280 270
281 /** 271 /**
282 * @param {!WebInspector.Geometry.Vector} v 272 * @param {!WebInspector.Geometry.Vector} v
283 * @param {!CSSMatrix} m 273 * @param {!CSSMatrix} m
284 * @return {!WebInspector.Geometry.Vector} 274 * @return {!WebInspector.Geometry.Vector}
285 */ 275 */
286 WebInspector.Geometry.multiplyVectorByMatrixAndNormalize = function(v, m) 276 WebInspector.Geometry.multiplyVectorByMatrixAndNormalize = function(v, m) {
287 { 277 var t = v.x * m.m14 + v.y * m.m24 + v.z * m.m34 + m.m44;
288 var t = v.x * m.m14 + v.y * m.m24 + v.z * m.m34 + m.m44; 278 var x = (v.x * m.m11 + v.y * m.m21 + v.z * m.m31 + m.m41) / t;
289 var x = (v.x * m.m11 + v.y * m.m21 + v.z * m.m31 + m.m41) / t; 279 var y = (v.x * m.m12 + v.y * m.m22 + v.z * m.m32 + m.m42) / t;
290 var y = (v.x * m.m12 + v.y * m.m22 + v.z * m.m32 + m.m42) / t; 280 var z = (v.x * m.m13 + v.y * m.m23 + v.z * m.m33 + m.m43) / t;
291 var z = (v.x * m.m13 + v.y * m.m23 + v.z * m.m33 + m.m43) / t; 281 return new WebInspector.Geometry.Vector(x, y, z);
292 return new WebInspector.Geometry.Vector(x, y, z);
293 }; 282 };
294 283
295 /** 284 /**
296 * @param {!WebInspector.Geometry.Vector} u 285 * @param {!WebInspector.Geometry.Vector} u
297 * @param {!WebInspector.Geometry.Vector} v 286 * @param {!WebInspector.Geometry.Vector} v
298 * @return {number} 287 * @return {number}
299 */ 288 */
300 WebInspector.Geometry.calculateAngle = function(u, v) 289 WebInspector.Geometry.calculateAngle = function(u, v) {
301 { 290 var uLength = u.length();
302 var uLength = u.length(); 291 var vLength = v.length();
303 var vLength = v.length(); 292 if (uLength <= WebInspector.Geometry._Eps || vLength <= WebInspector.Geometry. _Eps)
304 if (uLength <= WebInspector.Geometry._Eps || vLength <= WebInspector.Geometr y._Eps) 293 return 0;
305 return 0; 294 var cos = WebInspector.Geometry.scalarProduct(u, v) / uLength / vLength;
306 var cos = WebInspector.Geometry.scalarProduct(u, v) / uLength / vLength; 295 if (Math.abs(cos) > 1)
307 if (Math.abs(cos) > 1) 296 return 0;
308 return 0; 297 return WebInspector.Geometry.radiansToDegrees(Math.acos(cos));
309 return WebInspector.Geometry.radiansToDegrees(Math.acos(cos));
310 }; 298 };
311 299
312 /** 300 /**
313 * @param {number} deg 301 * @param {number} deg
314 * @return {number} 302 * @return {number}
315 */ 303 */
316 WebInspector.Geometry.degreesToRadians = function(deg) 304 WebInspector.Geometry.degreesToRadians = function(deg) {
317 { 305 return deg * Math.PI / 180;
318 return deg * Math.PI / 180;
319 }; 306 };
320 307
321 /** 308 /**
322 * @param {number} rad 309 * @param {number} rad
323 * @return {number} 310 * @return {number}
324 */ 311 */
325 WebInspector.Geometry.radiansToDegrees = function(rad) 312 WebInspector.Geometry.radiansToDegrees = function(rad) {
326 { 313 return rad * 180 / Math.PI;
327 return rad * 180 / Math.PI;
328 }; 314 };
329 315
330 /** 316 /**
331 * @param {!CSSMatrix} matrix 317 * @param {!CSSMatrix} matrix
332 * @param {!Array.<number>} points 318 * @param {!Array.<number>} points
333 * @param {{minX: number, maxX: number, minY: number, maxY: number}=} aggregateB ounds 319 * @param {{minX: number, maxX: number, minY: number, maxY: number}=} aggregateB ounds
334 * @return {!{minX: number, maxX: number, minY: number, maxY: number}} 320 * @return {!{minX: number, maxX: number, minY: number, maxY: number}}
335 */ 321 */
336 WebInspector.Geometry.boundsForTransformedPoints = function(matrix, points, aggr egateBounds) 322 WebInspector.Geometry.boundsForTransformedPoints = function(matrix, points, aggr egateBounds) {
337 { 323 if (!aggregateBounds)
338 if (!aggregateBounds) 324 aggregateBounds = {minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -I nfinity};
339 aggregateBounds = {minX: Infinity, maxX: -Infinity, minY: Infinity, maxY : -Infinity}; 325 if (points.length % 3)
340 if (points.length % 3) 326 console.assert('Invalid size of points array');
341 console.assert("Invalid size of points array"); 327 for (var p = 0; p < points.length; p += 3) {
342 for (var p = 0; p < points.length; p += 3) { 328 var vector = new WebInspector.Geometry.Vector(points[p], points[p + 1], poin ts[p + 2]);
343 var vector = new WebInspector.Geometry.Vector(points[p], points[p + 1], points[p + 2]); 329 vector = WebInspector.Geometry.multiplyVectorByMatrixAndNormalize(vector, ma trix);
344 vector = WebInspector.Geometry.multiplyVectorByMatrixAndNormalize(vector , matrix); 330 aggregateBounds.minX = Math.min(aggregateBounds.minX, vector.x);
345 aggregateBounds.minX = Math.min(aggregateBounds.minX, vector.x); 331 aggregateBounds.maxX = Math.max(aggregateBounds.maxX, vector.x);
346 aggregateBounds.maxX = Math.max(aggregateBounds.maxX, vector.x); 332 aggregateBounds.minY = Math.min(aggregateBounds.minY, vector.y);
347 aggregateBounds.minY = Math.min(aggregateBounds.minY, vector.y); 333 aggregateBounds.maxY = Math.max(aggregateBounds.maxY, vector.y);
348 aggregateBounds.maxY = Math.max(aggregateBounds.maxY, vector.y); 334 }
349 } 335 return aggregateBounds;
350 return aggregateBounds;
351 }; 336 };
352 337
353 /** 338 /**
354 * @constructor 339 * @unrestricted
355 * @param {number} width
356 * @param {number} height
357 */ 340 */
358 function Size(width, height) 341 var Size = class {
359 { 342 /**
343 * @param {number} width
344 * @param {number} height
345 */
346 constructor(width, height) {
360 this.width = width; 347 this.width = width;
361 this.height = height; 348 this.height = height;
362 } 349 }
350 };
363 351
364 /** 352 /**
365 * @param {?Size} size 353 * @param {?Size} size
366 * @return {boolean} 354 * @return {boolean}
367 */ 355 */
368 Size.prototype.isEqual = function(size) 356 Size.prototype.isEqual = function(size) {
369 { 357 return !!size && this.width === size.width && this.height === size.height;
370 return !!size && this.width === size.width && this.height === size.height;
371 }; 358 };
372 359
373 /** 360 /**
374 * @param {!Size|number} size 361 * @param {!Size|number} size
375 * @return {!Size} 362 * @return {!Size}
376 */ 363 */
377 Size.prototype.widthToMax = function(size) 364 Size.prototype.widthToMax = function(size) {
378 { 365 return new Size(Math.max(this.width, (typeof size === 'number' ? size : size.w idth)), this.height);
379 return new Size(Math.max(this.width, (typeof size === "number" ? size : size .width)), this.height);
380 }; 366 };
381 367
382 /** 368 /**
383 * @param {!Size|number} size 369 * @param {!Size|number} size
384 * @return {!Size} 370 * @return {!Size}
385 */ 371 */
386 Size.prototype.addWidth = function(size) 372 Size.prototype.addWidth = function(size) {
387 { 373 return new Size(this.width + (typeof size === 'number' ? size : size.width), t his.height);
388 return new Size(this.width + (typeof size === "number" ? size : size.width), this.height);
389 }; 374 };
390 375
391 /** 376 /**
392 * @param {!Size|number} size 377 * @param {!Size|number} size
393 * @return {!Size} 378 * @return {!Size}
394 */ 379 */
395 Size.prototype.heightToMax = function(size) 380 Size.prototype.heightToMax = function(size) {
396 { 381 return new Size(this.width, Math.max(this.height, (typeof size === 'number' ? size : size.height)));
397 return new Size(this.width, Math.max(this.height, (typeof size === "number" ? size : size.height)));
398 }; 382 };
399 383
400 /** 384 /**
401 * @param {!Size|number} size 385 * @param {!Size|number} size
402 * @return {!Size} 386 * @return {!Size}
403 */ 387 */
404 Size.prototype.addHeight = function(size) 388 Size.prototype.addHeight = function(size) {
405 { 389 return new Size(this.width, this.height + (typeof size === 'number' ? size : s ize.height));
406 return new Size(this.width, this.height + (typeof size === "number" ? size : size.height));
407 }; 390 };
408 391
409
410 /** 392 /**
411 * @constructor 393 * @unrestricted
412 * @param {number} left
413 * @param {number} top
414 * @param {number} right
415 * @param {number} bottom
416 */ 394 */
417 function Insets(left, top, right, bottom) 395 var Insets = class {
418 { 396 /**
397 * @param {number} left
398 * @param {number} top
399 * @param {number} right
400 * @param {number} bottom
401 */
402 constructor(left, top, right, bottom) {
419 this.left = left; 403 this.left = left;
420 this.top = top; 404 this.top = top;
421 this.right = right; 405 this.right = right;
422 this.bottom = bottom; 406 this.bottom = bottom;
423 } 407 }
424 408
425 Insets.prototype = { 409 /**
426 /** 410 * @param {?Insets} insets
427 * @param {?Insets} insets 411 * @return {boolean}
428 * @return {boolean} 412 */
429 */ 413 isEqual(insets) {
430 isEqual: function(insets) 414 return !!insets && this.left === insets.left && this.top === insets.top && t his.right === insets.right &&
431 { 415 this.bottom === insets.bottom;
432 return !!insets && this.left === insets.left && this.top === insets.top && this.right === insets.right && this.bottom === insets.bottom; 416 }
433 }
434 }; 417 };
435 418
436
437 /** 419 /**
438 * @constructor 420 * @unrestricted
439 * @param {number} left
440 * @param {number} top
441 * @param {number} width
442 * @param {number} height
443 */ 421 */
444 WebInspector.Rect = function(left, top, width, height) 422 WebInspector.Rect = class {
445 { 423 /**
424 * @param {number} left
425 * @param {number} top
426 * @param {number} width
427 * @param {number} height
428 */
429 constructor(left, top, width, height) {
446 this.left = left; 430 this.left = left;
447 this.top = top; 431 this.top = top;
448 this.width = width; 432 this.width = width;
449 this.height = height; 433 this.height = height;
434 }
435
436 /**
437 * @param {?WebInspector.Rect} rect
438 * @return {boolean}
439 */
440 isEqual(rect) {
441 return !!rect && this.left === rect.left && this.top === rect.top && this.wi dth === rect.width &&
442 this.height === rect.height;
443 }
444
445 /**
446 * @param {number} scale
447 * @return {!WebInspector.Rect}
448 */
449 scale(scale) {
450 return new WebInspector.Rect(this.left * scale, this.top * scale, this.width * scale, this.height * scale);
451 }
452
453 /**
454 * @return {!Size}
455 */
456 size() {
457 return new Size(this.width, this.height);
458 }
450 }; 459 };
451 460
452 WebInspector.Rect.prototype = {
453 /**
454 * @param {?WebInspector.Rect} rect
455 * @return {boolean}
456 */
457 isEqual: function(rect)
458 {
459 return !!rect && this.left === rect.left && this.top === rect.top && thi s.width === rect.width && this.height === rect.height;
460 },
461
462 /**
463 * @param {number} scale
464 * @return {!WebInspector.Rect}
465 */
466 scale: function(scale)
467 {
468 return new WebInspector.Rect(this.left * scale, this.top * scale, this.w idth * scale, this.height * scale);
469 },
470
471 /**
472 * @return {!Size}
473 */
474 size: function()
475 {
476 return new Size(this.width, this.height);
477 }
478 };
479
480
481 /** 461 /**
482 * @constructor 462 * @unrestricted
483 * @param {!Size=} minimum
484 * @param {?Size=} preferred
485 */ 463 */
486 function Constraints(minimum, preferred) 464 var Constraints = class {
487 { 465 /**
466 * @param {!Size=} minimum
467 * @param {?Size=} preferred
468 */
469 constructor(minimum, preferred) {
488 /** 470 /**
489 * @type {!Size} 471 * @type {!Size}
490 */ 472 */
491 this.minimum = minimum || new Size(0, 0); 473 this.minimum = minimum || new Size(0, 0);
492 474
493 /** 475 /**
494 * @type {!Size} 476 * @type {!Size}
495 */ 477 */
496 this.preferred = preferred || this.minimum; 478 this.preferred = preferred || this.minimum;
497 479
498 if (this.minimum.width > this.preferred.width || this.minimum.height > this. preferred.height) 480 if (this.minimum.width > this.preferred.width || this.minimum.height > this. preferred.height)
499 throw new Error("Minimum size is greater than preferred."); 481 throw new Error('Minimum size is greater than preferred.');
500 } 482 }
483 };
501 484
502 /** 485 /**
503 * @param {?Constraints} constraints 486 * @param {?Constraints} constraints
504 * @return {boolean} 487 * @return {boolean}
505 */ 488 */
506 Constraints.prototype.isEqual = function(constraints) 489 Constraints.prototype.isEqual = function(constraints) {
507 { 490 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pref erred.isEqual(constraints.preferred);
508 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pr eferred.isEqual(constraints.preferred);
509 }; 491 };
510 492
511 /** 493 /**
512 * @param {!Constraints|number} value 494 * @param {!Constraints|number} value
513 * @return {!Constraints} 495 * @return {!Constraints}
514 */ 496 */
515 Constraints.prototype.widthToMax = function(value) 497 Constraints.prototype.widthToMax = function(value) {
516 { 498 if (typeof value === 'number')
517 if (typeof value === "number") 499 return new Constraints(this.minimum.widthToMax(value), this.preferred.widthT oMax(value));
518 return new Constraints(this.minimum.widthToMax(value), this.preferred.wi dthToMax(value)); 500 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferred. widthToMax(value.preferred));
519 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferre d.widthToMax(value.preferred));
520 }; 501 };
521 502
522 /** 503 /**
523 * @param {!Constraints|number} value 504 * @param {!Constraints|number} value
524 * @return {!Constraints} 505 * @return {!Constraints}
525 */ 506 */
526 Constraints.prototype.addWidth = function(value) 507 Constraints.prototype.addWidth = function(value) {
527 { 508 if (typeof value === 'number')
528 if (typeof value === "number") 509 return new Constraints(this.minimum.addWidth(value), this.preferred.addWidth (value));
529 return new Constraints(this.minimum.addWidth(value), this.preferred.addW idth(value)); 510 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.ad dWidth(value.preferred));
530 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred. addWidth(value.preferred));
531 }; 511 };
532 512
533 /** 513 /**
534 * @param {!Constraints|number} value 514 * @param {!Constraints|number} value
535 * @return {!Constraints} 515 * @return {!Constraints}
536 */ 516 */
537 Constraints.prototype.heightToMax = function(value) 517 Constraints.prototype.heightToMax = function(value) {
538 { 518 if (typeof value === 'number')
539 if (typeof value === "number") 519 return new Constraints(this.minimum.heightToMax(value), this.preferred.heigh tToMax(value));
540 return new Constraints(this.minimum.heightToMax(value), this.preferred.h eightToMax(value)); 520 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferred .heightToMax(value.preferred));
541 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferr ed.heightToMax(value.preferred));
542 }; 521 };
543 522
544 /** 523 /**
545 * @param {!Constraints|number} value 524 * @param {!Constraints|number} value
546 * @return {!Constraints} 525 * @return {!Constraints}
547 */ 526 */
548 Constraints.prototype.addHeight = function(value) 527 Constraints.prototype.addHeight = function(value) {
549 { 528 if (typeof value === 'number')
550 if (typeof value === "number") 529 return new Constraints(this.minimum.addHeight(value), this.preferred.addHeig ht(value));
551 return new Constraints(this.minimum.addHeight(value), this.preferred.add Height(value)); 530 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred.a ddHeight(value.preferred));
552 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred .addHeight(value.preferred));
553 }; 531 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698