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;
100 PCursor<Stem*> s(stems);
102 for (; s.ok() ; s++) {
103 Real x = s->hpos()-x0;
104 s->set_stemend(left_pos + slope * x);
111 assert(stems.size()>1);
129 Beam::broken_at(const PCol *, const PCol *) const
131 return new Beam(*this);
137 left = (*stems.top()) ->pcol_;
138 right = (*stems.bottom())->pcol_;
144 return output->extent().y;
150 Beam * me = (Beam*) this; // ugh
151 return Interval( (*me->stems.top()) ->hpos(),
152 (*me->stems.bottom()) ->hpos() );
156 Beam::brew_molecule()
158 assert(left->line == right->line);
159 Real inter=paper()->internote();
160 Real sl = slope*inter;
161 Real w = width().length() + paper()->rule_thickness();
162 Symbol s = paper()->lookup_->beam(sl,w);
167 Real dx = width().min -left->hpos;
168 a.translate(Offset(dx,left_pos*inter));
169 output = new Molecule(a);
175 mtor << "Beam, slope " <<slope << "left ypos " << left_pos<<'\n';