OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright (c) 2014 The Chromium Authors. All rights reserved. | 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/base/base.html"> | 8 <link rel="import" href="/tracing/base/base.html"> |
9 <link rel="import" href="/tracing/base/iteration_helpers.html"> | 9 <link rel="import" href="/tracing/base/iteration_helpers.html"> |
10 <link rel="import" href="/tracing/base/math.html"> | 10 <link rel="import" href="/tracing/base/math/math.html"> |
11 | 11 |
12 <script> | 12 <script> |
13 'use strict'; | 13 'use strict'; |
14 | 14 |
15 /** | 15 /** |
16 * @fileoverview Quick range computations. | 16 * @fileoverview Quick range computations. |
17 */ | 17 */ |
18 tr.exportTo('tr.b', function() { | 18 tr.exportTo('tr.b.math', function() { |
19 function Range() { | 19 function Range() { |
20 this.isEmpty_ = true; | 20 this.isEmpty_ = true; |
21 this.min_ = undefined; | 21 this.min_ = undefined; |
22 this.max_ = undefined; | 22 this.max_ = undefined; |
23 } | 23 } |
24 | 24 |
25 Range.prototype = { | 25 Range.prototype = { |
26 __proto__: Object.prototype, | 26 __proto__: Object.prototype, |
27 | 27 |
28 reset: function() { | 28 reset: function() { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 * Get a new Range spanning the powers (of opt_base || 10) that enclose | 95 * Get a new Range spanning the powers (of opt_base || 10) that enclose |
96 * |this| Range. | 96 * |this| Range. |
97 * If |this| is empty, returns a new empty Range. | 97 * If |this| is empty, returns a new empty Range. |
98 * | 98 * |
99 * @param {number=} opt_base Defaults to 10. | 99 * @param {number=} opt_base Defaults to 10. |
100 * @return {!Range} | 100 * @return {!Range} |
101 */ | 101 */ |
102 enclosingPowers(opt_base) { | 102 enclosingPowers(opt_base) { |
103 if (this.isEmpty) return new Range(); | 103 if (this.isEmpty) return new Range(); |
104 return Range.fromExplicitRange( | 104 return Range.fromExplicitRange( |
105 tr.b.lesserPower(this.min_, opt_base), | 105 tr.b.math.lesserPower(this.min_, opt_base), |
106 tr.b.greaterPower(this.max_, opt_base)); | 106 tr.b.math.greaterPower(this.max_, opt_base)); |
107 }, | 107 }, |
108 | 108 |
109 normalize: function(x) { | 109 normalize: function(x) { |
110 return tr.b.normalize(x, this.min, this.max); | 110 return tr.b.math.normalize(x, this.min, this.max); |
111 }, | 111 }, |
112 | 112 |
113 lerp: function(x) { | 113 lerp: function(x) { |
114 return tr.b.lerp(x, this.min, this.max); | 114 return tr.b.math.lerp(x, this.min, this.max); |
115 }, | 115 }, |
116 | 116 |
117 clamp: function(x) { | 117 clamp: function(x) { |
118 return tr.b.clamp(x, this.min, this.max); | 118 return tr.b.math.clamp(x, this.min, this.max); |
119 }, | 119 }, |
120 | 120 |
121 equals: function(that) { | 121 equals: function(that) { |
122 if (this.isEmpty && that.isEmpty) | 122 if (this.isEmpty && that.isEmpty) |
123 return true; | 123 return true; |
124 if (this.isEmpty !== that.isEmpty) | 124 if (this.isEmpty !== that.isEmpty) |
125 return false; | 125 return false; |
126 return (tr.b.approximately(this.min, that.min) && | 126 return (tr.b.math.approximately(this.min, that.min) && |
127 tr.b.approximately(this.max, that.max)); | 127 tr.b.math.approximately(this.max, that.max)); |
128 }, | 128 }, |
129 | 129 |
130 containsExplicitRangeInclusive: function(min, max) { | 130 containsExplicitRangeInclusive: function(min, max) { |
131 if (this.isEmpty) | 131 if (this.isEmpty) |
132 return false; | 132 return false; |
133 return this.min_ <= min && max <= this.max_; | 133 return this.min_ <= min && max <= this.max_; |
134 }, | 134 }, |
135 | 135 |
136 containsExplicitRangeExclusive: function(min, max) { | 136 containsExplicitRangeExclusive: function(min, max) { |
137 if (this.isEmpty) | 137 if (this.isEmpty) |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 }; | 285 }; |
286 | 286 |
287 Range.PERCENT_RANGE = Range.fromExplicitRange(0, 1); | 287 Range.PERCENT_RANGE = Range.fromExplicitRange(0, 1); |
288 Object.freeze(Range.PERCENT_RANGE); | 288 Object.freeze(Range.PERCENT_RANGE); |
289 | 289 |
290 return { | 290 return { |
291 Range, | 291 Range, |
292 }; | 292 }; |
293 }); | 293 }); |
294 </script> | 294 </script> |
OLD | NEW |