// Note: The taken width is the distance in one direction, the whole width of the quad will be 2*width.
function IsPointInLineWidth takes real x, real y, real x1, real y1, real x2, real y2, real width returns boolean
// This function works like this: At both ends of the line 90° polar-offset coordinates into both directions create one quad,
// in which the taken coordinates have to be.
// The coordinate-changes after polar-offset
local real temp = (bj_RADTODEG * Atan2(y2-y1, x2-x1) + 90) * bj_DEGTORAD
local real xadd = width * Cos(temp)
local real yadd = width * Sin(temp)
// Setting the coordinates used for the DoesQuadContainOrigin-Check, origin = P(0|0)
local real x1q = x1-x+xadd
local real y1q = y1-y+yadd
local real x2q = x1-x-xadd
local real y2q = y1-y-yadd
local real x3q = x2-x-xadd
local real y3q = y2-y-yadd
local real x4q = x2-x+xadd
local real y4q = y2-y+yadd
// DoesQuadContainOrigin by Grater (only using a boolean instead of an integer)
local boolean FirstCheck = (x1q-x2q)*y1q < (y1q-y2q)*x1q
if (x2q-x3q)*y2q < (y2q-y3q)*x2q != FirstCheck then
return false
endif
if (x3q-x4q)*y3q < (y3q-y4q)*x3q != FirstCheck then
return false
endif
return (x4q-x1q)*y4q < (y4q-y1q)*x4q == FirstCheck
endfunction
function IsPointInLineWidthSimple takes real x, real y, real x1, real y1, real x2, real y2, real width returns boolean
// This function is useful, if you want to check lots of units, because it does not have to call IsPointInLineWidth everytime.
// The check works like checking if a coordinate is outside a given rect,
// with the only difference that no Max / Min values are given and it the function has to check both values.
// To do not cut the quad we have to make the rect a bit bigger (+width).
// I really recommend to use this function unless you limit the checked coordinates before.
if x > x1+width and x > x2+width then
return false
endif
if x < x1-width and x < x2-width then
return false
endif
if y > y1+width and y > y2+width then
return false
endif
if y < y1-width and y < y2-width then
return false
endif
return IsPointInLineWidth( x, y, x1, y1, x2, y2, width )
endfunction