public EPropQuadTreeDivisionResult ResolveDivision(EPropQuadTreeDivisionDecider decider) { var childResults = _subNodes.Values.Select(c => c.ResolveDivision(decider)).ToList(); return(new EPropQuadTreeDivisionResult() { ScopesToFree = childResults.SelectMany(c => c.ScopesToFree).ToList(), IdChanges = childResults.SelectMany(c => c.IdChanges).ToList() }); }
public EPropQuadTreeDivisionResult ResolveDivision(EPropQuadTreeDivisionDecider decider) { var expectedNodeType = decider.WhatTypeShouldNodeBe(_rectangle.RealSpaceRectangle); var currentNodeType = _node.NodeType; var idChanges = new List <EPropIdChange>(); var scopesToFree = new List <LocaleBufferScopeIndexType>(); if (expectedNodeType == currentNodeType) { if (currentNodeType == EPropQuadTreeNodeType.Complex) { var complexNode = _node as EPropQuadTreeComplex; var complexNodeDivisionResult = complexNode.ResolveDivision(decider.ChildElementDecider()); idChanges.AddRange(complexNodeDivisionResult.IdChanges); scopesToFree.AddRange(complexNodeDivisionResult.ScopesToFree); } } else { Dictionary <LocaleBufferScopeIndexType, EPropLocaleBufferScopeRegistry> scopes = _node.TakeAwayAllScopes(); if (expectedNodeType == EPropQuadTreeNodeType.Leaf) { var leafNode = new EPropQuadTreeLeaf(_rectangle, _localeBufferManager); _node = leafNode; leafNode.SetScopes(scopes); } else { var flatPositionWithId = scopes.SelectMany(c => { var allLocales = c.Value.RetriveAllLocales(); return(allLocales.Select(k => new EPropElevationIdWithFlatPosition() { FlatPosition = k.FlatPosition, Id = new EPropElevationId() { InScopeIndex = k.InScopeIndex, LocaleBufferScopeIndex = c.Key } })); }).ToList(); var complexNode = new EPropQuadTreeComplex(_rectangle, _localeBufferManager); var complexNodeDivisionResult = complexNode.ResolveDivision(decider.ChildElementDecider()); idChanges.AddRange(complexNodeDivisionResult.IdChanges); scopesToFree.AddRange(complexNodeDivisionResult.ScopesToFree); _node = complexNode; idChanges.AddRange(flatPositionWithId.Select(c => new EPropIdChange() { NewId = _node.RegisterProp(c.FlatPosition), OldId = c.Id } )); scopesToFree.AddRange(scopes.Keys); } } return(new EPropQuadTreeDivisionResult() { IdChanges = idChanges, ScopesToFree = scopesToFree }); }