function GroupEnumUnitsInCone takes group g, location loc, real length, real angle, real width1, real width2, boolexpr filter returns nothing
local group tempGroup = CreateGroup()
local real array x
local real array y
local real minX
local real minY
local real maxX
local real maxY
local rect tempRect
local location tempLoc
local unit u
set x[1] = GetLocationX(loc) + CosBJ(angle-90.0) * width1
set y[1] = GetLocationY(loc) + SinBJ(angle-90.0) * width1
set x[2] = GetLocationX(loc) + CosBJ(angle+90.0) * width1
set y[2] = GetLocationY(loc) + SinBJ(angle+90.0) * width1
set tempLoc = PolarProjectionBJ(loc, length,angle)
set x[3] = GetLocationX(tempLoc) + CosBJ(angle+90.0) * width2
set y[3] = GetLocationY(tempLoc) + SinBJ(angle+90.0) * width2
set x[4] = GetLocationX(tempLoc) + CosBJ(angle-90.0) * width2
set y[4] = GetLocationY(tempLoc) + SinBJ(angle-90.0) * width2
// Now we have a quad, define the rect that encloses it.
set minX = RMinBJ(x[1],RMinBJ(x[2],RMinBJ(x[3],x[4])))
set minY = RMinBJ(y[1],RMinBJ(y[2],RMinBJ(y[3],y[4])))
set maxX = RMaxBJ(x[1],RMaxBJ(x[2],RMaxBJ(x[3],x[4])))
set maxY = RMaxBJ(y[1],RMaxBJ(y[2],RMaxBJ(y[3],y[4])))
set tempRect = Rect(minX,minY,maxX,maxY)
call GroupEnumUnitsInRect(tempGroup,tempRect,filter)
//Now we filter the ins and outs
loop
set u = FirstOfGroup(tempGroup)
exitwhen u == null
if IsPointInQuadFast(GetUnitX(u),GetUnitY(u),x[1],y[1],x[2],y[2],x[3],y[3],x[4],y[4]) then
call GroupAddUnit(g,u)
endif
call GroupRemoveUnit(tempGroup,u)
endloop
call RemoveLocation(tempLoc)
call DestroyGroup(tempGroup)
call RemoveRect(tempRect)
set tempGroup = null
set tempLoc = null
set tempRect = null
endfunction