2 dimension-cache.cc -- implement Dimension_cache
4 source file of the GNU LilyPond music typesetter
6 (c) 1998--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "dimension-cache.hh"
13 #include "score-element.hh"
16 Dimension_cache::Dimension_cache (Dimension_cache const &d)
19 extent_callback_l_ = d.extent_callback_l_;
20 basic_offset_ = d.basic_offset_;
21 extra_offset_ = d.extra_offset_;
22 off_valid_b_ = d.off_valid_b_;
23 off_callbacks_ = d.off_callbacks_;
24 parent_l_ = d.parent_l_;
27 Dimension_cache::Dimension_cache ()
33 Dimension_cache::init()
35 extent_callback_l_ =0;
48 Dimension_cache::translate (Real x)
54 Dimension_cache::relative_coordinate (Dimension_cache *refp) const
60 We catch PARENT_L_ == nil case with this, but we crash if we did
61 not ask for the absolute coordinate (ie. REFP == nil.)
64 if (refp == parent_l_)
67 return get_offset () + parent_l_->relative_coordinate (refp);
71 Dimension_cache::axis () const
73 if (elt_l_-> dim_cache_[X_AXIS] == this)
80 Dimension_cache::get_offset () const
82 Dimension_cache *me = (Dimension_cache*) this;
83 while (off_callbacks_.size ())
85 Offset_cache_callback c = me->off_callbacks_[0];
86 me->off_callbacks_.del (0);
88 if (isinf (r) || isnan (r))
91 programming_error ("Infinity or NaN encountered");
93 me->basic_offset_ +=r;
95 return basic_offset_ + extra_offset_;
99 Dimension_cache::common_refpoint (Dimension_cache const* s) const
102 I don't like the quadratic aspect of this code. Maybe this should
103 be rewritten some time, but the largest chain of parents might be
104 10 high or so, so it shouldn't be a real issue. */
105 for (Dimension_cache const *c = this; c; c = c->parent_l_)
106 for (Dimension_cache const * d = s; d; d = d->parent_l_)
108 return (Dimension_cache*)d;
114 Dimension_cache::point_dimension_callback (Dimension_cache const* )
116 return Interval (0,0);
120 Dimension_cache::get_dim () const
123 Dimension_cache *nc = ((Dimension_cache*)this);
124 if (!extent_callback_l_)
126 nc->dim_.set_empty ();
130 nc->dim_= (*extent_callback_l_ ) (nc);
139 Dimension_cache::set_callback (Dim_cache_callback c)
141 extent_callback_l_ =c;