1// Copyright (c) 2013 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
5'use strict';
6
7base.require('base.rect');
8
9base.exportTo('cc', function() {
10  function RegionFromArray(array) {
11    if (array.length % 4 != 0)
12      throw new Error('Array must consist be a multiple of 4 in length');
13
14    var r = new Region();
15    for (var i = 0; i < array.length; i += 4) {
16      r.rects.push(base.Rect.FromXYWH(array[i], array[i + 1],
17                                      array[i + 2], array[i + 3]));
18    }
19    return r;
20  }
21
22  /**
23   * @constructor
24   */
25  function Region() {
26    this.rects = [];
27  }
28
29  Region.prototype = {
30    __proto__: Region.prototype,
31
32    rectIntersects: function(r) {
33      for (var i = 0; i < this.rects.length; i++) {
34        if (this.rects[i].intersects(r))
35          return true;
36      }
37      return false;
38    }
39  };
40
41  return {
42    Region: Region,
43    RegionFromArray: RegionFromArray
44  };
45});
46