2 molecule.cc -- implement Molecule
4 source file of the GNU LilyPond music typesetter
6 (c) 1997--2000 Han-Wen Nienhuys <hanwen@cs.uu.nl>
10 ugh. Rewrite not finished yet. Still must copy atom lists.
15 #include "interval.hh"
17 #include "molecule.hh"
20 #include "killing-cons.tcc"
24 Molecule::extent() const
30 Molecule::extent(Axis a
) const
36 Molecule::translate (Offset o
)
38 if (isinf (o
.length ()))
40 programming_error ("Translating infinitely. Ignore.");
44 for (SCM ptr
= gh_cdr (atom_list_
); ptr
!= SCM_EOL
; ptr
= gh_cdr(ptr
))
46 gh_set_car_x (ptr
, translate_atom (o
, gh_car (ptr
)));
53 Molecule::translate_axis (Real x
,Axis a
)
57 programming_error ("Translating infinitely. Ignore.");
60 for (SCM ptr
= gh_cdr (atom_list_
); ptr
!= SCM_EOL
; ptr
= gh_cdr(ptr
))
62 gh_set_car_x (ptr
, translate_atom_axis (x
, a
, gh_car (ptr
)));
65 if (!dim_
[a
].empty_b ())
70 Molecule::add_molecule (Molecule
const &m
)
72 for (SCM ptr
= gh_cdr (m
.atom_list_
); ptr
!= SCM_EOL
; ptr
= gh_cdr(ptr
))
74 add_atom (gh_car (ptr
));
80 Molecule::add_atom (SCM atomsmob
)
82 gh_set_cdr_x (atom_list_
,
83 gh_cons (atomsmob
, gh_cdr (atom_list_
)));
87 Molecule::operator=(Molecule
const & src
)
92 atom_list_
= gh_cons (SCM_EOL
,scm_list_copy (gh_cdr (src
.atom_list_
)));
97 Molecule::set_empty (bool e
)
101 dim_
[X_AXIS
].set_empty ();
102 dim_
[Y_AXIS
].set_empty ();
106 dim_
[X_AXIS
] = Interval(0,0);
107 dim_
[Y_AXIS
] = Interval (0,0);
112 Molecule::print () const
115 for (SCM ptr
= gh_cdr (atom_list_
); ptr
!= SCM_EOL
; ptr
= gh_cdr(ptr
))
116 gh_display (gh_car (ptr
));
120 Molecule::Molecule (Molecule
const &s
)
122 atom_list_
= gh_cons (SCM_EOL
, scm_list_copy (gh_cdr (s
.atom_list_
)));
126 Molecule::~Molecule ()
132 Molecule::align_to (Axis a
, Direction d
)
136 Interval
i (extent (a
));
137 translate_axis (-i
.center (), a
);
141 translate_axis (-extent (a
)[d
], a
);
145 Molecule::Molecule ()
147 dim_
[X_AXIS
].set_empty ();
148 dim_
[Y_AXIS
].set_empty ();
149 atom_list_
= gh_cons (SCM_EOL
, SCM_EOL
);
154 Molecule::add_at_edge (Axis a
, Direction d
, Molecule
const &m
, Real padding
)
156 Real my_extent
= empty_b () ? 0.0 : dim_
[a
][d
];
157 Interval
i (m
.extent ()[a
]);
159 programming_error ("Molecule::add_at_edge: adding empty molecule.");
161 Real his_extent
= i
[-d
];
162 Real offset
= my_extent
- his_extent
;
164 toadd
.translate_axis (offset
+ d
* padding
, a
);
165 add_molecule (toadd
);
169 Molecule::empty_b () const
171 return gh_cdr (atom_list_
) == SCM_EOL
;