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.
8 * @fileoverview Quick range computations.
10 tvcm.exportTo('tvcm', function() {
14 this.min_ = undefined;
15 this.max_ = undefined;
19 __proto__: Object.prototype,
23 this.min_ = undefined;
24 this.max_ = undefined;
31 addRange: function(range) {
34 this.addValue(range.min);
35 this.addValue(range.max);
38 addValue: function(value) {
42 this.isEmpty_ = false;
45 this.max_ = Math.max(this.max_, value);
46 this.min_ = Math.min(this.min_, value);
50 this.isEmpty_ = false;
67 this.isEmpty_ = false;
74 return this.max_ - this.min_;
78 return (this.min_ + this.max_) * 0.5;
81 equals: function(that) {
82 if (this.isEmpty && that.isEmpty)
84 if (this.isEmpty != that.isEmpty)
86 return this.min === that.min &&
87 this.max === that.max;
90 containsRange: function(range) {
91 if (this.isEmpty || range.isEmpty)
93 return this.min <= range.min && this.max >= range.max;
96 containsExplicitRange: function(min, max) {
99 return this.min <= min && this.max >= max;
102 intersectsRange: function(range) {
103 if (this.isEmpty || range.isEmpty)
105 return !(range.max < this.min ||
106 range.min > this.max);
109 intersectsExplicitRange: function(min, max) {
112 return !(max < this.min ||
117 Range.compareByMinTimes = function(a, b) {
118 if (!a.isEmpty && !b.isEmpty)
119 return a.min_ - b.min_;
121 if (a.isEmpty && !b.isEmpty)
124 if (!a.isEmpty && b.isEmpty)