include("vec2d.lua")

lGr = {}

function lGr.drawTriangle(x1, y1, x2, y2, height)
	local triDir = Vector2d(x2 - x1, y2 - y1)
	local cos
	if (triDir.x < 0) then
		cos = (triDir * Vector2d(-1, 0)) / triDir:getLength()
		if (triDir.y < 0) then
			cos = -cos
		end
	else
		cos = (triDir * Vector2d(1, 0)) / triDir:getLength()
		if (triDir.y > 0) then
			cos = -cos
		end
	end

	local xOff = math.sqrt(1 - cos^2) * (height / 2)
	local yOff = cos * (height / 2)

	local x3 = x2 + xOff
	local x4 = x2 - xOff

	local y3 = y2 + yOff
	local y4 = y2 - yOff

	gr.drawLine(x1, y1, x3, y3)
	gr.drawLine(x1, y1, x4, y4)
	gr.drawLine(x3, y3, x4, y4)
end

function lGr.checkCoords(x, y)
	return lGr.checkX(x) and lGr.checkY(y)
end

function lGr.checkX(x)
	if (x == nil or x < 0 or x > gr.getScreenWidth()) then
		return false
	else
		return true
	end
end

function lGr.checkY(y)
	if (y== nil or y < 0 or y > gr.getScreenHeight()) then
		return false
	else
		return true
	end
end
