Skip to main content
added 27 characters in body; edited tags
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

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:

enter image description herehttps://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

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible. Is it already?

The language this function is in is: PAWN

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 is a visual representation:

enter image description here

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;
    }
}

Is there 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?

Added new programming language tag
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Optimizing mathematical index calculation function?

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 is a visual representation:

enter image description herehttps://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 if there is anything I can optimize here? this 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 optimal as possible, is. Is it already?

The language this function is in is: PAWN

Optimizing mathematical index calculation function?

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible, is it already?

The language this function is in is: PAWN

Optimizing mathematical index calculation function

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible. Is it already?

The language this function is in is: PAWN

edited body
Source Link
user19795
user19795

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible, is it already?

The language this function is in is: PAWN

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible, is it already?

The language this function is in is: PAWN

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 is a visual representation:

enter image description herehttps://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 if 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 optimal as possible, is it already?

The language this function is in is: PAWN

Source Link
user19795
user19795
Loading