| OLD | NEW |
| 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 Common.Geometry = {}; | 30 UI.Geometry = {}; |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * @type {number} | 33 * @type {number} |
| 34 */ | 34 */ |
| 35 Common.Geometry._Eps = 1e-5; | 35 UI.Geometry._Eps = 1e-5; |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * @unrestricted | 38 * @unrestricted |
| 39 */ | 39 */ |
| 40 Common.Geometry.Vector = class { | 40 UI.Geometry.Vector = class { |
| 41 /** | 41 /** |
| 42 * @param {number} x | 42 * @param {number} x |
| 43 * @param {number} y | 43 * @param {number} y |
| 44 * @param {number} z | 44 * @param {number} z |
| 45 */ | 45 */ |
| 46 constructor(x, y, z) { | 46 constructor(x, y, z) { |
| 47 this.x = x; | 47 this.x = x; |
| 48 this.y = y; | 48 this.y = y; |
| 49 this.z = z; | 49 this.z = z; |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @return {number} | 53 * @return {number} |
| 54 */ | 54 */ |
| 55 length() { | 55 length() { |
| 56 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); | 56 return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); |
| 57 } | 57 } |
| 58 | 58 |
| 59 normalize() { | 59 normalize() { |
| 60 var length = this.length(); | 60 var length = this.length(); |
| 61 if (length <= Common.Geometry._Eps) | 61 if (length <= UI.Geometry._Eps) |
| 62 return; | 62 return; |
| 63 | 63 |
| 64 this.x /= length; | 64 this.x /= length; |
| 65 this.y /= length; | 65 this.y /= length; |
| 66 this.z /= length; | 66 this.z /= length; |
| 67 } | 67 } |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 /** | 70 /** |
| 71 * @unrestricted | 71 * @unrestricted |
| 72 */ | 72 */ |
| 73 Common.Geometry.Point = class { | 73 UI.Geometry.Point = class { |
| 74 /** | 74 /** |
| 75 * @param {number} x | 75 * @param {number} x |
| 76 * @param {number} y | 76 * @param {number} y |
| 77 */ | 77 */ |
| 78 constructor(x, y) { | 78 constructor(x, y) { |
| 79 this.x = x; | 79 this.x = x; |
| 80 this.y = y; | 80 this.y = y; |
| 81 } | 81 } |
| 82 | 82 |
| 83 /** | 83 /** |
| 84 * @param {!Common.Geometry.Point} p | 84 * @param {!UI.Geometry.Point} p |
| 85 * @return {number} | 85 * @return {number} |
| 86 */ | 86 */ |
| 87 distanceTo(p) { | 87 distanceTo(p) { |
| 88 return Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2)); | 88 return Math.sqrt(Math.pow(p.x - this.x, 2) + Math.pow(p.y - this.y, 2)); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * @param {!Common.Geometry.Point} line | 92 * @param {!UI.Geometry.Point} line |
| 93 * @return {!Common.Geometry.Point} | 93 * @return {!UI.Geometry.Point} |
| 94 */ | 94 */ |
| 95 projectOn(line) { | 95 projectOn(line) { |
| 96 if (line.x === 0 && line.y === 0) | 96 if (line.x === 0 && line.y === 0) |
| 97 return new Common.Geometry.Point(0, 0); | 97 return new UI.Geometry.Point(0, 0); |
| 98 return line.scale((this.x * line.x + this.y * line.y) / (Math.pow(line.x, 2)
+ Math.pow(line.y, 2))); | 98 return line.scale((this.x * line.x + this.y * line.y) / (Math.pow(line.x, 2)
+ Math.pow(line.y, 2))); |
| 99 } | 99 } |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * @param {number} scalar | 102 * @param {number} scalar |
| 103 * @return {!Common.Geometry.Point} | 103 * @return {!UI.Geometry.Point} |
| 104 */ | 104 */ |
| 105 scale(scalar) { | 105 scale(scalar) { |
| 106 return new Common.Geometry.Point(this.x * scalar, this.y * scalar); | 106 return new UI.Geometry.Point(this.x * scalar, this.y * scalar); |
| 107 } | 107 } |
| 108 | 108 |
| 109 /** | 109 /** |
| 110 * @override | 110 * @override |
| 111 * @return {string} | 111 * @return {string} |
| 112 */ | 112 */ |
| 113 toString() { | 113 toString() { |
| 114 return Math.round(this.x * 100) / 100 + ', ' + Math.round(this.y * 100) / 10
0; | 114 return Math.round(this.x * 100) / 100 + ', ' + Math.round(this.y * 100) / 10
0; |
| 115 } | 115 } |
| 116 }; | 116 }; |
| 117 | 117 |
| 118 /** | 118 /** |
| 119 * @unrestricted | 119 * @unrestricted |
| 120 */ | 120 */ |
| 121 Common.Geometry.CubicBezier = class { | 121 UI.Geometry.CubicBezier = class { |
| 122 /** | 122 /** |
| 123 * @param {!Common.Geometry.Point} point1 | 123 * @param {!UI.Geometry.Point} point1 |
| 124 * @param {!Common.Geometry.Point} point2 | 124 * @param {!UI.Geometry.Point} point2 |
| 125 */ | 125 */ |
| 126 constructor(point1, point2) { | 126 constructor(point1, point2) { |
| 127 this.controlPoints = [point1, point2]; | 127 this.controlPoints = [point1, point2]; |
| 128 } | 128 } |
| 129 | 129 |
| 130 /** | 130 /** |
| 131 * @param {string} text | 131 * @param {string} text |
| 132 * @return {?Common.Geometry.CubicBezier} | 132 * @return {?UI.Geometry.CubicBezier} |
| 133 */ | 133 */ |
| 134 static parse(text) { | 134 static parse(text) { |
| 135 var keywordValues = Common.Geometry.CubicBezier.KeywordValues; | 135 var keywordValues = UI.Geometry.CubicBezier.KeywordValues; |
| 136 var value = text.toLowerCase().replace(/\s+/g, ''); | 136 var value = text.toLowerCase().replace(/\s+/g, ''); |
| 137 if (Object.keys(keywordValues).indexOf(value) !== -1) | 137 if (Object.keys(keywordValues).indexOf(value) !== -1) |
| 138 return Common.Geometry.CubicBezier.parse(keywordValues[value]); | 138 return UI.Geometry.CubicBezier.parse(keywordValues[value]); |
| 139 var bezierRegex = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^,]+)\)$/; | 139 var bezierRegex = /^cubic-bezier\(([^,]+),([^,]+),([^,]+),([^,]+)\)$/; |
| 140 var match = value.match(bezierRegex); | 140 var match = value.match(bezierRegex); |
| 141 if (match) { | 141 if (match) { |
| 142 var control1 = new Common.Geometry.Point(parseFloat(match[1]), parseFloat(
match[2])); | 142 var control1 = new UI.Geometry.Point(parseFloat(match[1]), parseFloat(matc
h[2])); |
| 143 var control2 = new Common.Geometry.Point(parseFloat(match[3]), parseFloat(
match[4])); | 143 var control2 = new UI.Geometry.Point(parseFloat(match[3]), parseFloat(matc
h[4])); |
| 144 return new Common.Geometry.CubicBezier(control1, control2); | 144 return new UI.Geometry.CubicBezier(control1, control2); |
| 145 } | 145 } |
| 146 return null; | 146 return null; |
| 147 } | 147 } |
| 148 | 148 |
| 149 /** | 149 /** |
| 150 * @param {number} t | 150 * @param {number} t |
| 151 * @return {!Common.Geometry.Point} | 151 * @return {!UI.Geometry.Point} |
| 152 */ | 152 */ |
| 153 evaluateAt(t) { | 153 evaluateAt(t) { |
| 154 /** | 154 /** |
| 155 * @param {number} v1 | 155 * @param {number} v1 |
| 156 * @param {number} v2 | 156 * @param {number} v2 |
| 157 * @param {number} t | 157 * @param {number} t |
| 158 */ | 158 */ |
| 159 function evaluate(v1, v2, t) { | 159 function evaluate(v1, v2, t) { |
| 160 return 3 * (1 - t) * (1 - t) * t * v1 + 3 * (1 - t) * t * t * v2 + Math.po
w(t, 3); | 160 return 3 * (1 - t) * (1 - t) * t * v1 + 3 * (1 - t) * t * t * v2 + Math.po
w(t, 3); |
| 161 } | 161 } |
| 162 | 162 |
| 163 var x = evaluate(this.controlPoints[0].x, this.controlPoints[1].x, t); | 163 var x = evaluate(this.controlPoints[0].x, this.controlPoints[1].x, t); |
| 164 var y = evaluate(this.controlPoints[0].y, this.controlPoints[1].y, t); | 164 var y = evaluate(this.controlPoints[0].y, this.controlPoints[1].y, t); |
| 165 return new Common.Geometry.Point(x, y); | 165 return new UI.Geometry.Point(x, y); |
| 166 } | 166 } |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * @return {string} | 169 * @return {string} |
| 170 */ | 170 */ |
| 171 asCSSText() { | 171 asCSSText() { |
| 172 var raw = 'cubic-bezier(' + this.controlPoints.join(', ') + ')'; | 172 var raw = 'cubic-bezier(' + this.controlPoints.join(', ') + ')'; |
| 173 var keywordValues = Common.Geometry.CubicBezier.KeywordValues; | 173 var keywordValues = UI.Geometry.CubicBezier.KeywordValues; |
| 174 for (var keyword in keywordValues) { | 174 for (var keyword in keywordValues) { |
| 175 if (raw === keywordValues[keyword]) | 175 if (raw === keywordValues[keyword]) |
| 176 return keyword; | 176 return keyword; |
| 177 } | 177 } |
| 178 return raw; | 178 return raw; |
| 179 } | 179 } |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 /** @type {!RegExp} */ | 182 /** @type {!RegExp} */ |
| 183 Common.Geometry.CubicBezier.Regex = /((cubic-bezier\([^)]+\))|\b(linear|ease-in-
out|ease-in|ease-out|ease)\b)/g; | 183 UI.Geometry.CubicBezier.Regex = /((cubic-bezier\([^)]+\))|\b(linear|ease-in-out|
ease-in|ease-out|ease)\b)/g; |
| 184 | 184 |
| 185 Common.Geometry.CubicBezier.KeywordValues = { | 185 UI.Geometry.CubicBezier.KeywordValues = { |
| 186 'linear': 'cubic-bezier(0, 0, 1, 1)', | 186 'linear': 'cubic-bezier(0, 0, 1, 1)', |
| 187 'ease': 'cubic-bezier(0.25, 0.1, 0.25, 1)', | 187 'ease': 'cubic-bezier(0.25, 0.1, 0.25, 1)', |
| 188 'ease-in': 'cubic-bezier(0.42, 0, 1, 1)', | 188 'ease-in': 'cubic-bezier(0.42, 0, 1, 1)', |
| 189 'ease-in-out': 'cubic-bezier(0.42, 0, 0.58, 1)', | 189 'ease-in-out': 'cubic-bezier(0.42, 0, 0.58, 1)', |
| 190 'ease-out': 'cubic-bezier(0, 0, 0.58, 1)' | 190 'ease-out': 'cubic-bezier(0, 0, 0.58, 1)' |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * @unrestricted | 195 * @unrestricted |
| 196 */ | 196 */ |
| 197 Common.Geometry.EulerAngles = class { | 197 UI.Geometry.EulerAngles = class { |
| 198 /** | 198 /** |
| 199 * @param {number} alpha | 199 * @param {number} alpha |
| 200 * @param {number} beta | 200 * @param {number} beta |
| 201 * @param {number} gamma | 201 * @param {number} gamma |
| 202 */ | 202 */ |
| 203 constructor(alpha, beta, gamma) { | 203 constructor(alpha, beta, gamma) { |
| 204 this.alpha = alpha; | 204 this.alpha = alpha; |
| 205 this.beta = beta; | 205 this.beta = beta; |
| 206 this.gamma = gamma; | 206 this.gamma = gamma; |
| 207 } | 207 } |
| 208 | 208 |
| 209 /** | 209 /** |
| 210 * @param {!CSSMatrix} rotationMatrix | 210 * @param {!CSSMatrix} rotationMatrix |
| 211 * @return {!Common.Geometry.EulerAngles} | 211 * @return {!UI.Geometry.EulerAngles} |
| 212 */ | 212 */ |
| 213 static fromRotationMatrix(rotationMatrix) { | 213 static fromRotationMatrix(rotationMatrix) { |
| 214 var beta = Math.atan2(rotationMatrix.m23, rotationMatrix.m33); | 214 var beta = Math.atan2(rotationMatrix.m23, rotationMatrix.m33); |
| 215 var gamma = Math.atan2( | 215 var gamma = Math.atan2( |
| 216 -rotationMatrix.m13, | 216 -rotationMatrix.m13, |
| 217 Math.sqrt(rotationMatrix.m11 * rotationMatrix.m11 + rotationMatrix.m12 *
rotationMatrix.m12)); | 217 Math.sqrt(rotationMatrix.m11 * rotationMatrix.m11 + rotationMatrix.m12 *
rotationMatrix.m12)); |
| 218 var alpha = Math.atan2(rotationMatrix.m12, rotationMatrix.m11); | 218 var alpha = Math.atan2(rotationMatrix.m12, rotationMatrix.m11); |
| 219 return new Common.Geometry.EulerAngles( | 219 return new UI.Geometry.EulerAngles( |
| 220 Common.Geometry.radiansToDegrees(alpha), Common.Geometry.radiansToDegree
s(beta), | 220 UI.Geometry.radiansToDegrees(alpha), UI.Geometry.radiansToDegrees(beta),
UI.Geometry.radiansToDegrees(gamma)); |
| 221 Common.Geometry.radiansToDegrees(gamma)); | |
| 222 } | 221 } |
| 223 | 222 |
| 224 /** | 223 /** |
| 225 * @return {string} | 224 * @return {string} |
| 226 */ | 225 */ |
| 227 toRotate3DString() { | 226 toRotate3DString() { |
| 228 var gammaAxisY = -Math.sin(Common.Geometry.degreesToRadians(this.beta)); | 227 var gammaAxisY = -Math.sin(UI.Geometry.degreesToRadians(this.beta)); |
| 229 var gammaAxisZ = Math.cos(Common.Geometry.degreesToRadians(this.beta)); | 228 var gammaAxisZ = Math.cos(UI.Geometry.degreesToRadians(this.beta)); |
| 230 var axis = {alpha: [0, 1, 0], beta: [-1, 0, 0], gamma: [0, gammaAxisY, gamma
AxisZ]}; | 229 var axis = {alpha: [0, 1, 0], beta: [-1, 0, 0], gamma: [0, gammaAxisY, gamma
AxisZ]}; |
| 231 return 'rotate3d(' + axis.alpha.join(',') + ',' + this.alpha + 'deg) ' + | 230 return 'rotate3d(' + axis.alpha.join(',') + ',' + this.alpha + 'deg) ' + |
| 232 'rotate3d(' + axis.beta.join(',') + ',' + this.beta + 'deg) ' + | 231 'rotate3d(' + axis.beta.join(',') + ',' + this.beta + 'deg) ' + |
| 233 'rotate3d(' + axis.gamma.join(',') + ',' + this.gamma + 'deg)'; | 232 'rotate3d(' + axis.gamma.join(',') + ',' + this.gamma + 'deg)'; |
| 234 } | 233 } |
| 235 }; | 234 }; |
| 236 | 235 |
| 237 | 236 |
| 238 /** | 237 /** |
| 239 * @param {!Common.Geometry.Vector} u | 238 * @param {!UI.Geometry.Vector} u |
| 240 * @param {!Common.Geometry.Vector} v | 239 * @param {!UI.Geometry.Vector} v |
| 241 * @return {number} | 240 * @return {number} |
| 242 */ | 241 */ |
| 243 Common.Geometry.scalarProduct = function(u, v) { | 242 UI.Geometry.scalarProduct = function(u, v) { |
| 244 return u.x * v.x + u.y * v.y + u.z * v.z; | 243 return u.x * v.x + u.y * v.y + u.z * v.z; |
| 245 }; | 244 }; |
| 246 | 245 |
| 247 /** | 246 /** |
| 248 * @param {!Common.Geometry.Vector} u | 247 * @param {!UI.Geometry.Vector} u |
| 249 * @param {!Common.Geometry.Vector} v | 248 * @param {!UI.Geometry.Vector} v |
| 250 * @return {!Common.Geometry.Vector} | 249 * @return {!UI.Geometry.Vector} |
| 251 */ | 250 */ |
| 252 Common.Geometry.crossProduct = function(u, v) { | 251 UI.Geometry.crossProduct = function(u, v) { |
| 253 var x = u.y * v.z - u.z * v.y; | 252 var x = u.y * v.z - u.z * v.y; |
| 254 var y = u.z * v.x - u.x * v.z; | 253 var y = u.z * v.x - u.x * v.z; |
| 255 var z = u.x * v.y - u.y * v.x; | 254 var z = u.x * v.y - u.y * v.x; |
| 256 return new Common.Geometry.Vector(x, y, z); | 255 return new UI.Geometry.Vector(x, y, z); |
| 257 }; | 256 }; |
| 258 | 257 |
| 259 /** | 258 /** |
| 260 * @param {!Common.Geometry.Vector} u | 259 * @param {!UI.Geometry.Vector} u |
| 261 * @param {!Common.Geometry.Vector} v | 260 * @param {!UI.Geometry.Vector} v |
| 262 * @return {!Common.Geometry.Vector} | 261 * @return {!UI.Geometry.Vector} |
| 263 */ | 262 */ |
| 264 Common.Geometry.subtract = function(u, v) { | 263 UI.Geometry.subtract = function(u, v) { |
| 265 var x = u.x - v.x; | 264 var x = u.x - v.x; |
| 266 var y = u.y - v.y; | 265 var y = u.y - v.y; |
| 267 var z = u.z - v.z; | 266 var z = u.z - v.z; |
| 268 return new Common.Geometry.Vector(x, y, z); | 267 return new UI.Geometry.Vector(x, y, z); |
| 269 }; | 268 }; |
| 270 | 269 |
| 271 /** | 270 /** |
| 272 * @param {!Common.Geometry.Vector} v | 271 * @param {!UI.Geometry.Vector} v |
| 273 * @param {!CSSMatrix} m | 272 * @param {!CSSMatrix} m |
| 274 * @return {!Common.Geometry.Vector} | 273 * @return {!UI.Geometry.Vector} |
| 275 */ | 274 */ |
| 276 Common.Geometry.multiplyVectorByMatrixAndNormalize = function(v, m) { | 275 UI.Geometry.multiplyVectorByMatrixAndNormalize = function(v, m) { |
| 277 var t = v.x * m.m14 + v.y * m.m24 + v.z * m.m34 + m.m44; | 276 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; | 277 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; | 278 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; | 279 var z = (v.x * m.m13 + v.y * m.m23 + v.z * m.m33 + m.m43) / t; |
| 281 return new Common.Geometry.Vector(x, y, z); | 280 return new UI.Geometry.Vector(x, y, z); |
| 282 }; | 281 }; |
| 283 | 282 |
| 284 /** | 283 /** |
| 285 * @param {!Common.Geometry.Vector} u | 284 * @param {!UI.Geometry.Vector} u |
| 286 * @param {!Common.Geometry.Vector} v | 285 * @param {!UI.Geometry.Vector} v |
| 287 * @return {number} | 286 * @return {number} |
| 288 */ | 287 */ |
| 289 Common.Geometry.calculateAngle = function(u, v) { | 288 UI.Geometry.calculateAngle = function(u, v) { |
| 290 var uLength = u.length(); | 289 var uLength = u.length(); |
| 291 var vLength = v.length(); | 290 var vLength = v.length(); |
| 292 if (uLength <= Common.Geometry._Eps || vLength <= Common.Geometry._Eps) | 291 if (uLength <= UI.Geometry._Eps || vLength <= UI.Geometry._Eps) |
| 293 return 0; | 292 return 0; |
| 294 var cos = Common.Geometry.scalarProduct(u, v) / uLength / vLength; | 293 var cos = UI.Geometry.scalarProduct(u, v) / uLength / vLength; |
| 295 if (Math.abs(cos) > 1) | 294 if (Math.abs(cos) > 1) |
| 296 return 0; | 295 return 0; |
| 297 return Common.Geometry.radiansToDegrees(Math.acos(cos)); | 296 return UI.Geometry.radiansToDegrees(Math.acos(cos)); |
| 298 }; | 297 }; |
| 299 | 298 |
| 300 /** | 299 /** |
| 301 * @param {number} deg | 300 * @param {number} deg |
| 302 * @return {number} | 301 * @return {number} |
| 303 */ | 302 */ |
| 304 Common.Geometry.degreesToRadians = function(deg) { | 303 UI.Geometry.degreesToRadians = function(deg) { |
| 305 return deg * Math.PI / 180; | 304 return deg * Math.PI / 180; |
| 306 }; | 305 }; |
| 307 | 306 |
| 308 /** | 307 /** |
| 309 * @param {number} rad | 308 * @param {number} rad |
| 310 * @return {number} | 309 * @return {number} |
| 311 */ | 310 */ |
| 312 Common.Geometry.radiansToDegrees = function(rad) { | 311 UI.Geometry.radiansToDegrees = function(rad) { |
| 313 return rad * 180 / Math.PI; | 312 return rad * 180 / Math.PI; |
| 314 }; | 313 }; |
| 315 | 314 |
| 316 /** | 315 /** |
| 317 * @param {!CSSMatrix} matrix | 316 * @param {!CSSMatrix} matrix |
| 318 * @param {!Array.<number>} points | 317 * @param {!Array.<number>} points |
| 319 * @param {{minX: number, maxX: number, minY: number, maxY: number}=} aggregateB
ounds | 318 * @param {{minX: number, maxX: number, minY: number, maxY: number}=} aggregateB
ounds |
| 320 * @return {!{minX: number, maxX: number, minY: number, maxY: number}} | 319 * @return {!{minX: number, maxX: number, minY: number, maxY: number}} |
| 321 */ | 320 */ |
| 322 Common.Geometry.boundsForTransformedPoints = function(matrix, points, aggregateB
ounds) { | 321 UI.Geometry.boundsForTransformedPoints = function(matrix, points, aggregateBound
s) { |
| 323 if (!aggregateBounds) | 322 if (!aggregateBounds) |
| 324 aggregateBounds = {minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -I
nfinity}; | 323 aggregateBounds = {minX: Infinity, maxX: -Infinity, minY: Infinity, maxY: -I
nfinity}; |
| 325 if (points.length % 3) | 324 if (points.length % 3) |
| 326 console.assert('Invalid size of points array'); | 325 console.assert('Invalid size of points array'); |
| 327 for (var p = 0; p < points.length; p += 3) { | 326 for (var p = 0; p < points.length; p += 3) { |
| 328 var vector = new Common.Geometry.Vector(points[p], points[p + 1], points[p +
2]); | 327 var vector = new UI.Geometry.Vector(points[p], points[p + 1], points[p + 2])
; |
| 329 vector = Common.Geometry.multiplyVectorByMatrixAndNormalize(vector, matrix); | 328 vector = UI.Geometry.multiplyVectorByMatrixAndNormalize(vector, matrix); |
| 330 aggregateBounds.minX = Math.min(aggregateBounds.minX, vector.x); | 329 aggregateBounds.minX = Math.min(aggregateBounds.minX, vector.x); |
| 331 aggregateBounds.maxX = Math.max(aggregateBounds.maxX, vector.x); | 330 aggregateBounds.maxX = Math.max(aggregateBounds.maxX, vector.x); |
| 332 aggregateBounds.minY = Math.min(aggregateBounds.minY, vector.y); | 331 aggregateBounds.minY = Math.min(aggregateBounds.minY, vector.y); |
| 333 aggregateBounds.maxY = Math.max(aggregateBounds.maxY, vector.y); | 332 aggregateBounds.maxY = Math.max(aggregateBounds.maxY, vector.y); |
| 334 } | 333 } |
| 335 return aggregateBounds; | 334 return aggregateBounds; |
| 336 }; | 335 }; |
| 337 | 336 |
| 338 /** | 337 /** |
| 339 * @unrestricted | 338 * @unrestricted |
| 340 */ | 339 */ |
| 341 var Size = class { | 340 UI.Size = class { |
| 342 /** | 341 /** |
| 343 * @param {number} width | 342 * @param {number} width |
| 344 * @param {number} height | 343 * @param {number} height |
| 345 */ | 344 */ |
| 346 constructor(width, height) { | 345 constructor(width, height) { |
| 347 this.width = width; | 346 this.width = width; |
| 348 this.height = height; | 347 this.height = height; |
| 349 } | 348 } |
| 350 }; | 349 }; |
| 351 | 350 |
| 352 /** | 351 /** |
| 353 * @param {?Size} size | 352 * @param {?UI.Size} size |
| 354 * @return {boolean} | 353 * @return {boolean} |
| 355 */ | 354 */ |
| 356 Size.prototype.isEqual = function(size) { | 355 UI.Size.prototype.isEqual = function(size) { |
| 357 return !!size && this.width === size.width && this.height === size.height; | 356 return !!size && this.width === size.width && this.height === size.height; |
| 358 }; | 357 }; |
| 359 | 358 |
| 360 /** | 359 /** |
| 361 * @param {!Size|number} size | 360 * @param {!UI.Size|number} size |
| 362 * @return {!Size} | 361 * @return {!UI.Size} |
| 363 */ | 362 */ |
| 364 Size.prototype.widthToMax = function(size) { | 363 UI.Size.prototype.widthToMax = function(size) { |
| 365 return new Size(Math.max(this.width, (typeof size === 'number' ? size : size.w
idth)), this.height); | 364 return new UI.Size(Math.max(this.width, (typeof size === 'number' ? size : siz
e.width)), this.height); |
| 366 }; | 365 }; |
| 367 | 366 |
| 368 /** | 367 /** |
| 369 * @param {!Size|number} size | 368 * @param {!UI.Size|number} size |
| 370 * @return {!Size} | 369 * @return {!UI.Size} |
| 371 */ | 370 */ |
| 372 Size.prototype.addWidth = function(size) { | 371 UI.Size.prototype.addWidth = function(size) { |
| 373 return new Size(this.width + (typeof size === 'number' ? size : size.width), t
his.height); | 372 return new UI.Size(this.width + (typeof size === 'number' ? size : size.width)
, this.height); |
| 374 }; | 373 }; |
| 375 | 374 |
| 376 /** | 375 /** |
| 377 * @param {!Size|number} size | 376 * @param {!UI.Size|number} size |
| 378 * @return {!Size} | 377 * @return {!UI.Size} |
| 379 */ | 378 */ |
| 380 Size.prototype.heightToMax = function(size) { | 379 UI.Size.prototype.heightToMax = function(size) { |
| 381 return new Size(this.width, Math.max(this.height, (typeof size === 'number' ?
size : size.height))); | 380 return new UI.Size(this.width, Math.max(this.height, (typeof size === 'number'
? size : size.height))); |
| 382 }; | 381 }; |
| 383 | 382 |
| 384 /** | 383 /** |
| 385 * @param {!Size|number} size | 384 * @param {!UI.Size|number} size |
| 386 * @return {!Size} | 385 * @return {!UI.Size} |
| 387 */ | 386 */ |
| 388 Size.prototype.addHeight = function(size) { | 387 UI.Size.prototype.addHeight = function(size) { |
| 389 return new Size(this.width, this.height + (typeof size === 'number' ? size : s
ize.height)); | 388 return new UI.Size(this.width, this.height + (typeof size === 'number' ? size
: size.height)); |
| 390 }; | 389 }; |
| 391 | 390 |
| 392 /** | 391 /** |
| 393 * @unrestricted | 392 * @unrestricted |
| 394 */ | 393 */ |
| 395 var Insets = class { | 394 UI.Insets = class { |
| 396 /** | 395 /** |
| 397 * @param {number} left | 396 * @param {number} left |
| 398 * @param {number} top | 397 * @param {number} top |
| 399 * @param {number} right | 398 * @param {number} right |
| 400 * @param {number} bottom | 399 * @param {number} bottom |
| 401 */ | 400 */ |
| 402 constructor(left, top, right, bottom) { | 401 constructor(left, top, right, bottom) { |
| 403 this.left = left; | 402 this.left = left; |
| 404 this.top = top; | 403 this.top = top; |
| 405 this.right = right; | 404 this.right = right; |
| 406 this.bottom = bottom; | 405 this.bottom = bottom; |
| 407 } | 406 } |
| 408 | 407 |
| 409 /** | 408 /** |
| 410 * @param {?Insets} insets | 409 * @param {?UI.Insets} insets |
| 411 * @return {boolean} | 410 * @return {boolean} |
| 412 */ | 411 */ |
| 413 isEqual(insets) { | 412 isEqual(insets) { |
| 414 return !!insets && this.left === insets.left && this.top === insets.top && t
his.right === insets.right && | 413 return !!insets && this.left === insets.left && this.top === insets.top && t
his.right === insets.right && |
| 415 this.bottom === insets.bottom; | 414 this.bottom === insets.bottom; |
| 416 } | 415 } |
| 417 }; | 416 }; |
| 418 | 417 |
| 419 /** | 418 /** |
| 420 * @unrestricted | 419 * @unrestricted |
| 421 */ | 420 */ |
| 422 Common.Rect = class { | 421 UI.Rect = class { |
| 423 /** | 422 /** |
| 424 * @param {number} left | 423 * @param {number} left |
| 425 * @param {number} top | 424 * @param {number} top |
| 426 * @param {number} width | 425 * @param {number} width |
| 427 * @param {number} height | 426 * @param {number} height |
| 428 */ | 427 */ |
| 429 constructor(left, top, width, height) { | 428 constructor(left, top, width, height) { |
| 430 this.left = left; | 429 this.left = left; |
| 431 this.top = top; | 430 this.top = top; |
| 432 this.width = width; | 431 this.width = width; |
| 433 this.height = height; | 432 this.height = height; |
| 434 } | 433 } |
| 435 | 434 |
| 436 /** | 435 /** |
| 437 * @param {?Common.Rect} rect | 436 * @param {?UI.Rect} rect |
| 438 * @return {boolean} | 437 * @return {boolean} |
| 439 */ | 438 */ |
| 440 isEqual(rect) { | 439 isEqual(rect) { |
| 441 return !!rect && this.left === rect.left && this.top === rect.top && this.wi
dth === rect.width && | 440 return !!rect && this.left === rect.left && this.top === rect.top && this.wi
dth === rect.width && |
| 442 this.height === rect.height; | 441 this.height === rect.height; |
| 443 } | 442 } |
| 444 | 443 |
| 445 /** | 444 /** |
| 446 * @param {number} scale | 445 * @param {number} scale |
| 447 * @return {!Common.Rect} | 446 * @return {!UI.Rect} |
| 448 */ | 447 */ |
| 449 scale(scale) { | 448 scale(scale) { |
| 450 return new Common.Rect(this.left * scale, this.top * scale, this.width * sca
le, this.height * scale); | 449 return new UI.Rect(this.left * scale, this.top * scale, this.width * scale,
this.height * scale); |
| 451 } | 450 } |
| 452 | 451 |
| 453 /** | 452 /** |
| 454 * @return {!Size} | 453 * @return {!UI.Size} |
| 455 */ | 454 */ |
| 456 size() { | 455 size() { |
| 457 return new Size(this.width, this.height); | 456 return new UI.Size(this.width, this.height); |
| 458 } | 457 } |
| 459 }; | 458 }; |
| 460 | 459 |
| 461 /** | 460 /** |
| 462 * @unrestricted | 461 * @unrestricted |
| 463 */ | 462 */ |
| 464 var Constraints = class { | 463 UI.Constraints = class { |
| 465 /** | 464 /** |
| 466 * @param {!Size=} minimum | 465 * @param {!UI.Size=} minimum |
| 467 * @param {?Size=} preferred | 466 * @param {?UI.Size=} preferred |
| 468 */ | 467 */ |
| 469 constructor(minimum, preferred) { | 468 constructor(minimum, preferred) { |
| 470 /** | 469 /** |
| 471 * @type {!Size} | 470 * @type {!UI.Size} |
| 472 */ | 471 */ |
| 473 this.minimum = minimum || new Size(0, 0); | 472 this.minimum = minimum || new UI.Size(0, 0); |
| 474 | 473 |
| 475 /** | 474 /** |
| 476 * @type {!Size} | 475 * @type {!UI.Size} |
| 477 */ | 476 */ |
| 478 this.preferred = preferred || this.minimum; | 477 this.preferred = preferred || this.minimum; |
| 479 | 478 |
| 480 if (this.minimum.width > this.preferred.width || this.minimum.height > this.
preferred.height) | 479 if (this.minimum.width > this.preferred.width || this.minimum.height > this.
preferred.height) |
| 481 throw new Error('Minimum size is greater than preferred.'); | 480 throw new Error('Minimum size is greater than preferred.'); |
| 482 } | 481 } |
| 483 }; | 482 }; |
| 484 | 483 |
| 485 /** | 484 /** |
| 486 * @param {?Constraints} constraints | 485 * @param {?UI.Constraints} constraints |
| 487 * @return {boolean} | 486 * @return {boolean} |
| 488 */ | 487 */ |
| 489 Constraints.prototype.isEqual = function(constraints) { | 488 UI.Constraints.prototype.isEqual = function(constraints) { |
| 490 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pref
erred.isEqual(constraints.preferred); | 489 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pref
erred.isEqual(constraints.preferred); |
| 491 }; | 490 }; |
| 492 | 491 |
| 493 /** | 492 /** |
| 494 * @param {!Constraints|number} value | 493 * @param {!UI.Constraints|number} value |
| 495 * @return {!Constraints} | 494 * @return {!UI.Constraints} |
| 496 */ | 495 */ |
| 497 Constraints.prototype.widthToMax = function(value) { | 496 UI.Constraints.prototype.widthToMax = function(value) { |
| 498 if (typeof value === 'number') | 497 if (typeof value === 'number') |
| 499 return new Constraints(this.minimum.widthToMax(value), this.preferred.widthT
oMax(value)); | 498 return new UI.Constraints(this.minimum.widthToMax(value), this.preferred.wid
thToMax(value)); |
| 500 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferred.
widthToMax(value.preferred)); | 499 return new UI.Constraints(this.minimum.widthToMax(value.minimum), this.preferr
ed.widthToMax(value.preferred)); |
| 501 }; | 500 }; |
| 502 | 501 |
| 503 /** | 502 /** |
| 504 * @param {!Constraints|number} value | 503 * @param {!UI.Constraints|number} value |
| 505 * @return {!Constraints} | 504 * @return {!UI.Constraints} |
| 506 */ | 505 */ |
| 507 Constraints.prototype.addWidth = function(value) { | 506 UI.Constraints.prototype.addWidth = function(value) { |
| 508 if (typeof value === 'number') | 507 if (typeof value === 'number') |
| 509 return new Constraints(this.minimum.addWidth(value), this.preferred.addWidth
(value)); | 508 return new UI.Constraints(this.minimum.addWidth(value), this.preferred.addWi
dth(value)); |
| 510 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.ad
dWidth(value.preferred)); | 509 return new UI.Constraints(this.minimum.addWidth(value.minimum), this.preferred
.addWidth(value.preferred)); |
| 511 }; | 510 }; |
| 512 | 511 |
| 513 /** | 512 /** |
| 514 * @param {!Constraints|number} value | 513 * @param {!UI.Constraints|number} value |
| 515 * @return {!Constraints} | 514 * @return {!UI.Constraints} |
| 516 */ | 515 */ |
| 517 Constraints.prototype.heightToMax = function(value) { | 516 UI.Constraints.prototype.heightToMax = function(value) { |
| 518 if (typeof value === 'number') | 517 if (typeof value === 'number') |
| 519 return new Constraints(this.minimum.heightToMax(value), this.preferred.heigh
tToMax(value)); | 518 return new UI.Constraints(this.minimum.heightToMax(value), this.preferred.he
ightToMax(value)); |
| 520 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferred
.heightToMax(value.preferred)); | 519 return new UI.Constraints(this.minimum.heightToMax(value.minimum), this.prefer
red.heightToMax(value.preferred)); |
| 521 }; | 520 }; |
| 522 | 521 |
| 523 /** | 522 /** |
| 524 * @param {!Constraints|number} value | 523 * @param {!UI.Constraints|number} value |
| 525 * @return {!Constraints} | 524 * @return {!UI.Constraints} |
| 526 */ | 525 */ |
| 527 Constraints.prototype.addHeight = function(value) { | 526 UI.Constraints.prototype.addHeight = function(value) { |
| 528 if (typeof value === 'number') | 527 if (typeof value === 'number') |
| 529 return new Constraints(this.minimum.addHeight(value), this.preferred.addHeig
ht(value)); | 528 return new UI.Constraints(this.minimum.addHeight(value), this.preferred.addH
eight(value)); |
| 530 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred.a
ddHeight(value.preferred)); | 529 return new UI.Constraints(this.minimum.addHeight(value.minimum), this.preferre
d.addHeight(value.preferred)); |
| 531 }; | 530 }; |
| OLD | NEW |