Ejemplo n.º 1
0
 public void Concat(ILinkGroup other)
 {
     foreach (var a in other.Children)
     {
         this.Add(a);
     }
     this.RecalculateCenter();
 }
        public static void RecalculateCenter(this ILinkGroup group)
        {
            group.TagGroup.Clear();
            if (!group.Any())
            {
                return;
            }

            List <ILinkData> list = group.Children;

            list.Sort((x, y) => {
                int result = (int)(x.Pos.x - y.Pos.x);
                return(result != 0 ? result : (int)(y.Pos.z - x.Pos.z));
            });

            int count  = list.Count();
            int center = count / 2;
            int index  = center;
            int mod2   = count % 2;

            for (int i = 0; i < center; i++)
            {
                list[i].DistFromCenter = index;
                list[i].PosTag         = PositionTag.LeftSide;
                index--;
            }
            for (int i = center + mod2; i < count; i++)
            {
                index++;
                list[i].PosTag         = PositionTag.RightSide;
                list[i].DistFromCenter = index;
            }
            if (mod2 == 0)
            {
                list[center - 1].PosTag |= PositionTag.LeftBorder;
                list[center].PosTag     |= PositionTag.RightBorder;
            }
            else
            {
                list[center].PosTag         = PositionTag.Center;
                list[center].DistFromCenter = 0;
            }
#if DEBUG
            Log.Message("*****RecalculateCenter(): children=" + list.Count);
            foreach (var a in list)
            {
                Log.Message("pos=" + a.DrawPos + " flag=" + a.PosTag + " dist=" + a.DistFromCenter);
            }
#endif
        }
        public static void DetachGroupAround(ILinkData delObj)
        {
            ILinkGroup parent = delObj.GroupParent;

            if (parent.Children.Count() <= 1)
            {
                return;
            }
            if (parent.Children.First() == delObj || parent.Children.Last() == delObj)
            {
                parent.Remove(delObj);
                parent.RecalculateCenter();
            }
            else
            {
                parent.Split(delObj);
            }
            delObj.Reset();
            ILinkGroup result = new LinkGroup(delObj);
        }