Beispiel #1
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);
        }
Beispiel #2
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);
        }