1 /** 2 * The Render Engine 3 * SpatialGridNode 4 * 5 * @fileoverview A simple collision model which divides a finite space up into 6 * a coarse grid to assist in quickly finding objects within that 7 * space. 8 * 9 * @author: Brett Fattori (brettf@renderengine.com) 10 * 11 * @author: $Author: bfattori $ 12 * @version: $Revision: 1555 $ 13 * 14 * Copyright (c) 2011 Brett Fattori (brettf@renderengine.com) 15 * 16 * Permission is hereby granted, free of charge, to any person obtaining a copy 17 * of this software and associated documentation files (the "Software"), to deal 18 * in the Software without restriction, including without limitation the rights 19 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 20 * copies of the Software, and to permit persons to whom the Software is 21 * furnished to do so, subject to the following conditions: 22 * 23 * The above copyright notice and this permission notice shall be included in 24 * all copies or substantial portions of the Software. 25 * 26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 29 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 30 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 31 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 32 * THE SOFTWARE. 33 * 34 */ 35 36 // The class this file defines and its required classes 37 R.Engine.define({ 38 "class":"R.collision.broadphase.SpatialGridNode", 39 "requires":[ 40 "R.collision.broadphase.AbstractCollisionNode" 41 ] 42 }); 43 44 /** 45 * @class A single node within a <tt>R.collision.broadphase.SpatialGrid</tt>. When the collision model is 46 * updated, the nodes within the grid will be updated to reflect the 47 * objects within them. A node defines a single rectangle within the 48 * entire {@link R.collision.broadphase.SpatialGrid} 49 * 50 * @extends R.collision.broadphase.AbstractCollisionNode 51 * @constructor 52 * @description Create an instance of an <tt>R.collision.broadphase.SpatialNode</tt> for use within a {@link R.collision.broadphase.SpatialGrid} 53 * @param rect {R.math.Rectangle2D} The rectangle which defines this node. 54 */ 55 R.collision.broadphase.SpatialGridNode = function () { 56 "use strict"; 57 return R.collision.broadphase.AbstractCollisionNode.extend(/** @scope R.collision.broadphase.SpatialGridNode.prototype */{ 58 59 rect:null, 60 61 /** @private */ 62 constructor:function (rect) { 63 this.base(); 64 this.rect = rect; 65 }, 66 67 /** 68 * Get the rectangle which defines this node. 69 * @return {R.math.Rectangle2D} 70 */ 71 getRect:function () { 72 return this.rect 73 }, 74 75 /** 76 * Returns true if the spatial node contains the point specified. 77 * @param point {R.math.Point2D} The point to check 78 * @return {Boolean} 79 */ 80 contains:function (point) { 81 return this.getRect().containsPoint(point); 82 } 83 84 }, /** @scope R.collision.broadphase.SpatialGridNode.prototype */ { 85 86 /** 87 * Get the class name of this object 88 * 89 * @return {String} "R.collision.broadphase.SpatialGridNode" 90 */ 91 getClassName:function () { 92 return "R.collision.broadphase.SpatialGridNode"; 93 } 94 95 }); 96 97 }