1 /** 2 * The MIT License (MIT) 3 * 4 * Copyright (c) 2016 DeNA Co., Ltd. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a copy 7 * of this software and associated documentation files (the "Software"), to deal 8 * in the Software without restriction, including without limitation the rights 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the Software is 11 * furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice shall be included in 14 * all copies or substantial portions of the Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 * SOFTWARE. 23 */ 24 25 /// <reference path="base.js"/> 26 /// <reference path="object.js"/> 27 /// <reference path="region.js"/> 28 29 /** 30 * Represents a rectangle on a two-dimensional coordinate system. 31 * @param {number} x 32 * @param {number} y 33 * @param {number} width 34 * @param {number} height 35 * @extends {createjs.Object} 36 * @implements {createjs.Region} 37 * @constructor 38 */ 39 createjs.Rectangle = function(x, y, width, height) { 40 createjs.Object.call(this); 41 42 /** 43 * The x position of this rectangle. 44 * @type {number} 45 */ 46 this.x = x; 47 48 /** 49 * The y position of this rectangle. 50 * @type {number} 51 */ 52 this.y = y; 53 54 /** 55 * The width of this rectangle. 56 * @type {number} 57 */ 58 this.width = width; 59 60 /** 61 * The height of this rectangle. 62 * @type {number} 63 */ 64 this.height = height; 65 66 }; 67 createjs.inherits('Rectangle', createjs.Rectangle, createjs.Object); 68 69 /** 70 * Initializes all properties. 71 * @param {number} x 72 * @param {number} y 73 * @param {number} width 74 * @param {number} height 75 * @return {createjs.Rectangle} 76 */ 77 createjs.Rectangle.prototype.initialize = function(x, y, width, height) { 78 /// <param type="number" name="x"/> 79 /// <param type="number" name="y"/> 80 /// <param type="number" name="width"/> 81 /// <param type="number" name="height"/> 82 /// <returns type="createjs.Rectangle"/> 83 this.x = x; 84 this.y = y; 85 this.width = width; 86 this.height = height; 87 return this; 88 }; 89 90 /** 91 * Compares this rectangle with the specified one. 92 * @param {createjs.Rectangle} rectangle 93 * @return {boolean} 94 */ 95 createjs.Rectangle.prototype.isEqual = function(rectangle) { 96 /// <param type="createjs.Rectangle" name="rectangle"/> 97 /// <returns type="boolean"/> 98 return this.x == rectangle.x && this.y == rectangle.y && 99 this.width == rectangle.width && this.height == rectangle.height; 100 }; 101 102 /** @override */ 103 createjs.Rectangle.prototype.isEmpty = function() { 104 /// <returns type="boolean"/> 105 return !this.width || !this.height; 106 }; 107 108 /** @override */ 109 createjs.Rectangle.prototype.contain = function(x, y) { 110 /// <param type="number" name="x"/> 111 /// <param type="number" name="y"/> 112 /// <returns type="boolean"/> 113 return this.x <= x && x <= this.x + this.width && 114 this.y <= y && y <= this.y + this.height; 115 }; 116 117 // Export the createjs.Rectangle object to the global namespace. 118 createjs.exportObject('createjs.Rectangle', createjs.Rectangle, { 119 // createjs.Rectangle methods 120 121 // createjs.Object methods. 122 }); 123