[
	#functions-geometry.cfg
	{
		#determine the length between two points
		name: "length",
		args: "x, y, u, v",
		formula: "sqrt(ly^2 + lx^2) where lx = abs(x-u) where ly = abs(y-v)",
	},
	{

		#convenience version of length; which gets the length between two objects' midpoints.
		name: "distance",
		args: "a, b",
		formula: "if(is_list(a), 
			length(a[0], a[1], b[0], b[1]), 
			length(a.midpoint_x, a.midpoint_y, b.midpoint_x, b.midpoint_y))",
	},
	{

		#convenience function for the angle between two objects
		name: "angle_to",
		args: "a, b",
		formula: "if(is_list(a),
			angle(a[0], a[1], b[0], b[1]),
			angle(a.midpoint_x, a.midpoint_y, b.midpoint_x, b.midpoint_y))",
	},
	{

		#since orbital motion is a frequent use of trig, we've made a general helper function.
		#this returns a vector [x,y] of our orbitee's position.
		#This would be at an angle "rot" on a circle centered on x, y, with diameter "dist".
		name: "orbit_obj",
		args: "x, y, rot, dist",
		formula: "debug_fn('orbit_obj() is deprecated, use orbit() instead.', 
			[(dist * cos(rot)) / 100 + x, (dist * sin(rot)) / 100 + y])",
	},
	{
		name: "angle_alpha",
		args: "a, b, c",
		formula: "acos(((b^2 + c^2 - a^2)*100)/(2*b*c))",
	},
	{
		name: "angle_beta",
		args: "a, b, c",
		formula: "acos(((a^2 + c^2 - b^2)*100)/(2*a*c))",
	},
	{
		name: "angle_theta",
		args: "a, b, c",
		formula: "acos(((a^2 + b^2 - c^2)*100)/(2*a*b))",
	},


	{
		name: "normalize_rect",	//Ensures rect is defined as [upper-left corner xy, lower-right corner xy].
		args: "rect ",			//rect format x1y1x2y2
		formula: "[min(rect[0], rect[2]),
				   min(rect[1], rect[3]), 
				   max(rect[0], rect[2]), 
				   max(rect[1], rect[3])]",
	},		
	{
		name: "xywh_to_xyxy",	//Note: Rects as xywh are generally depreciated, but may be needed in places.
		args: "rect",
		formula: "[rect[0], rect[1], rect[0]+rect[2], rect[1]+rect[3]]",
	},		
	{
		name: "xyxy_to_xywh",
		args: "rect ",
		formula: "[rect[0], rect[1], rect[2]-rect[0], rect[3]-rect[1]]",
	},	

	{
		name: "point_in_rect",
		args: "point, rect_",	//rect format x1y1x2y2
		formula: "(rect[0] < point[0] and point[0] < rect[2] and
				   rect[1] < point[1] and point[1] < rect[3]) where
			rect = normalize_rect(rect_)",
	},
	{
		name: "rect_in_rect",
		args: "rect1, rect2",	//rect format x1y1x2y2
		formula: "0 < sum(map([[rect1, rect2], [rect2, rect1]], 'rects',
			sum(map([	[rects[0][0], rects[0][1]],	//Works by testing each point of each rect to see if it's in the other rect. Slightly inefficient.
					[rects[0][0], rects[0][3]],
					[rects[0][2], rects[0][1]],
					[rects[0][2], rects[0][3]]], 'point',
				point_in_rect(point, rects[1])
				))
			))",
	},


]