2 skyline.cc -- implement Skyline_entry and funcs.
4 source file of the GNU LilyPond music typesetter
6 (c) 2002 Han-Wen Nienhuys <hanwen@cs.uu.nl>
12 insert_extent_into_skyline (Array<Skyline_entry> *line, Box b, Axis line_axis,
15 Interval extent = b[line_axis];
19 Real stick_out = b[other_axis (line_axis)][d];
21 for (int i = line->size(); i--;)
23 Interval w = line->elem(i).width_;
24 if (extent[LEFT] > w[RIGHT])
28 Real my_height = line->elem(i).height_;
30 if (!w.empty_b () && d* (my_height - stick_out) < 0)
32 Interval e1 (line->elem(i).width_[LEFT], extent[LEFT]);
33 Interval e3 (extent[RIGHT], line->elem(i).width_[RIGHT]);
36 line->insert (Skyline_entry (e3, my_height), i+1);
38 line->elem_ref(i).height_ = stick_out;
39 line->elem_ref(i).width_ = w;
41 line->insert (Skyline_entry (e1, my_height), i );
49 extents_to_skyline (Array<Box> extents, Axis a, Direction d)
51 Array<Skyline_entry> skyline;
58 e.height_ = -d * infinity_f;
62 This makes a quadratic algorithm -- we could do better (n log (n) ) but that
63 seems overkill for now.
65 for (int j = extents.size(); j--; )
66 insert_extent_into_skyline (&skyline, extents[j], a, d);
73 minimum distance that can be achieved between baselines. "Clouds" is
74 a skyline pointing down.
77 skyline_meshing_distance (Array<Skyline_entry> buildings,
78 Array<Skyline_entry> clouds)
80 int i = buildings.size () -1;
81 int j = clouds.size() -1;
83 Real distance = - infinity_f;
85 while (i > 0 || j > 0)
87 Interval w = buildings[i].width_;
88 w.intersect(clouds[j].width_);
91 distance = distance >? (buildings[i].height_ - clouds[j].height_);
93 if (i>0 && buildings[i].width_[LEFT] >= clouds[j].width_[LEFT])
97 else if (j > 0 && buildings[i].width_[LEFT] <= clouds[j].width_[LEFT])
106 Skyline_entry::Skyline_entry()
111 Skyline_entry::Skyline_entry (Interval i, Real r)