+%
+% UGH: xs not declared as argument.
+%
+def define_triangle_shape (expr stemdir) =
+ save triangle_a, triangle_b, triangle_c;
+ save triangle_out_a, triangle_out_b, triangle_out_c;
+ save triangle_in, triangle_out;
+ save width, depth, height;
+ save origin, left_up_dir;
+ save exact_left_point, exact_right_point, exact_down_point;
+
+ path triangle_a, triangle_b, triangle_c;
+ path triangle_out_a, triangle_out_b, triangle_out_c;
+ path triangle_in, triangle_out;
+ pair origin, left_up_dir;
+ pair exact_down_point, exact_left_point, exact_right_point;
+
+ save pen_thick;
+ pen_thick# = stafflinethickness# + .1 staff_space#;
+ define_pixels (llap);
+ define_blacker_pixels (pen_thick);
+
+ left_up_dir = llap# * dir (90 + tilt);
+
+ xpart (left_up_dir) * xs - (pen_thick# * xs) / 2 + xpart origin = 0;
+ ypart origin = 0;
+
+ exact_left_point := origin + (left_up_dir xscaled xs);
+ exact_down_point := origin + (left_up_dir rotated 120 xscaled xs);
+ exact_right_point := origin + (left_up_dir rotated 240 xscaled xs);
+
+ height# = ypart (exact_left_point + origin) + pen_thick# / 2;
+ depth# = -ypart (exact_down_point + origin) + pen_thick# / 2;
+ width# = xpart (exact_right_point - exact_left_point)
+ + pen_thick# * xs;
+
+ set_char_box (0, width#, depth#, height#);
+
+ % Formerly, the shape has simply been drawn with an elliptical pen
+ % (`scaled pen_thick xscaled xs'), but the envelope of such a curve
+ % is of 6th degree. For the sake of mf2pt1, we approximate it.
+
+ pickup pencircle scaled pen_thick xscaled xs;
+
+ z0 = (hround_pixels (xpart origin), 0);
+
+ z1 = z1' = z0 + llap * dir (90 + tilt) xscaled xs;
+ z2 = z2' = z0 + llap * dir (90 + tilt + 120) xscaled xs;
+ z3 = z3' = z0 + llap * dir (90 + tilt + 240) xscaled xs;
+
+ z12 = caveness [.5[z1, z2], z3];
+ z23 = caveness [.5[z2, z3], z1];
+ z31 = caveness [.5[z3, z1], z2];
+
+ triangle_a = z1 .. z12 .. z2;
+ triangle_b = z2 .. z23 .. z3;
+ triangle_c = z3 .. z31 .. z1;
+
+ penposx1 (angle (direction 0 of triangle_a) - 90);
+ penposx2 (angle (direction 0 of triangle_b) - 90);
+ penposx3 (angle (direction 0 of triangle_c) - 90);
+
+ penposx1' (angle (direction infinity of triangle_c) + 90);
+ penposx2' (angle (direction infinity of triangle_a) + 90);
+ penposx3' (angle (direction infinity of triangle_b) + 90);
+
+ penposx12 (angle (z12 - z0));
+ penposx23 (angle (z23 - z0));
+ penposx31 (angle (z31 - z0));
+
+ z10 = (z0 -- z1) intersectionpoint (z1l .. z12l .. z2'r);
+ z20 = (z0 -- z2) intersectionpoint (z2l .. z23l .. z3'r);
+ z30 = (z0 -- z3) intersectionpoint (z3l .. z31l .. z1'r);
+
+ triangle_in = z10
+ .. z12l
+ .. z20
+ & z20
+ .. z23l
+ .. z30
+ & z30
+ .. z31l
+ .. z10
+ & cycle;
+
+ triangle_out_a = z1r .. z12r .. z2'l;
+ triangle_out_b = z2r .. z23r .. z3'l;
+ triangle_out_c = z3r .. z31r .. z1'l;
+
+ triangle_out = top z1
+ .. lft z1
+ .. z1r{direction 0 of triangle_out_a}
+ & triangle_out_a
+ & {direction infinity of triangle_out_a}z2'l
+ .. lft z2
+ .. bot z2
+ .. z2r{direction 0 of triangle_out_b}
+ & triangle_out_b
+ & {direction infinity of triangle_out_b}z3'l
+ .. rt z3
+ .. top z3
+ .. z3r{direction 0 of triangle_out_c}
+ & triangle_out_c
+ & {direction infinity of triangle_out_c}z1'l
+ .. cycle;
+
+ labels (0, 10, 20, 30);
+ penlabels (1, 1', 2, 2', 3, 3', 12, 23, 31);
+
+ % attachment Y
+ if stemdir = 1:
+ charwy := ypart exact_right_point;
+ charwx := xpart exact_right_point + .5 pen_thick# * xs;
+ else:
+ charwy := -ypart exact_down_point;
+ charwx := width# - (xpart exact_down_point - .5 pen_thick# * xs);
+ fi
+enddef;
+
+
+def draw_whole_triangle_head =
+ save hei, xs;
+ save llap;
+ save tilt;
+
+ tilt = 40;
+ llap# = 3/4 noteheight#;
+