]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
3f79970b7154d1ad8f369db4c40ec088a7e7cfd8
[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
10 #include "atom.hh"
11 #include "interval.hh"
12 #include "string.hh"
13 #include "array.hh"
14 #include "debug.hh"
15 #include "dimensions.hh"
16 #include "lookup.hh"
17 #include "main.hh"
18
19 inline bool
20 Atom::check_infinity_b ()const
21 {
22   bool ridiculous = false;
23 #ifndef NDEBUG
24   
25   /* infinity checks. */
26   for (int a = X_AXIS; a < NO_AXES; a++)
27     {
28       Axis ax = (Axis)a;
29       if (abs (off_[ax]) >= 100 CM)
30         {
31           warning (_f ("ridiculous dimension: %s, %s", axis_name_str (ax),
32                    global_lookup_l->print_dimen (off_[ax])));
33           
34           if (experimental_features_global_b)
35             assert (false);
36
37           ( (Atom*)this)->off_[ax] = 0.0;
38           ridiculous = true;
39         }
40     }
41 #endif
42   return ridiculous;
43 }
44
45
46 void
47 Atom::print () const
48 {
49 #ifndef NPRINT
50   DOUT << "string: " << str_ << '\n';
51
52   DOUT << "dim:";
53   for (Axis i=X_AXIS; i < NO_AXES; incr (i))
54     DOUT << axis_name_str (i) << " = " << dim_[i].str ();
55
56   DOUT << "\noffset: " << off_.str ();
57 #endif
58 }
59
60 Box
61 Atom::extent () const
62 {
63   Box b (dim_);
64   b.translate (off_);
65   return b;
66 }
67
68
69 Atom::Atom ()
70   : dim_ (Interval (0,0),Interval (0,0))
71 {
72   /*
73     urg
74     We should probably make Atom an abstract base class to
75     derive Ps_atom and Tex_atom from.
76     But Atom is used as a simple type *everywhere*,
77     and we don't have virtual contructors.
78    */
79   lambda_ = 0;
80   str_ = global_lookup_l->unknown_str ();
81 }
82
83 Atom::Atom (String s, Box b)
84   :  dim_ (b)
85 {
86   lambda_ = 0;
87   str_ = s;
88 }
89
90
91 String
92 Atom::str () const
93 {
94   return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", "
95     + dim_.y ().str () + "))";
96 }
97
98 Offset
99 Atom::offset () const
100 {
101   return off_;
102 }
103
104
105
106 void
107 Atom::translate_axis (Real r, Axis a)
108 {
109   off_[a] += r;
110   check_infinity_b ();
111 }
112
113 void
114 Atom::translate (Offset o)
115 {
116   off_ += o;
117   check_infinity_b ();
118 }
119
120 bool
121 Atom::empty() const
122 {
123   return (dim_.y().length() == 0);
124 }