X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;ds=sidebyside;f=lily%2Fdimension-cache.cc;h=6fc99bde284f48bee45184eeb3a604d4ffaa5edf;hb=0f7b7e90fb80f52206e3bca71357eb2a4d481235;hp=8746337cca4b96bac67fd08dfcb7cd38726fed47;hpb=afa5829cd270e1b0c616b7ba5c5e6cdc0e920e5f;p=lilypond.git diff --git a/lily/dimension-cache.cc b/lily/dimension-cache.cc index 8746337cca..6fc99bde28 100644 --- a/lily/dimension-cache.cc +++ b/lily/dimension-cache.cc @@ -3,7 +3,7 @@ source file of the GNU LilyPond music typesetter - (c) 1998 Han-Wen Nienhuys + (c) 1998--1999 Han-Wen Nienhuys */ #include "dimension-cache.hh" @@ -12,7 +12,9 @@ Dimension_cache::Dimension_cache (Dimension_cache const &d) { init(); + callback_l_ = d.callback_l_; empty_b_ = d.empty_b_; + offset_ = d.offset_; //let's hope others will copy the refpoint appropriately. } Dimension_cache::Dimension_cache () @@ -23,6 +25,7 @@ Dimension_cache::Dimension_cache () void Dimension_cache::init() { + callback_l_ =0; offset_ =0.0; elt_l_ = 0; dim_.set_empty (); @@ -66,46 +69,36 @@ Dimension_cache::translate (Real x) offset_ += x; } - -Real -Dimension_cache::absolute_coordinate () const -{ - Real r = offset_; - for (Dimension_cache * c = parent_l_; - c; c = c->parent_l_) - r += c->offset_; - return r; -} - Real -Dimension_cache::relative_coordinate (Dimension_cache *d) const +Dimension_cache::relative_coordinate (Dimension_cache *refp) const { - Real r =0.0; - - for (Dimension_cache* c = parent_l_; - c != d; - c = c->parent_l_) - r += c->offset_; - return r; + if (refp == this) + return 0.0; + + /* + We catch PARENT_L_ == nil case with this, but we crash if we did + not ask for the absolute coordinate (ie. REFP == nil.) + + */ + if (refp == parent_l_) + return offset_; + else + return offset_ + parent_l_->relative_coordinate (refp); } Dimension_cache * -Dimension_cache::common_group (Dimension_cache const* s) const +Dimension_cache::common_refpoint (Dimension_cache const* s) const { - Link_array my_groups; - for (Dimension_cache const *c = this; - c ; c = c->parent_l_) - my_groups.push (c); - + Link_array my_groups; + for (Dimension_cache const *c = this; c ; c = c->parent_l_) + my_groups.push ((Dimension_cache*)c); Dimension_cache const *common=0; - for (Dimension_cache const * d = s; - !common && d; - d = d->parent_l_) - common = my_groups.find_l (d); + for (Dimension_cache const * d = s; !common && d; d = d->parent_l_) + common = (Dimension_cache const*)my_groups.find_l (d); - return (Dimension_cache*)common; + return (Dimension_cache*) common; } @@ -121,14 +114,6 @@ Dimension_cache::set_empty (bool b) } } -void -Dimension_cache::set_dim (Interval v) -{ - dim_ = v; - valid_b_ = true; -} - - Interval Dimension_cache::get_dim () const { @@ -139,13 +124,21 @@ Dimension_cache::get_dim () const return r; } - assert (valid_b_); + if (!valid_b_) + { + Dimension_cache *nc = ((Dimension_cache*)this); + nc->dim_= (*callback_l_ ) (nc); + nc->valid_b_ = true; + } r=dim_; - if (!r.empty_b()) // float exception on DEC Alpha - r += offset_; return r; } +void +Dimension_cache::set_callback (Dim_cache_callback c) +{ + callback_l_ =c; +}