]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 1.0.1
[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 "tex.hh"
12 #include "interval.hh"
13 #include "dimension.hh"
14 #include "string.hh"
15 #include "array.hh"
16 #include "debug.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                    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 << "texstring: " << tex_ << '\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   tex_ = "\\unknown";
73 }
74
75 Atom::Atom (String s, Box b)
76   :  dim_ (b)
77 {
78   tex_ = s;
79 }
80
81
82 String
83 Atom::str() const
84 {
85   return String ("Atom (\'") + tex_ + "\', (" + dim_.x().str () + ", "
86     + dim_.y ().str () + "))";
87 }
88
89 Offset
90 Atom::offset () const
91 {
92   return off_;
93 }
94
95
96
97 void
98 Atom::translate_axis (Real r, Axis a)
99 {
100   off_[a] += r;
101   check_infinity_b ();
102 }
103
104 void
105 Atom::translate (Offset o)
106 {
107   off_ += o;
108   check_infinity_b ();
109 }