%(c) 1990,91 by Joel M. Hoffman

mode_def testing=
		pixels_per_inch:=300*4;
		blacker:=.1;
		o_correction:=1;
		fillin:=.01;
		proofing:=2;
		fontmaking:=0;
		tracingtitles:=1;
	enddef;
if unknown mode:
mode:=testing; fi
mode_setup;

if mode=testing: screenstrokes; fi

% parameters that control what a wedge looks like.
width_to_length_ratio := 1/2;
tailang  := 30;
costail  := cosd tailang;
tantail  := sind tailang/cosd tailang;

u# = 1/384in#;
wedge_len# := 50u#;
wedge_wid# := wedge_len#*width_to_length_ratio;
tail_len# := wedge_wid#*costail;
stem_len# := wedge_len# - tail_len#;
tail_porp := tail_len#/wedge_len#;
stem_porp := stem_len#/wedge_len#;
let_height# := wedge_len#+wedge_wid#;
pen_thick# := wedge_len#/10;

define_pixels(wedge_len, wedge_wid, tail_len, stem_len, let_height, pen_thick);

def wedgepen = pickup pencircle scaled pen_thick; enddef;

def drawwedge (expr n) =
	wedgelen := V[n]len;
	wedgewid := wedgelen*width_to_length_ratio;
	taillen := wedgewid*costail;
	stemlen := wedgelen - taillen;
	V[n]pnt = V[n]mid + ((stemlen, 0) rotated (V[n]theta));
	V[n]ccw = V[n]mid + ((taillen, 0) rotated (V[n]theta + 180 - tailang));
	V[n]cw  = V[n]mid + ((taillen, 0) rotated (V[n]theta - 180 + tailang));
	if unknown V[n]mid.x:
		V[n]mid.x = (V[n]pnt.x + V[n]ccw.x + V[n]cw.x)/3;
	fi
	if unknown V[n]mid.y:
		V[n]mid.y = (V[n]pnt.y + V[n]ccw.y + V[n]cw.y)/3;
	fi
	if unknown V[n].tmid.x:
		V[n]tmid.x = (V[n]mid.x + V[n]ccw.x + V[n]cw.x)/3;
	fi
	if unknown V[n].tmid.y:
		V[n]tmid.y = (V[n]mid.y + V[n]ccw.y + V[n]cw.y)/3;
	fi
	% classic
%	fill V[n]pnt..controls V[n]mid and V[n]mid..V[n]ccw &
%		V[n]ccw..controls V[n]mid and V[n]mid..V[n]cw &
%		V[n]cw..controls V[n]mid and V[n]mid..V[n]pnt--cycle;
	% wedge
%	fill V[n]pnt--V[n]ccw--V[n]cw--cycle;
	% academic
	wedgepen;
	draw V[n]pnt--V[n]mid--V[n]ccw--V[n]cw--V[n]mid;
enddef;

def lenwedge(expr n) =
	V[n]len
enddef;

def rotwedge(expr n) =
	V[n]theta
enddef;

def pointwedge(expr n) = 
	V[n]pnt
enddef;

def midwedge(expr n) = 
	V[n]mid
enddef;

def ccwwedge(expr n) = 
	V[n]ccw
enddef;

def cwwedge(expr n) = 
	V[n]cw
enddef;

def tmidwedge(expr n) = 
	V[n]tmid
enddef;

def wedgesetup =
	save V;
	numeric	V[]len, V[]theta;
	pair	V[]pnt, V[]cw, V[]ccw, V[]mid, V[]tmid;

	for x = 0 step 1 until 20:
		lenwedge(x) := wedge_len;
		rotwedge(x) := 0;
	endfor
enddef;

beginchar("B",wedge_len#+wedge_wid#,let_height#,0); "ma";
wedgesetup;

pointwedge(1) = .5[cwwedge(4),midwedge(4)];
ccwwedge(4) = (w, h);
ccwwedge(3) = cwwedge(2);
w2pnt.x = w3pnt.x = w4pnt.x
w3cw.y = 0;
rotwedge(4) := -90;

drawwedge(4);
drawwedge(1);
drawwedge(2);
drawwedge(3);
endchar;

beginchar("A",wedge_len#,let_height#,0); "nu";
wedgesetup;

midwedge(1) = midwedge(2) = (w/2, h/2);
rotwedge(2) := 80;

drawwedge(1);
drawwedge(2);
endchar;

beginchar("@",wedge_wid#+wedge_len#,let_height#,0); "e";
wedgesetup;

ccwwedge(1) = (0, h);
pointwedge(2) = (wedge_len, wedge_len/2);
midwedge(3) = (wedge_len/2, wedge_len/2);
rotwedge(3) := -90;
ccwwedge(4) = (w, h);
rotwedge(4) := -90;
ccwwedge(5) = (w, h - tail_len);
rotwedge(5) := -90;

drawwedge(1);
drawwedge(2);
drawwedge(3);
drawwedge(4);
drawwedge(5);
endchar;

end;