5 #include "leastsquares.hh"
21 Stem_info(const Stem*);
23 Stem_info::Stem_info(const Stem*s)
27 idealy = MAX(dir*s->top, dir*s->bot);
28 miny = MAX(dir*s->minnote, dir*s-> maxnote);
29 assert(miny <= idealy);
45 stems.bottom().add(s);
46 s->print_flag = false;
50 Beam::set_default_dir()
53 dirs[0]=0; dirs[1] =0;
54 for (PCursor<Stem*> sc(stems); sc.ok(); sc++) {
55 sc->set_default_dir();
56 dirs[(sc->dir+1)/2] ++;
58 dir = (dirs[0] > dirs[1]) ? -1 : 1;
59 for (PCursor<Stem*> sc(stems); sc.ok(); sc++) {
64 should use minimum energy formulation (cf linespacing)
69 svec<Stem_info> sinfo;
70 for (PCursor<Stem* >sc(stems); sc.ok(); sc++) {
71 sc->set_default_extents();
75 Real leftx = sinfo[0].x;
77 for (int i=0; i < sinfo.sz(); i++) {
79 l.input.add(Offset(sinfo[i].x, sinfo[i].idealy));
82 l.minimise(slope, left_pos);
84 for (int i=0; i < sinfo.sz(); i++) {
85 Real y = sinfo[i].x * slope + left_pos;
86 Real my = sinfo[i].miny;
96 Real inter =paper()->interline()/2;
97 Real unitslope = slope*inter;
99 // set beamslope, for setting stems correctly
101 Symbol sy = paper()->lookup_->beam(unitslope, width().length());
102 slope =unitslope / inter;
109 PCursor<Stem*> s(stems);
111 for (; s.ok() ; s++) {
112 Real x = s->hpos()-x0;
113 s->set_stemend(left_pos + slope * x);
120 assert(stems.size()>1);
138 Beam::broken_at(const PCol *, const PCol *) const
140 return new Beam(*this);
146 left = (*stems.top()) ->pcol_;
147 right = (*stems.bottom())->pcol_;
153 return output->extent().y;
159 Beam * me = (Beam*) this; // ugh
160 return Interval( (*me->stems.top()) ->hpos(),
161 (*me->stems.bottom()) ->hpos() );
165 Beam::brew_molecule()
167 Real inter=paper()->interline()/2;
168 Real sl = slope*inter;
169 Real w = width().length() + paper()->rule_thickness();
170 Symbol s = paper()->lookup_->beam(sl,w);
174 Real dx = width().min -left->hpos;
175 a.translate(Offset(dx,left_pos*inter));
176 output = new Molecule(a);
182 mtor << "Beam, slope " <<slope << "left ypos " << left_pos<<'\n';