Query = function Query( rules, /* internal use */ $op ){

        var op
            ,l
            ,rule
            ,first
            ,list
            ,fn
            ;

        if ( $op ){
            
            // parse operation choice
            if ( $op === '$or' || $op === '$and' ){

                // expect a rules array
                for ( op = 0, l = rules.length; op < l; ++op ){
                    
                    fn = Query( rules[ op ] );
                    // if first hasn't been set yet, set it and start the list there
                    // otherwise set the next node of the list
                    list = list ? list.next = fn : first = fn;
                }

                return ($op === '$or') ? $or( first ) : $and( first );
            } else if ( op = operations[ $op ] ){

                return op( rules );

            } else {
                // does not compute...
                throw 'Unknown query operation: ' + $op;
            }
        }

        // loop through rules
        for ( op in rules ){
            rule = rules[ op ];
   
            if ( op[0] === '$' ){
                // it's an operation rule
                fn = Query( rule, op );
                
            } else if ( Physics.util.isPlainObject( rule ) ) {
                // it's an object so parse subrules
                fn = wrapRule( Query( rule ), op );
            } else {
                // simple equality rule
                fn = $eq( rule, op );
            }

            // if first hasn't been set yet, set it and start the list there
            // otherwise set the next node of the list
            list = list ? list.next = fn : first = fn;
        }

        // return the rules test
        return $and( first || fnTrue );
    }
related to: Physics.world#find
Physics.query( rules ) -> Function
- rules (Object): The mongodb-like search rules. (See description).
+ (Function): The test function

Creates a function that can be used to perform tests on objects.

The test function will return a [[Boolean]]; `true` if the object matches the tests.

Query rules are mongodb-like. You can specify a hash of values to match like this:

```javascript
{
    foo: 'bar',
    baz: 2,
    some: {
        nested: 'value'
    }
}
```

And they will all need to match (it's an AND rule).

You can also use operators for more versatility. The operators you can use include:

- $eq: Test if some property is equal to a value (this is done by default, and is thus redundant)
- $ne: Test if some property is _NOT_ equal to a value
- $in: Test if some value (or array of values) is one of the specified array of values
- $nin: Test if some value (or array of values) is _NOT_ one of the specified array of values
- $at: Test if a body's [[Physics.aabb]] includes specified point. It's a primative hit-test.

Example:

```javascript
var wheelsArray = [];

var queryFn = Physics.query({
    name: 'circle', // only circles
    $nin: wheelsArray, // not in the wheelsArray
    labels: { $in: [ 'player', 'monster' ] } // that have player OR monster labels
});

var obj = {
    name: 'circle',
    labels: [ 'round' ]
};

queryFn( obj ); // -> false
// give it a player tag
obj.labels.push('player');
queryFn( obj ); // -> true
// put it inside the wheelsArray
wheelsArray.push( obj );
queryFn( obj ); // -> false
```