2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "molecule.hh"
15 #include "killing-cons.tcc"
18 #define MOL_EOL SCM_EOL
19 #define NEXT_CELL(a) gh_cdr(a)
21 #define UNBOX_ATOM(a) Atom::atom_l (a)
22 #define BOX_ATOM(a) a->make_smob ()
23 #define NEWCELL(a,b) gh_cons (a,b)
24 #define UNBOX_PTR(a) gh_car (a)
27 #define NEXT_CELL(a) ptr->next_
28 #define CELLTYPE Cons<Atom>*
29 #define UNBOX_ATOM(a) a
30 #define UNBOX_PTR(a) a->car_
32 #define NEWCELL(a,b) new Killing_cons<Atom>(a,b)
36 Molecule::extent() const
42 Molecule::extent(Axis a
) const
48 Molecule::translate (Offset o
)
50 for (CELLTYPE ptr
= atom_list_
; ptr
!= MOL_EOL
; ptr
= NEXT_CELL(ptr
))
52 UNBOX_ATOM(UNBOX_PTR(ptr
))->off_
+= o
;
59 Molecule::translate_axis (Real x
,Axis a
)
61 for (CELLTYPE ptr
= atom_list_
; ptr
!= MOL_EOL
; ptr
= NEXT_CELL(ptr
))
62 UNBOX_ATOM (UNBOX_PTR(ptr
))->off_
[a
] += x
;
64 if (!dim_
[a
].empty_b ())
69 Molecule::add_molecule (Molecule
const &m
)
71 for (CELLTYPE ptr
= m
.atom_list_
; ptr
!= MOL_EOL
; ptr
= NEXT_CELL(ptr
))
72 add_atom(UNBOX_ATOM (UNBOX_PTR(ptr
)));
78 Molecule::add_atom (Atom
const *al
)
80 Atom
*a
= new Atom(*al
);
82 atom_list_
= NEWCELL(BOX_ATOM(a
), atom_list_
);
86 Molecule::operator=(Molecule
const & src
)
88 if (&src
== this) return;
100 Molecule::set_empty (bool e
)
104 dim_
[X_AXIS
].set_empty ();
105 dim_
[Y_AXIS
].set_empty ();
109 dim_
[X_AXIS
] = Interval(0,0);
110 dim_
[Y_AXIS
] = Interval (0,0);
114 Molecule::Molecule (Molecule
const &s
)
116 atom_list_
= MOL_EOL
;
121 Molecule::~Molecule ()
129 Molecule::print() const
132 if (! flower_dstream
)
135 for (Axis i
=X_AXIS
; i
< NO_AXES
; incr (i
))
136 DEBUG_OUT
<< axis_name_str (i
) << " = " << dim_
[i
].str ();
141 Molecule::align_to (Axis a
, Direction d
)
145 Interval
i (extent (a
));
146 translate_axis (-i
.center (), a
);
150 translate_axis (-extent (a
)[d
], a
);
154 Molecule::Molecule ()
156 dim_
[X_AXIS
].set_empty ();
157 dim_
[Y_AXIS
].set_empty ();
158 atom_list_
= MOL_EOL
;
163 Molecule::add_at_edge (Axis a
, Direction d
, Molecule
const &m
, Real padding
)
165 Real my_extent
= empty_b () ? 0.0 : dim_
[a
][d
];
166 Interval
i (m
.extent ()[a
]);
168 programming_error ("Molecule::add_at_edge: adding empty molecule.");
170 Real his_extent
= i
[-d
];
171 Real offset
= my_extent
- his_extent
;
173 toadd
.translate_axis (offset
+ d
* padding
, a
);
174 add_molecule (toadd
);
178 Molecule::empty_b () const
180 return atom_list_
== MOL_EOL
;