src/StackQuadtree.cs
/// <summary>Query and return the items intersecting <paramref name="rect"/>.</summary>
Query and return the items intersecting .
Query and return the items intersecting .
public IEnumerable<int> Query(RotRect rect) {
            _toProcess.Push(0);
            do {
                var nId = _toProcess.Pop();
                var n = _nodes[nId];
                if (n._itemCount < 0) {
                    var node2 = _nodes[n._firstChild];
                    if (rect.Intersects(node2._bounds))
                        _toProcess.Push(n._firstChild);
                    node2 = _nodes[n._firstChild + 1];
                    if (rect.Intersects(node2._bounds))
                        _toProcess.Push(n._firstChild + 1);
                    node2 = _nodes[n._firstChild + 2];
                    if (rect.Intersects(node2._bounds))
                        _toProcess.Push(n._firstChild + 2);
                    node2 = _nodes[n._firstChild + 3];
                    if (rect.Intersects(node2._bounds))
                        _toProcess.Push(n._firstChild + 3);
                    continue;
                }
                if (n._itemCount > 0) {
                    var item = _items[n._firstChild];
                    if (rect.Contains(n._bounds)) {
                        var itemId = n._firstChild;
                        for (var i = 0; i < n._itemCount; i++) {
                            item = _items[itemId];
                            yield return item._id;
                            itemId = item._next;
                        }
                    } else
                        do {
                            if (rect.Intersects(item._bounds))
                                yield return item._id;
                            if (item._next < 0)
                                break;
                            item = _items[item._next];
                        } while (true);
                }
            } while (_toProcess.Count > 0);
            yield break;
        }
public IEnumerable < int > Query ( RotRect rect ) { _toProcess . Push ( 0 ) ; do { var nId = _toProcess . Pop ( ) ; var n = _nodes [ nId ] ; if ( n . _itemCount < 0 ) { var node2 = _nodes [ n . _firstChild ] ; if ( rect . Intersects ( node2 . _bounds ) ) _toProcess . Push ( n . _firstChild ) ; node2 = _nodes [ n . _firstChild + 1 ] ; if ( rect . Intersects ( node2 . _bounds ) ) _toProcess . Push ( n . _firstChild + 1 ) ; node2 = _nodes [ n . _firstChild + 2 ] ; if ( rect . Intersects ( node2 . _bounds ) ) _toProcess . Push ( n . _firstChild + 2 ) ; node2 = _nodes [ n . _firstChild + 3 ] ; if ( rect . Intersects ( node2 . _bounds ) ) _toProcess . Push ( n . _firstChild + 3 ) ; continue ; } if ( n . _itemCount > 0 ) { var item = _items [ n . _firstChild ] ; if ( rect . Contains ( n . _bounds ) ) { var itemId = n . _firstChild ; for ( var i = 0 ; i < n . _itemCount ; i ++ ) { item = _items [ itemId ] ; yield return item . _id ; itemId = item . _next ; } } else do { if ( rect . Intersects ( item . _bounds ) ) yield return item . _id ; if ( item . _next < 0 ) break ; item = _items [ item . _next ] ; } while ( true ) ; } } while ( _toProcess . Count > 0 ) ; yield break ; }
Query and return the items intersecting .
Query and return the items intersecting .
//do { //    yield return item._id; //    if (item._next < 0) //        break; //    item = _items[item._next]; //} while (true);
rect
RotRect