I have made a function which calculates the index of a point to which an arbitrary point on a polygon made of XY points belong, this.
This is a visual representation:
https://i.sstatic.net/zDTa3.png
And this is the function I made:
stock GetNodeIndexFromPolygonIndex(polygonid,Polygon_Size)
{
new polid = (polygonid - (polygonid % 2));
new mid = Polygon_Size/2;
if(polid > mid)
{
polid /= 2;
return (mid - (++polid));
}
else
{
polid /= 2;
if(polid == 0)
{
return 0;
}
return --polid;
}
}
I'm wondering ifIs there is anything I can optimize here? This function is going to be called ~2000 times in the worst case in one run on a single threaded application. I would like this to be as optimal as possible. Is it already?
The language this function is in is: PAWN