/// <summary> /// Select minimal need and apply it recursively for all coliding items /// <remarks> /// Notice that applying same need on all recursive collisions /// is enough for state where no collision has been before /// </remarks> /// </summary> /// <param name="need"></param> /// <param name="itemToMove"></param> private bool recursiveApplyNeed(Move need, DiagramItem itemToMove) { if (!need.HasStretchableDirection) { //we have to check if need appling is allowed var possibilities = computePossibilities(itemToMove); if (!need.IsSatisfiedBy(possibilities.GetMove(need.Direction))) { return(false); } } var currentPosition = getPosition(itemToMove); var newPosition = need.Apply(currentPosition); trySetPosition(itemToMove, newPosition); var collidingItems = _navigator.GetItemsInCollision(itemToMove).ToArray(); foreach (var collidingItem in collidingItems) { //for other coliding items apply same need var hasSuccess = recursiveApplyNeed(need, collidingItem); if (!hasSuccess) { return(false); } } return(true); }
internal void Arrange(IEnumerable <DiagramItem> arrangedItems) { //TODO use zGroups on container var sortedItems = arrangedItems.OrderBy((item) => DiagramCanvasBase.GetZIndex(item)); _navigator = new SceneNavigator(); foreach (var item in sortedItems) { var collidingItems = _navigator.GetItemsInCollision(item).ToArray(); foreach (var colidingItem in collidingItems) { //move colliding items moveCollidingItem(item, colidingItem); } _navigator.AddItem(item); } }