]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
efe4bf30f137244cff9f06caf3c07d1355325d46
[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 #ifndef NDEBUG
23   
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
68
69 Atom::Atom ()
70   : dim_ (Interval (0,0),Interval (0,0))
71 {
72   str_ = "unknown\n";
73   origin_l_ = 0;
74 }
75
76 Atom::Atom (String s, Box b)
77   :  dim_ (b)
78 {
79   str_ = s;
80   origin_l_ = 0;  
81 }
82
83
84 String
85 Atom::str () const
86 {
87   return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", "
88     + dim_.y ().str () + "))";
89 }
90
91 Offset
92 Atom::offset () const
93 {
94   check_infinity_b ();
95   return off_;
96 }
97
98 void
99 Atom::translate_axis (Real r, Axis a)
100 {
101   off_[a] += r;
102   check_infinity_b ();
103 }
104
105 void
106 Atom::translate (Offset o)
107 {
108   off_ += o;
109   check_infinity_b ();
110 }
111
112 bool
113 Atom::empty() const
114 {
115   return (dim_.y().length() == 0);
116 }