Esempio n. 1
0
 private BuchheimNode init_lmost_sibling()
 {
     if (!this._lmost_sibling && this.parent && this != this.parent.children[0])
     {
         this._lmost_sibling = this.parent.children[0];
     }
     return(this._lmost_sibling);
 }
Esempio n. 2
0
 static void third_walk(BuchheimNode tree, float n)
 {
     tree.x += n;
     foreach (var c in tree.children)
     {
         third_walk(c, n);
     }
 }
Esempio n. 3
0
        static void move_subtree(BuchheimNode wl, BuchheimNode wr, float shift)
        {
            var subtrees = wr.number - wl.number;

            wr.change -= shift / subtrees;
            wr.shift  += shift;
            wl.change += shift / subtrees;
            wr.x      += shift;
            wr.mod    += shift;
        }
Esempio n. 4
0
 static BuchheimNode get_ancestor(BuchheimNode vil, BuchheimNode v, BuchheimNode default_ancestor)
 {
     if (v.parent.children.Contains(vil.ancestor))
     {
         return(vil.ancestor);
     }
     else
     {
         return(default_ancestor);
     }
 }
Esempio n. 5
0
        static void execute_shifts(BuchheimNode v)
        {
            float shift = 0, change = 0;

            foreach (var w in v.children.Reverse())
            {
                w.x    += shift;
                w.mod  += shift;
                change += w.change;
                shift  += w.shift + change;
            }
        }
Esempio n. 6
0
        static BuchheimNode apportion(BuchheimNode v, BuchheimNode default_ancestor, float distance)
        {
            var w = v.lbrother();

            if (w != null)
            {
                var vir = v;
                var vor = v;
                var vil = w;
                var vol = v.lmost_sibling;

                var sir = v.mod;
                var sor = v.mod;
                var sil = vil.mod;
                var sol = vol.mod;

                while (vil.right() && vir.left())
                {
                    vil          = vil.right();
                    vir          = vir.left();
                    vol          = vol.left();
                    vor          = vor.right();
                    vor.ancestor = v;
                    var shift = (vil.x + sil) - (vir.x + sir) + distance;
                    if (shift > 0)
                    {
                        move_subtree(get_ancestor(vil, v, default_ancestor), v, shift);
                        sir = sir + shift;
                        sor = sor + shift;
                    }
                    sil += vil.mod;
                    sir += vir.mod;
                    sol += vol.mod;
                    sor += vor.mod;
                }
                if (vil.right() && !vor.right())
                {
                    vor.thread = vil.right();
                    vor.mod   += sil - sor;
                }
                else
                {
                    if (vir.left() && !vol.left())
                    {
                        vol.thread = vir.left();
                        vol.mod   += sir - sol;
                    }
                    default_ancestor = v;
                }
            }
            return(default_ancestor);
        }
Esempio n. 7
0
 public BuchheimNode(BuchNodeWrapper node, BuchheimNode parent = null, int depth = 0, int number = 1)
 {
     this.x        = -1;
     this.y        = depth;
     this.node     = node;
     this.children = node
                     .Select((c, i) => new BuchheimNode(c, this, depth + 1, i + 1))
                     .ToArray();
     this.parent         = parent;
     this.thread         = null;
     this.mod            = 0;
     this.ancestor       = this;
     this.change         = 0;
     this.shift          = 0;
     this._lmost_sibling = null;
     this.number         = number;
 }
Esempio n. 8
0
        static float?second_walk(BuchheimNode v, float m = 0, int depth = 0, float?min = null)
        {
            v.x += m;
            v.y  = depth;

            if (min == null || v.x < min)
            {
                min = v.x;
            }

            foreach (var w in v.children)
            {
                min = second_walk(w, m + v.mod, depth + 1, min);
            }

            return(min);
        }
Esempio n. 9
0
        public BuchheimNode lbrother()
        {
            BuchheimNode n = null;

            if (this.parent)
            {
                foreach (var node in this.parent.children)
                {
                    if (node == this)
                    {
                        return(n);
                    }
                    else
                    {
                        n = node;
                    }
                }
            }
            return(n);
        }
Esempio n. 10
0
        static BuchheimNode firstwalk(BuchheimNode v, float distance = 1)
        {
            if (v.children.Length == 0)
            {
                if (v.lmost_sibling)
                {
                    v.x = v.lbrother().x + distance;
                }
                else
                {
                    v.x = 0;
                }
            }
            else
            {
                var default_ancestor = v.children[0];
                foreach (var c in v.children)
                {
                    firstwalk(c);
                    default_ancestor = apportion(c, default_ancestor, distance);
                }
                execute_shifts(v);

                var midpoint = (v.children.First().x + v.children.Last().x) / 2f;

                var ell = v.children.First();
                var arr = v.children.Last();
                var w   = v.lbrother();
                if (w)
                {
                    v.x   = w.x + distance;
                    v.mod = v.x - midpoint;
                }
                else
                {
                    v.x = midpoint;
                }
            }

            return(v);
        }