X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=lily%2Fgrob.cc;h=d36a6721301430fcae21ae84f268c089c423aaaf;hb=59c56667425ec6fae59655cf01ee724e024c0ebd;hp=fa8e1f684307453ec9d90b1d4998c9747b2e212a;hpb=4f49b000d6e257724e311b406e2346b8388c1f0e;p=lilypond.git diff --git a/lily/grob.cc b/lily/grob.cc index fa8e1f6843..d36a672130 100644 --- a/lily/grob.cc +++ b/lily/grob.cc @@ -483,8 +483,6 @@ Grob::pure_height (Grob *refp, int start, int end) Interval Grob::maybe_pure_extent (Grob *refp, Axis a, bool pure, int start, int end) { - if (pure && a != Y_AXIS) - programming_error ("tried to get pure width"); return (pure && a == Y_AXIS) ? pure_height (refp, start, end) : extent (refp, a); } @@ -515,15 +513,39 @@ Grob::less (Grob *g1, Grob *g2) Grob * Grob::common_refpoint (Grob const *s, Axis a) const { - /* I don't like the quadratic aspect of this code, but I see no - other way. The largest chain of parents might be 10 high or so, - so it shouldn't be a real issue. */ - for (Grob const *c = this; c; c = c->dim_cache_[a].parent_) - for (Grob const *d = s; d; d = d->dim_cache_[a].parent_) - if (d == c) - return (Grob *) d; - return 0; + /* Catching the trivial cases is likely costlier than just running + through: one can't avoid going to the respective chain ends + anyway. We might save the second run through when the chain ends + differ, but keeping track of the ends makes the loop more costly. + */ + + int balance = 0; + Grob const *c; + Grob const *d; + + for (c = this; c; ++balance) + c = c->dim_cache_[a].parent_; + + for (d = s; d; --balance) + d = d->dim_cache_[a].parent_; + + /* Cut down ancestry to same size */ + + for (c = this; balance > 0; --balance) + c = c->dim_cache_[a].parent_; + + for (d = s; balance < 0; ++balance) + d = d->dim_cache_[a].parent_; + + /* Now find point where our lineages converge */ + while (c != d) + { + c = c->dim_cache_[a].parent_; + d = d->dim_cache_[a].parent_; + } + + return (Grob *) c; } void @@ -576,7 +598,7 @@ Grob::fixup_refpoint () VERTICAL ORDERING ****************************************************************/ -Grob* +Grob * get_maybe_root_vertical_alignment (Grob *g, Grob *maybe) { if (!g) @@ -587,13 +609,13 @@ get_maybe_root_vertical_alignment (Grob *g, Grob *maybe) } -Grob* +Grob * Grob::get_root_vertical_alignment (Grob *g) { return get_maybe_root_vertical_alignment (g, 0); } -Grob* +Grob * Grob::get_vertical_axis_group (Grob *g) { if (!g) @@ -622,6 +644,18 @@ Grob::get_vertical_axis_group_index (Grob *g) bool Grob::vertical_less (Grob *g1, Grob *g2) +{ + return internal_vertical_less (g1, g2, false); +} + +bool +Grob::pure_vertical_less (Grob *g1, Grob *g2) +{ + return internal_vertical_less (g1, g2, true); +} + +bool +Grob::internal_vertical_less (Grob *g1, Grob *g2, bool pure) { Grob *vag = get_root_vertical_alignment (g1); if (!vag) @@ -636,6 +670,12 @@ Grob::vertical_less (Grob *g1, Grob *g2) extract_grob_set (vag, "elements", elts); + if (ag1 == ag2 && !pure) + { + Grob *common = g1->common_refpoint (g2, Y_AXIS); + return g1->relative_coordinate (common, Y_AXIS) > g2->relative_coordinate (common, Y_AXIS); + } + for (vsize i = 0; i < elts.size (); i++) { if (elts[i] == ag1) @@ -746,6 +786,7 @@ ADD_INTERFACE (Grob, "extra-X-extent " "extra-Y-extent " "extra-offset " + "forced-spacing " "interfaces " "layer " "meta "