]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 1.1.24
[lilypond.git] / lily / atom.cc
1 /*
2   atom.cc -- implement Atom
3
4   source file of the GNU LilyPond music typesetter
5
6   (c)  1997--1998 Han-Wen Nienhuys <hanwen@cs.uu.nl>
7 */
8
9 #include "atom.hh"
10 #include "interval.hh"
11 #include "string.hh"
12 #include "array.hh"
13 #include "debug.hh"
14 #include "dimensions.hh"
15 #include "lookup.hh"
16 #include "main.hh"
17
18 inline bool
19 Atom::check_infinity_b ()const
20 {
21   bool ridiculous = false;
22   
23 #ifndef NDEBUG
24   /* infinity checks. */
25   for (int a = X_AXIS; a < NO_AXES; a++)
26     {
27       Axis ax = (Axis)a;
28       if (abs (off_[ax]) >= 100 CM)
29         {
30           warning (_f ("ridiculous dimension: %s, %s", axis_name_str (ax),
31                    print_dimen (off_[ax])));
32           
33           if (experimental_features_global_b)
34             assert (false);
35
36           ( (Atom*)this)->off_[ax] = 0.0;
37           ridiculous = true;
38         }
39     }
40 #endif
41   return ridiculous;
42 }
43
44
45 void
46 Atom::print () const
47 {
48 #ifndef NPRINT
49   DOUT << "string: " << str_ << '\n';
50
51   DOUT << "dim:";
52   for (Axis i=X_AXIS; i < NO_AXES; incr (i))
53     DOUT << axis_name_str (i) << " = " << dim_[i].str ();
54
55   DOUT << "\noffset: " << off_.str ();
56 #endif
57 }
58
59 Box
60 Atom::extent () const
61 {
62   Box b (dim_);
63   b.translate (off_);
64   return b;
65 }
66
67 Interval
68 Atom::extent (Axis a) const
69 {
70   return dim_[a] + off_[a];
71 }
72
73
74
75 Atom::Atom ()
76   : dim_ (Interval (0,0),Interval (0,0))
77 {
78   str_ = "unknown\n";
79   origin_l_ = 0;
80 }
81
82 Atom::Atom (String s, Box b)
83   :  dim_ (b)
84 {
85   str_ = s;
86   origin_l_ = 0;  
87 }
88
89
90 String
91 Atom::str () const
92 {
93   return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", "
94     + dim_.y ().str () + "))";
95 }
96
97 Offset
98 Atom::offset () const
99 {
100   check_infinity_b ();
101   return off_;
102 }
103
104 void
105 Atom::translate_axis (Real r, Axis a)
106 {
107   off_[a] += r;
108   check_infinity_b ();
109 }
110
111 void
112 Atom::translate (Offset o)
113 {
114   off_ += o;
115   check_infinity_b ();
116 }
117
118 bool
119 Atom::empty() const
120 {
121   return (dim_.y().length() == 0);
122 }