// min bounding rectangle of node children from k to p-1
            public BBox <T> DistBBox(int k, int p)
            {
                var destNode = new BBox <T>();

                destNode.Reset();

                for (int i = k; i < p; i++)
                {
                    var child = Children[i];
                    destNode.Extend(child); //node.Leaf ? toBBox(child) : child);
                }

                return(destNode);
            }
        public List <IBBox <T> > SearchParentsOrNull(IBBox <T> bbox)
        {
            var node = _data;
            //_cacheListResult.Clear();
            //var result = _cacheListResult;
            var result = new List <IBBox <T> >();

            if (!node.Contains(bbox))
            {
                return(null);
            }

            var nodesToSearch = new Stack <Node>();

            while (node != null)
            {
                for (int i = 0, len = node.Children.Count; i < len; i++)
                {
                    Node     child     = node.Children[i];
                    BBox <T> childBBox = child;

                    if (childBBox.Contains(bbox))
                    {
                        if (node.Leaf)
                        {
                            result.Add(child.ExternalObject);
                        }
                        else if (BBox <T> .Contains(bbox, childBBox))
                        {
                            AllCombine(child, ref result);
                        }
                        else
                        {
                            nodesToSearch.Push(child);
                        }
                    }
                }
                node = nodesToSearch.Count > 0 ? nodesToSearch.Pop() : null;
            }

            return(result.Count == 0 ? null : result.ToList());
        }
            public static int ChooseSplitIndex(Node node, int minEntries, int nodeChildsCount)
            {
                int index = 0;

                var minOverlap = float.MaxValue;
                var minArea    = float.MaxValue;

                for (int i = minEntries; i <= nodeChildsCount - minEntries; i++)
                {
                    BBox <T> bbox1 = node.DistBBox(0, i);
                    BBox <T> bbox2 = node.DistBBox(i, nodeChildsCount);

                    float overlap = bbox1.IntersectionArea(bbox2);
                    float area    = bbox1.Area + bbox2.Area;

                    // choose distribution with minimum overlap
                    if (overlap < minOverlap)
                    {
                        minOverlap = overlap;
                        index      = i;

                        minArea = area < minArea ? area : minArea;
                    }
                    else if (overlap == minOverlap)
                    {
                        // otherwise choose distribution with minimum area
                        if (area < minArea)
                        {
                            minArea = area;
                            index   = i;
                        }
                    }
                }

                return(index);
            }
Example #4
0
 private int CompareMinY(T a, T b) => BBox.CompareMinY(_geomSelecter(a), _geomSelecter(b));