Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Containment vs Intersection #55

Open
mediabuff opened this issue Dec 19, 2024 · 0 comments
Open

Containment vs Intersection #55

mediabuff opened this issue Dec 19, 2024 · 0 comments

Comments

@mediabuff
Copy link

mediabuff commented Dec 19, 2024

This library seems to handle 'search' by detecting intersections for given bounds. There is also a notion of 'containment', i.e return results of nodes that are contained within the given bounds.

Can this be made to work. Tried a fork - changing the 'intersection' calls with 'contain' calls. Doesn't see to work. Should the logic of enclosed envelop be changed as well ? Currently, intermediate nodes (of 9 ) are created with a 'union' envelope of the children. How should be to changed to support the containment paradigm ? My search logic fails at these intermediate nodes.

The parameter ContainmentType is either Contains or Intersects

private List<T> DoSearch(
    in RectangleF boundingBox, 
    ContainmentType ctype = ContainmentType.Intersects, 
    int maxLevel = int.MaxValue)
{
    if (ctype == ContainmentType.Intersects)
    {
        if (!boundingBox.Containment(Root.Envelope, ctype) || maxLevel < 1)
            return [];
    }

 var intersections = new List<T>();
    var queue = new Queue<Node>();
    queue.Enqueue(Root);

    while (queue.Count != 0)
    {
        var item = queue.Dequeue();

        if (item.IsLeaf)
        {
            foreach (var i in item.Items)
            {
                if (boundingBox.Containment(i.Envelope, ctype))
                    intersections.Add((T)i);
            }
        }
        else
        {
            if (maxLevel-- > 0)
            {
                foreach (var i in item.Items)
                {
                    if (boundingBox.Containment(i.Envelope, ctype))
                        queue.Enqueue((Node)i);
                }
            }
        }
    }

    return intersections;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant