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
5 found in the LICENSE file.
7 <link rel="import" href="/tvcm.html">
12 * @fileoverview Quick range computations.
14 tvcm.exportTo('tvcm', function() {
18 this.min_ = undefined;
19 this.max_ = undefined;
23 __proto__: Object.prototype,
27 this.min_ = undefined;
28 this.max_ = undefined;
35 addRange: function(range) {
38 this.addValue(range.min);
39 this.addValue(range.max);
42 addValue: function(value) {
46 this.isEmpty_ = false;
49 this.max_ = Math.max(this.max_, value);
50 this.min_ = Math.min(this.min_, value);
54 this.isEmpty_ = false;
71 this.isEmpty_ = false;
78 return this.max_ - this.min_;
82 return (this.min_ + this.max_) * 0.5;
85 equals: function(that) {
86 if (this.isEmpty && that.isEmpty)
88 if (this.isEmpty != that.isEmpty)
90 return this.min === that.min &&
91 this.max === that.max;
94 containsRange: function(range) {
95 if (this.isEmpty || range.isEmpty)
97 return this.min <= range.min && this.max >= range.max;
100 containsExplicitRange: function(min, max) {
103 return this.min <= min && this.max >= max;
106 intersectsRange: function(range) {
107 if (this.isEmpty || range.isEmpty)
109 return !(range.max < this.min ||
110 range.min > this.max);
113 intersectsExplicitRange: function(min, max) {
116 return !(max < this.min ||
121 Range.compareByMinTimes = function(a, b) {
122 if (!a.isEmpty && !b.isEmpty)
123 return a.min_ - b.min_;
125 if (a.isEmpty && !b.isEmpty)
128 if (!a.isEmpty && b.isEmpty)