]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 1.0.17
[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   str_ = global_lookup_l->unknown_str ();
80 }
81
82 Atom::Atom (String s, Box b)
83   :  dim_ (b)
84 {
85   str_ = s;
86 }
87
88
89 String
90 Atom::str () const
91 {
92   return String ("Atom (\'") + str_ + "\', (" + dim_.x ().str () + ", "
93     + dim_.y ().str () + "))";
94 }
95
96 Offset
97 Atom::offset () const
98 {
99   return off_;
100 }
101
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 }