Code coverage report for src/pixi/core/Circle.js

Statements: 50% (7 / 14)      Branches: 75% (6 / 8)      Functions: 33.33% (1 / 3)      Lines: 50% (7 / 14)     

All files » src/pixi/core\ » Circle.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75                          1             1             1             1                 1                         1                               1    
/**
 * @author Chad Engler <chad@pantherdev.com>
 */
 
/**
 * The Circle object can be used to specify a hit area for displayobjects
 *
 * @class Circle
 * @constructor
 * @param x {Number} The X coord of the upper-left corner of the framing rectangle of this circle
 * @param y {Number} The Y coord of the upper-left corner of the framing rectangle of this circle
 * @param radius {Number} The radius of the circle
 */
PIXI.Circle = function(x, y, radius)
{
    /**
     * @property x
     * @type Number
     * @default 0
     */
    this.x = x || 0;
 
    /**
     * @property y
     * @type Number
     * @default 0
     */
    this.y = y || 0;
 
    /**
     * @property radius
     * @type Number
     * @default 0
     */
    this.radius = radius || 0;
};
 
/**
 * Creates a clone of this Circle instance
 *
 * @method clone
 * @return {Circle} a copy of the polygon
 */
PIXI.Circle.prototype.clone = function()
{
    return new PIXI.Circle(this.x, this.y, this.radius);
};
 
/**
 * Checks if the x, and y coords passed to this function are contained within this circle
 *
 * @method contains
 * @param x {Number} The X coord of the point to test
 * @param y {Number} The Y coord of the point to test
 * @return {Boolean} if the x/y coords are within this polygon
 */
PIXI.Circle.prototype.contains = function(x, y)
{
    if(this.radius <= 0)
        return false;
 
    var dx = (this.x - x),
        dy = (this.y - y),
        r2 = this.radius * this.radius;
 
    dx *= dx;
    dy *= dy;
 
    return (dx + dy <= r2);
};
 
// constructor
PIXI.Circle.prototype.constructor = PIXI.Circle;