]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system-scheme.cc
Merge branch 'master' of ssh://kainhofer@git.sv.gnu.org/srv/git/lilypond into dev...
[lilypond.git] / lily / paper-system-scheme.cc
1 /* 
2   paper-system-scheme.cc -- implement Paper_system bindings.
3   
4   source file of the GNU LilyPond music typesetter
5   
6   (c) 2008 Han-Wen Nienhuys <hanwen@lilypond.org>
7   
8 */
9
10 #include "prob.hh"
11
12 #include "skyline-pair.hh"
13   
14 LY_DEFINE (ly_paper_system_p, "ly:paper-system?",
15           1, 0, 0, (SCM obj),
16           "Type predicate.")
17 {
18   return ly_prob_type_p (obj, ly_symbol2scm ("paper-system"));
19 }
20
21 LY_DEFINE (ly_paper_system_minimum_distance, "ly:paper-system-minimum-distance",
22            2, 0, 0, (SCM sys1, SCM sys2),
23            "Measure the minimum distance between these two paper-systems,"
24            " using their stored skylines if possible and falling back to"
25            " their extents otherwise.")
26 {
27   Real ret = 0;
28   Prob *p1 = unsmob_prob (sys1);
29   Prob *p2 = unsmob_prob (sys2);
30   Skyline_pair *sky1 = Skyline_pair::unsmob (p1->get_property ("vertical-skylines"));
31   Skyline_pair *sky2 = Skyline_pair::unsmob (p2->get_property ("vertical-skylines"));
32
33   if (sky1 && sky2)
34     ret = (*sky1)[DOWN].distance ((*sky2)[UP]);
35   else
36     {
37       Stencil *s1 = unsmob_stencil (p1->get_property ("stencil"));
38       Stencil *s2 = unsmob_stencil (p2->get_property ("stencil"));
39       Interval iv1 = s1->extent (Y_AXIS);
40       Interval iv2 = s2->extent (Y_AXIS);
41       ret = iv2[UP] - iv1[DOWN];
42     }
43   return scm_from_double (ret);
44 }