Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / region.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 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.
6 -->
7
8 <link rel="import" href="/base/rect.html">
9 <script>
10 'use strict';
11
12 tv.exportTo('cc', function() {
13   /**
14    * @constructor
15    */
16   function Region() {
17     this.rects = [];
18   }
19
20   Region.fromArray = function(array) {
21     if (array.length % 4 != 0)
22       throw new Error('Array must consist be a multiple of 4 in length');
23
24     var r = new Region();
25     for (var i = 0; i < array.length; i += 4) {
26       r.rects.push(tv.Rect.fromXYWH(array[i], array[i + 1],
27                                       array[i + 2], array[i + 3]));
28     }
29     return r;
30   }
31
32   /**
33    * @return {Region} If array is undefined, returns an empty region. Otherwise
34    * returns Region.fromArray(array).
35    */
36   Region.fromArrayOrUndefined = function(array) {
37     if (array === undefined)
38       return new Region();
39     return Region.fromArray(array);
40   };
41
42   Region.prototype = {
43     __proto__: Region.prototype,
44
45     rectIntersects: function(r) {
46       for (var i = 0; i < this.rects.length; i++) {
47         if (this.rects[i].intersects(r))
48           return true;
49       }
50       return false;
51     },
52
53     addRect: function(r) {
54       this.rects.push(r);
55     }
56   };
57
58   return {
59     Region: Region
60   };
61 });
62 </script>