OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 'use strict'; |
| 5 |
| 6 /** |
| 7 * @fileoverview Quick range computations. |
| 8 */ |
| 9 base.exportTo('base', function() { |
| 10 |
| 11 function Range() { |
| 12 this.isEmpty_ = true; |
| 13 this.min_ = undefined; |
| 14 this.max_ = undefined; |
| 15 }; |
| 16 |
| 17 Range.prototype = { |
| 18 __proto__: Object.prototype, |
| 19 |
| 20 reset: function() { |
| 21 this.isEmpty_ = true; |
| 22 this.min_ = undefined; |
| 23 this.max_ = undefined; |
| 24 }, |
| 25 |
| 26 get isEmpty() { |
| 27 return this.isEmpty_; |
| 28 }, |
| 29 |
| 30 addRange: function(range) { |
| 31 if (range.isEmpty) |
| 32 return; |
| 33 this.addValue(range.min); |
| 34 this.addValue(range.max); |
| 35 }, |
| 36 |
| 37 addValue: function(value) { |
| 38 if (this.isEmpty_) { |
| 39 this.max_ = value; |
| 40 this.min_ = value; |
| 41 this.isEmpty_ = false; |
| 42 return; |
| 43 } |
| 44 this.max_ = Math.max(this.max_, value); |
| 45 this.min_ = Math.min(this.min_, value); |
| 46 }, |
| 47 |
| 48 get min() { |
| 49 if (this.isEmpty_) |
| 50 return undefined; |
| 51 return this.min_; |
| 52 }, |
| 53 |
| 54 get max() { |
| 55 if (this.isEmpty_) |
| 56 return undefined; |
| 57 return this.max_; |
| 58 }, |
| 59 }; |
| 60 |
| 61 return { |
| 62 Range: Range |
| 63 }; |
| 64 |
| 65 }); |
OLD | NEW |