source file of the GNU LilyPond music typesetter
- (c) 2006--2007 Joe Neeman <joeneeman@gmail.com>
+ (c) 2006--2009 Joe Neeman <joeneeman@gmail.com>
*/
#include "skyline.hh"
#include <deque>
+#include <cstdio>
#include "ly-smobs.icc"
print_buildings (buildings_);
}
+void
+Skyline::print_points () const
+{
+ vector<Offset> ps (to_points (X_AXIS));
+
+ for (vsize i = 0; i < ps.size (); i++)
+ printf ("(%f,%f)%s" , ps[i][X_AXIS], ps[i][Y_AXIS],
+ (i%2)==1 ? "\n" : " ");
+}
+
Building::Building (Real start, Real start_height, Real end_height, Real end)
{
if (isinf (start) || isinf (end))
/* their slopes were not equal, so there is an intersection point */
Real i = intersection_x (other);
- return (i < x && slope_ > other.slope_)
+ return (i <= x && slope_ > other.slope_)
|| (i > x && slope_ < other.slope_);
}
Skyline::internal_merge_skyline (list<Building> *s1, list<Building> *s2,
list<Building> *const result)
{
+ if (s1->empty () || s2->empty ())
+ {
+ programming_error ("tried to merge an empty skyline");
+ return;
+ }
+
Real x = -infinity_f;
while (!s1->empty ())
{
}
if (iv[LEFT] - horizon_padding > last_end + EPS)
- result.push_front (Building (last_end, -infinity_f, -infinity_f, iv[LEFT] - horizon_padding));
+ result.push_front (Building (last_end, -infinity_f, -infinity_f, iv[LEFT] - 2*horizon_padding));
Building b (*i, horizon_padding, horizon_axis, sky);
bool sloped_neighbours = horizon_padding > 0 && !isinf (iv.length ());
{
list<Building> result;
single_skyline (Building (boxes->front (), horizon_padding, horizon_axis, sky),
- boxes->front ()[horizon_axis][LEFT], horizon_axis, &result);
+ boxes->front ()[horizon_axis][LEFT], horizon_padding, &result);
return result;
}
Skyline::Skyline ()
{
sky_ = UP;
- empty_skyline (&buildings_);
+ empty_skyline (&buildings_);
}
Skyline::Skyline (Skyline const &src)
list<Building> other_bld;
list<Building> my_bld;
+ if (isnan (b[other_axis (a)][LEFT])
+ || isnan (b[other_axis (a)][RIGHT]))
+ {
+ programming_error ("insane box for skyline");
+ return;
+ }
+
+ /* do the same filtering as in Skyline (vector<Box> const&, etc.) */
+ Interval iv = b[a];
+ iv.widen (horizon_padding);
+ if (iv.length () <= EPS || b[other_axis (a)].is_empty ())
+ return;
+
my_bld.splice (my_bld.begin (), buildings_);
single_skyline (Building (b, horizon_padding, a, sky_), b[a][LEFT], horizon_padding, &other_bld);
internal_merge_skyline (&other_bld, &my_bld, &buildings_);
vector<Offset>
-Skyline::to_points (Axis a) const
+Skyline::to_points (Axis horizon_axis) const
{
vector<Offset> out;
start = i->end_;
}
- if (a == Y_AXIS)
+ if (horizon_axis == Y_AXIS)
for (vsize i = 0; i < out.size (); i++)
- out[i] = Offset (out[i][Y_AXIS], out[i][X_AXIS]);
+ out[i] = out[i].swapped ();
return out;
}
bool
Skyline::is_empty () const
{
- return buildings_.empty ();
-}
-
-Skyline_pair::Skyline_pair ()
- : skylines_ (Skyline (DOWN), Skyline (UP))
-{
-}
-
-Skyline_pair::Skyline_pair (vector<Box> const &boxes, Real padding, Axis a)
- : skylines_ (Skyline (boxes, padding, a, DOWN), Skyline (boxes, padding, a, UP))
-{
-}
-
-Skyline_pair::Skyline_pair (Box const &b, Real padding, Axis a)
- : skylines_ (Skyline (b, padding, a, DOWN), Skyline (b, padding, a, UP))
-{
-}
-
-void
-Skyline_pair::raise (Real r)
-{
- skylines_[UP].raise (r);
- skylines_[DOWN].raise (r);
-}
-
-void
-Skyline_pair::shift (Real r)
-{
- skylines_[UP].shift (r);
- skylines_[DOWN].shift (r);
+ Building b = buildings_.front ();
+ return b.end_ == infinity_f && b.y_intercept_ == -infinity_f;
}
-void
-Skyline_pair::insert (Box const &b, Real padding, Axis a)
-{
- skylines_[UP].insert (b, padding, a);
- skylines_[DOWN].insert (b, padding, a);
-}
-
-void
-Skyline_pair::merge (Skyline_pair const &other)
-{
- skylines_[UP].merge (other[UP]);
- skylines_[DOWN].merge (other[DOWN]);
-}
-
-bool
-Skyline_pair::is_empty () const
-{
- return skylines_[UP].is_empty ()
- && skylines_[DOWN].is_empty ();
-}
-
-Skyline&
-Skyline_pair::operator [] (Direction d)
-{
- return skylines_[d];
-}
-
-Skyline const&
-Skyline_pair::operator [] (Direction d) const
-{
- return skylines_[d];
-}
/****************************************************************/
IMPLEMENT_TYPE_P (Skyline, "ly:skyline?");
IMPLEMENT_DEFAULT_EQUAL_P (Skyline);
-IMPLEMENT_SIMPLE_SMOBS (Skyline_pair);
-IMPLEMENT_TYPE_P (Skyline_pair, "ly:skyline-pair?");
-IMPLEMENT_DEFAULT_EQUAL_P (Skyline_pair);
-
SCM
Skyline::mark_smob (SCM)
{
return 1;
}
-
-SCM
-Skyline_pair::mark_smob (SCM)
-{
- return SCM_EOL;
-}
-
-int
-Skyline_pair::print_smob (SCM s, SCM port, scm_print_state *)
-{
- Skyline_pair *r = (Skyline_pair *) SCM_CELL_WORD_1 (s);
- (void) r;
-
- scm_puts ("#<Skyline-pair>", port);
- return 1;
-}