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.require('base.gl_matrix'); |
| 10 |
| 11 base.exportTo('base', function() { |
| 12 |
| 13 /** |
| 14 * Tracks a 2D bounding box. |
| 15 * @constructor |
| 16 */ |
| 17 function Rect2() { |
| 18 this.left = 0; |
| 19 this.top = 0; |
| 20 this.width = 0; |
| 21 this.height = 0; |
| 22 }; |
| 23 Rect2.FromXYWH = function(x, y, w, h) { |
| 24 var rect = new Rect2(); |
| 25 rect.left = x; |
| 26 rect.top = y; |
| 27 rect.width = w; |
| 28 rect.height = h; |
| 29 return rect; |
| 30 } |
| 31 |
| 32 Rect2.prototype = { |
| 33 __proto__: Object.prototype, |
| 34 |
| 35 translateXY: function(x, y) { |
| 36 this.left += x; |
| 37 this.top += y; |
| 38 }, |
| 39 |
| 40 enlarge: function(pad) { |
| 41 this.left -= pad; |
| 42 this.top -= pad; |
| 43 this.width += 2*pad; |
| 44 this.height += 2*pad; |
| 45 }, |
| 46 |
| 47 get right() { |
| 48 return this.left + this.width; |
| 49 }, |
| 50 |
| 51 get bottom() { |
| 52 return this.left + this.width; |
| 53 } |
| 54 }; |
| 55 |
| 56 return { |
| 57 Rect2: Rect2 |
| 58 }; |
| 59 |
| 60 }); |
OLD | NEW |