source file of the GNU LilyPond music typesetter
- (c) 1997--2005 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+ (c) 1997--2006 Han-Wen Nienhuys <hanwen@xs4all.nl>
Jan Nieuwenhuizen <janneke@gnu.org>
*/
#include "lookup.hh"
-#include <math.h>
+#include <cmath>
#include <cctype>
+using namespace std;
#include "line-interface.hh"
#include "warn.hh"
Lookup::dot (Offset p, Real radius)
{
SCM at = (scm_list_n (ly_symbol2scm ("dot"),
- scm_make_real (p[X_AXIS]),
- scm_make_real (p[Y_AXIS]),
- scm_make_real (radius),
+ scm_from_double (p[X_AXIS]),
+ scm_from_double (p[Y_AXIS]),
+ scm_from_double (radius),
SCM_UNDEFINED));
Box box;
box.add_point (p - Offset (radius, radius));
return Stencil (box, at);
}
-/*
- * Horizontal Slope:
- *
- * /| ^
- * / | |
- * / | | height
- * / | |
- * / | v
- * | /
- * | /
- * (0, 0)x /slope = dy/dx
- * | /
- * |/
- *
- * <----->
- * width
- */
Stencil
Lookup::beam (Real slope, Real width, Real thick, Real blot)
{
- Real height = slope * width;
- Real min_y = (0 <? height) - thick / 2;
- Real max_y = (0 >? height) + thick / 2;
-
- Box b (Interval (0, width),
- Interval (min_y, max_y));
-
- SCM at = scm_list_n (ly_symbol2scm ("beam"),
- scm_make_real (width),
- scm_make_real (slope),
- scm_make_real (thick),
- scm_make_real (blot),
- SCM_UNDEFINED);
- return Stencil (b, at);
+ Box b;
+
+ Offset p;
+
+ p = Offset (0, thick / 2);
+ b.add_point (p);
+ p += Offset (1, -1) * (blot / 2);
+
+ SCM points = SCM_EOL;
+
+ points = scm_cons (scm_from_double (p[X_AXIS]),
+ scm_cons (scm_from_double (p[Y_AXIS]),
+ points));
+
+ p = Offset (0, -thick / 2);
+ b.add_point (p);
+ p += Offset (1, 1) * (blot / 2);
+
+ points = scm_cons (scm_from_double (p[X_AXIS]),
+ scm_cons (scm_from_double (p[Y_AXIS]),
+ points));
+
+ p = Offset (width, width * slope - thick / 2);
+ b.add_point (p);
+ p += Offset (-1, 1) * (blot / 2);
+
+ points = scm_cons (scm_from_double (p[X_AXIS]),
+ scm_cons (scm_from_double (p[Y_AXIS]),
+ points));
+
+ p = Offset (width, width * slope + thick / 2);
+ b.add_point (p);
+ p += Offset (-1, -1) * (blot / 2);
+
+ points = scm_cons (scm_from_double (p[X_AXIS]),
+ scm_cons (scm_from_double (p[Y_AXIS]),
+ points));
+
+ SCM expr = scm_list_n (ly_symbol2scm ("polygon"),
+ ly_quote_scm (points),
+ scm_from_double (blot),
+ SCM_BOOL_T,
+ SCM_UNDEFINED);
+
+ return Stencil (b, expr);
}
Stencil
Real off = dash_period - on;
for (int i = 4; i--;)
- {
- l = scm_cons (ly_offset2scm (b.control_[i]), l);
- }
+ l = scm_cons (ly_offset2scm (b.control_[i]), l);
SCM at = (scm_list_n (ly_symbol2scm ("dashed-slur"),
- scm_make_real (thick),
- scm_make_real (on),
- scm_make_real (off),
+ scm_from_double (thick),
+ scm_from_double (on),
+ scm_from_double (off),
ly_quote_scm (l),
SCM_UNDEFINED));
Stencil
Lookup::horizontal_line (Interval w, Real th)
{
- SCM at = scm_list_n (ly_symbol2scm ("horizontal-line"),
- scm_make_real (w[LEFT]),
- scm_make_real (w[RIGHT]),
- scm_make_real (th),
+ SCM at = scm_list_n (ly_symbol2scm ("draw-line"),
+ scm_from_double (th),
+ scm_from_double (w[LEFT]),
+ scm_from_double (0),
+ scm_from_double (w[RIGHT]),
+ scm_from_double (0),
SCM_UNDEFINED);
Box box;
Stencil
Lookup::filled_box (Box b)
{
- SCM at = (scm_list_n (ly_symbol2scm ("filledbox"),
- scm_make_real (-b[X_AXIS][LEFT]),
- scm_make_real (b[X_AXIS][RIGHT]),
- scm_make_real (-b[Y_AXIS][DOWN]),
- scm_make_real (b[Y_AXIS][UP]),
- SCM_UNDEFINED));
-
- return Stencil (b, at);
+ return round_filled_box (b, 0.0);
}
/*
Lookup::round_filled_box (Box b, Real blotdiameter)
{
if (b.x ().length () < blotdiameter)
- {
- blotdiameter = b.x ().length ();
- }
+ blotdiameter = b.x ().length ();
if (b.y ().length () < blotdiameter)
- {
- blotdiameter = b.y ().length ();
- }
+ blotdiameter = b.y ().length ();
SCM at = (scm_list_n (ly_symbol2scm ("round-filled-box"),
- scm_make_real (-b[X_AXIS][LEFT]),
- scm_make_real (b[X_AXIS][RIGHT]),
- scm_make_real (-b[Y_AXIS][DOWN]),
- scm_make_real (b[Y_AXIS][UP]),
- scm_make_real (blotdiameter),
+ scm_from_double (-b[X_AXIS][LEFT]),
+ scm_from_double (b[X_AXIS][RIGHT]),
+ scm_from_double (-b[Y_AXIS][DOWN]),
+ scm_from_double (b[Y_AXIS][UP]),
+ scm_from_double (blotdiameter),
SCM_UNDEFINED));
return Stencil (b, at);
* shrinked polygon). --jr
*/
Stencil
-Lookup::round_filled_polygon (Array<Offset> points, Real blotdiameter)
+Lookup::round_filled_polygon (Array<Offset> const &points,
+ Real blotdiameter)
{
/* TODO: Maybe print a warning if one of the above limitations
applies to the given polygon. However, this is quite complicated
to check. */
- /* remove consecutive duplicate points */
const Real epsilon = 0.01;
- for (int i = 0; i < points.size ();)
+
+#ifndef NDEBUG
+ /* remove consecutive duplicate points */
+ for (int i = 0; i < points.size (); i++)
{
int next_i = (i + 1) % points.size ();
Real d = (points[i] - points[next_i]).length ();
if (d < epsilon)
- points.del (next_i);
- else
- i++;
+ programming_error ("Polygon should not have duplicate points");
}
+#endif
/* special cases: degenerated polygons */
if (points.size () == 0)
return Line_interface::make_line (blotdiameter, points[0], points[1]);
/* shrink polygon in size by 0.5 * blotdiameter */
- Array<Offset> shrinked_points;
- shrinked_points.set_size (points.size ());
+ Array<Offset> shrunk_points;
+ shrunk_points.set_size (points.size ());
bool ccw = 1; // true, if three adjacent points are counterclockwise ordered
for (int i = 0; i < points.size (); i++)
{
}
else
p13 = (0.5 * blotdiameter / d) * p13n;
- shrinked_points[i1] = p1 + ((ccw) ? p13 : -p13);
+ shrunk_points[i1] = p1 + ((ccw) ? p13 : -p13);
}
/* build scm expression and bounding box */
- SCM shrinked_points_scm = SCM_EOL;
+ SCM shrunk_points_scm = SCM_EOL;
Box box;
- for (int i = 0; i < shrinked_points.size (); i++)
+ for (int i = 0; i < shrunk_points.size (); i++)
{
- SCM x = scm_make_real (shrinked_points[i][X_AXIS]);
- SCM y = scm_make_real (shrinked_points[i][Y_AXIS]);
- shrinked_points_scm = scm_cons (x, scm_cons (y, shrinked_points_scm));
+ SCM x = scm_from_double (shrunk_points[i][X_AXIS]);
+ SCM y = scm_from_double (shrunk_points[i][Y_AXIS]);
+ shrunk_points_scm = scm_cons (x, scm_cons (y, shrunk_points_scm));
box.add_point (points[i]);
}
SCM polygon_scm = scm_list_n (ly_symbol2scm ("polygon"),
- ly_quote_scm (shrinked_points_scm),
- scm_make_real (blotdiameter),
+ ly_quote_scm (shrunk_points_scm),
+ scm_from_double (blotdiameter),
+ SCM_BOOL_T,
SCM_UNDEFINED);
Stencil polygon = Stencil (box, polygon_scm);
- shrinked_points.clear ();
+ shrunk_points.clear ();
return polygon;
}
SCM scontrols[8];
- for (int i =4; i--;)
- scontrols[ i ] = ly_offset2scm (back.control_[i]);
- for (int i =4; i--;)
+ for (int i = 0; i < 4; i++)
+ scontrols[i] = ly_offset2scm (back.control_[i]);
+ for (int i = 0; i < 4; i++)
scontrols[i + 4] = ly_offset2scm (curve.control_[i]);
/*
Need the weird order b.o. the way PS want its arguments
*/
- int indices[]= {5, 6, 7, 4, 1, 2, 3, 0};
+ int indices[] = {5, 6, 7, 4, 1, 2, 3, 0};
SCM list = SCM_EOL;
for (int i = 8; i--;)
- {
- list = scm_cons (scontrols[indices[i]], list);
- }
+ list = scm_cons (scontrols[indices[i]], list);
SCM at = (scm_list_n (ly_symbol2scm ("bezier-sandwich"),
ly_quote_scm (list),
- scm_make_real (linethick),
+ scm_from_double (linethick),
SCM_UNDEFINED));
Box b (curve.extent (X_AXIS),
curve.extent (Y_AXIS));
SCM horizontal_bend = scm_list_n (ly_symbol2scm ("bezier-sandwich"),
ly_quote_scm (list),
- scm_make_real (0.0),
+ scm_from_double (0.0),
SCM_UNDEFINED);
Interval x_extent = top_curve.extent (X_AXIS);
Stencil
Lookup::repeat_slash (Real w, Real s, Real t)
{
- SCM wid = scm_make_real (w);
- SCM sl = scm_make_real (s);
- SCM thick = scm_make_real (t);
+#if 0 /* TODO */
+ Array<Offset> points;
+ Real blotdiameter = 0.0;
+
+ Offset p1 (0, 0);
+ Offset p2 (w, w * s);
+
+ return Lookup::round_filled_polygon (points, blotdiameter);
+#endif
+
+ SCM wid = scm_from_double (w);
+ SCM sl = scm_from_double (s);
+ SCM thick = scm_from_double (t);
SCM slashnodot = scm_list_n (ly_symbol2scm ("repeat-slash"),
wid, sl, thick, SCM_UNDEFINED);
{
Box b;
b[X_AXIS] = Interval (0, iv.length ());
- b[Y_AXIS] = Interval (0 <? protude, 0 >? protude);
+ b[Y_AXIS] = Interval (min (0., protude), max (0.0, protude));
Offset z1 (iv[LEFT], 0);
Offset z2 (iv[RIGHT], 0);