src/Trigger.js
/**
 * A trigger object is an entity that can make trigger volumes signal its events.
 * 
 * @param particle is a TriggerParticle
 * @param target is an object with onTrigger(event, volume, object) method
 * @param shapes is either a {Rectf} or an array of {Circle} objects, non-empty
 * @returns {TriggerObject}
 */
A trigger object is an entity that can make trigger volumes signal its events.

@param particle is a TriggerParticle
@param target is an object with onTrigger(event, volume, object) method
@param shapes is either a {Rectf} or an array of {Circle} objects, non-empty
@returns {TriggerObject}
A trigger object is an entity that can make trigger volumes signal its events . @param particle is a TriggerParticle @param target is an object with onTrigger ( event volume object ) method @param shapes is either a { Rectf } or an array of { Circle } objects non - empty @returns { TriggerObject }
function TriggerObject(particle, target, shapes) {
    assert(particle instanceof TriggerParticle && target != null);
    this.particle = particle;
    this.target = target;
    if (shapes instanceof Rectf) {
        this.rect = shapes;
        this.circles = null;
    } else if (shapes instanceof Array) {
        assert(shapes.length > 0);
        var cursor = shapes[0], r = cursor.r, x = cursor.c.x, y = cursor.c.y, i;
        var x0 = x - r, y0 = y - r, x1 = x + r, y1 = y + r;
        with (Math) {
            for (i = 0; i < shapes.length; i++) {
                cursor = shapes[i];
                r = cursor.r;
                x = cursor.c.x;
                y = cursor.c.y;
                x0 = min(x0, x - r);
                y0 = min(y0, y - r);
                x1 = max(x1, x + r);
                y1 = max(y1, y + r);
            }
        }
        this.rect = new Rectf(x0, y0, x1, y1);
        this.circles = shapes;
    } else {
        assert(false);
    }
}
function TriggerObject ( particle , target , shapes ) { assert ( particle instanceof TriggerParticle && target != null ) ; this . particle = particle ; this . target = target ; if ( shapes instanceof Rectf ) { this . rect = shapes ; this . circles = null ; } else if ( shapes instanceof Array ) { assert ( shapes . length > 0 ) ; var cursor = shapes [ 0 ] , r = cursor . r , x = cursor . c . x , y = cursor . c . y , i ; var x0 = x - r , y0 = y - r , x1 = x + r , y1 = y + r ; with ( Math ) { for ( i = 0 ; i < shapes . length ; i ++ ) { cursor = shapes [ i ] ; r = cursor . r ; x = cursor . c . x ; y = cursor . c . y ; x0 = min ( x0 , x - r ) ; y0 = min ( y0 , y - r ) ; x1 = max ( x1 , x + r ) ; y1 = max ( y1 , y + r ) ; } } this . rect = new Rectf ( x0 , y0 , x1 , y1 ) ; this . circles = shapes ; } else { assert ( false ) ; } }
A trigger object is an entity that can make trigger volumes signal its events.
A trigger object is an entity that can make trigger volumes signal its events .