public Box GetTile(IBox box, double maxSize) { if (_mainBox == null) { throw new InvalidOperationException("main box not initialized"); } VerifyExtent(box); IList <int> counter0 = null; IList <int> denominator = null; if (_unitBox != null) { GetPositions(out counter0, out denominator); } BoxTile addTile = FindAddTile(_mainTile, box, true, counter0, denominator); while (addTile.MaxInParentSplitDim - addTile.MinInParentSplitDim > maxSize) { addTile.Split(_unitBox, counter0, denominator, _mainCounter, _mainSize); BoxTile childTile = FindAddTile(addTile, box, false, counter0, denominator); if (childTile == addTile) { break; } addTile = childTile; } Box tileBox = GetBox(addTile); return(tileBox); }
private BoxTile FindAddTile([NotNull] BoxTile parent, [NotNull] IBox geomExtent, bool dynamic, IList <int> counter0, IList <int> denominator) { BoxTile child0 = parent.Child0; if (child0 != null) { BoxTile child1 = parent.Child1; int divDim = parent.SplitDimension; if (geomExtent.Min[divDim] < child1.MinInParentSplitDim) { if (geomExtent.Max[divDim] < child0.MaxInParentSplitDim) { if (dynamic) { counter0[divDim] *= 2; denominator[divDim] *= 2; } bool addDynamic = dynamic; if (denominator[divDim] >= _maxDenominator) { addDynamic = false; } return(FindAddTile(child0, geomExtent, addDynamic, counter0, denominator)); } return(parent); } if (geomExtent.Max[divDim] < child1.MaxInParentSplitDim) { if (dynamic) { counter0[divDim] += counter0[divDim] + 1; denominator[divDim] *= 2; } bool addDynamic = dynamic; if (denominator[divDim] >= _maxDenominator) { addDynamic = false; } return(FindAddTile(child1, geomExtent, addDynamic, counter0, denominator)); } return(parent); } // tile has no children if (!dynamic || parent.ElemsCount < _maxElemPerTile) { return(parent); } // split tile and try again if (_unitBox == null) { InitSize(); VerifyExtent(geomExtent); return(StartFindAddTile(geomExtent, true)); } parent.Split(_unitBox, counter0, denominator, _mainCounter, _mainSize); return(FindAddTile(parent, geomExtent, false, counter0, denominator)); }