src/SpatialHash.cs
/// <summary>Query and return the items intersecting <paramref name="area"/></summary>
Query and return the items intersecting
Query and return the items intersecting
public IEnumerable<T> Query(Rectangle area) {
            int x = area.X / Spacing,
                y = area.Y / Spacing;
            int lX = area.Width / Spacing + x + 1,
                lY = area.Height / Spacing + y + 1;
            for (var j = x; j < lX; j += 3)
                for (var k = y; k < lY; k += 3)
                    foreach (var t in InQuery(new Point(j, k)))
                        if (new RotRect(t.Bounds.XY, t.Bounds.Size, t.Bounds.Rotation, t.Bounds.Origin).Intersects(area))
                            yield return t;
            int e = area.Width / Spacing % 3;
            if (e > 0) {
                for (var k = y; k < lY; k += 3)
                    foreach (var t in InQuery(new Point(e % 2 + lX, k)))
                        if (new RotRect(t.Bounds.XY, t.Bounds.Size, t.Bounds.Rotation, t.Bounds.Origin).Intersects(area))
                            yield return t;
                lX += 3;
            }
            e = area.Height / Spacing % 3;
            if (e > 0)
                for (var j = x; j < lX; j += 3)
                    foreach (var t in InQuery(new Point(j, e % 2 + lY)))
                        if (new RotRect(t.Bounds.XY, t.Bounds.Size, t.Bounds.Rotation, t.Bounds.Origin).Intersects(area))
                            yield return t;
        }
public IEnumerable < T > Query ( Rectangle area ) { int x = area . X / Spacing , y = area . Y / Spacing ; int lX = area . Width / Spacing + x + 1 , lY = area . Height / Spacing + y + 1 ; for ( var j = x ; j < lX ; j += 3 ) for ( var k = y ; k < lY ; k += 3 ) foreach ( var t in InQuery ( new Point ( j , k ) ) ) if ( new RotRect ( t . Bounds . XY , t . Bounds . Size , t . Bounds . Rotation , t . Bounds . Origin ) . Intersects ( area ) ) yield return t ; int e = area . Width / Spacing % 3 ; if ( e > 0 ) { for ( var k = y ; k < lY ; k += 3 ) foreach ( var t in InQuery ( new Point ( e % 2 + lX , k ) ) ) if ( new RotRect ( t . Bounds . XY , t . Bounds . Size , t . Bounds . Rotation , t . Bounds . Origin ) . Intersects ( area ) ) yield return t ; lX += 3 ; } e = area . Height / Spacing % 3 ; if ( e > 0 ) for ( var j = x ; j < lX ; j += 3 ) foreach ( var t in InQuery ( new Point ( j , e % 2 + lY ) ) ) if ( new RotRect ( t . Bounds . XY , t . Bounds . Size , t . Bounds . Rotation , t . Bounds . Origin ) . Intersects ( area ) ) yield return t ; }
Query and return the items intersecting
Query and return the items intersecting
area
Rectangle