]> git.donarmstrong.com Git - lilypond.git/blob - lily/atom.cc
release: 1.1.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 #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   /*
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_ = "unknown\n";
80   origin_l_ = 0;
81 }
82
83 Atom::Atom (String s, Box b)
84   :  dim_ (b)
85 {
86   str_ = s;
87   origin_l_ = 0;  
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 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 }