]> git.donarmstrong.com Git - lilypond.git/blob - lily/paper-system-scheme.cc
Web-ja: update introduction
[lilypond.git] / lily / paper-system-scheme.cc
1 /*
2   This file is part of LilyPond, the GNU music typesetter.
3
4   Copyright (C) 2008--2015 Han-Wen Nienhuys <hanwen@lilypond.org>
5
6
7   LilyPond is free software: you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation, either version 3 of the License, or
10   (at your option) any later version.
11
12   LilyPond is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16
17   You should have received a copy of the GNU General Public License
18   along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "prob.hh"
22
23 #include "skyline-pair.hh"
24
25 LY_DEFINE (ly_paper_system_p, "ly:paper-system?",
26            1, 0, 0, (SCM obj),
27            "Is @var{obj} a C++ @code{Prob} object of type"
28            " @code{paper-system}?")
29 {
30   return ly_prob_type_p (obj, ly_symbol2scm ("paper-system"));
31 }
32
33 LY_DEFINE (ly_paper_system_minimum_distance, "ly:paper-system-minimum-distance",
34            2, 0, 0, (SCM sys1, SCM sys2),
35            "Measure the minimum distance between these two paper-systems,"
36            " using their stored skylines if possible and falling back to"
37            " their extents otherwise.")
38 {
39   Real ret = 0;
40   Prob *p1 = unsmob<Prob> (sys1);
41   Prob *p2 = unsmob<Prob> (sys2);
42   Skyline_pair *sky1 = unsmob<Skyline_pair> (p1->get_property ("vertical-skylines"));
43   Skyline_pair *sky2 = unsmob<Skyline_pair> (p2->get_property ("vertical-skylines"));
44
45   if (sky1 && sky2)
46     ret = (*sky1)[DOWN].distance ((*sky2)[UP]);
47   else
48     {
49       Stencil *s1 = unsmob<Stencil> (p1->get_property ("stencil"));
50       Stencil *s2 = unsmob<Stencil> (p2->get_property ("stencil"));
51       Interval iv1 = s1->extent (Y_AXIS);
52       Interval iv2 = s2->extent (Y_AXIS);
53       ret = iv2[UP] - iv1[DOWN];
54     }
55   return scm_from_double (ret);
56 }