]> git.donarmstrong.com Git - lilypond.git/blob - lily/pitch-interval.cc
Fix 537 (introduced in c0e7005ed202874f8ea67279e5c96ec53985c3fb)
[lilypond.git] / lily / pitch-interval.cc
1 /*
2   pitch-interval.cc -- implement Pitch_interval
3
4   source file of the GNU LilyPond music typesetter
5
6   (c) 2004--2007 Han-Wen Nienhuys <hanwen@xs4all.nl>
7 */
8
9 #include "pitch-interval.hh"
10
11 #include "interval.tcc"
12
13 Pitch_interval::Pitch_interval (Pitch p1, Pitch p2)
14 {
15   at (LEFT) = p1;
16   at (RIGHT) = p2;
17 }
18
19 Pitch_interval::Pitch_interval ()
20 {
21   at (LEFT) = Pitch (100, 0, 0);
22   at (RIGHT) = Pitch (-100, 0, 0);
23 }
24
25 bool
26 Pitch_interval::is_empty () const
27 {
28   return at (LEFT) > at (RIGHT);
29 }
30
31 Direction
32 Pitch_interval::add_point (Pitch p)
33 {
34   if (is_empty())
35     {
36       at (LEFT) = at (RIGHT) = p;
37       return CENTER;
38     }
39   else if (at (LEFT).tone_pitch () > p.tone_pitch ())
40     {
41       at (LEFT) = p;
42       return LEFT;
43     }
44   else if (at (RIGHT).tone_pitch () < p.tone_pitch ())
45     {
46       at (RIGHT) = p;
47       return RIGHT;
48     }
49   else
50     return CENTER;
51 }
52
53
54 Pitch_lexicographic_interval::Pitch_lexicographic_interval (Pitch p1, Pitch p2)
55 {
56   at (LEFT) = p1;
57   at (RIGHT) = p2;
58 }
59
60 Pitch_lexicographic_interval::Pitch_lexicographic_interval ()
61 {
62   at (LEFT) = Pitch (100, 0, 0);
63   at (RIGHT) = Pitch (-100, 0, 0);
64 }
65
66 bool
67 Pitch_lexicographic_interval::is_empty () const
68 {
69   return at (LEFT) > at (RIGHT);
70 }
71
72 Direction
73 Pitch_lexicographic_interval::add_point (Pitch p)
74 {
75   if (is_empty())
76     {
77       at (LEFT) = at (RIGHT) = p;
78       return CENTER;
79     }
80   else if (at (LEFT) > p)
81     {
82       at (LEFT) = p;
83       return LEFT;
84     }
85   else if (at (RIGHT) < p)
86     {
87       at (RIGHT) = p;
88       return RIGHT;
89     }
90   else
91     return CENTER;
92 }