FashGek / hotween

Automatically exported from code.google.com/p/hotween
0 stars 0 forks source link

minor code improvements #27

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
GetTimeToArcLenTable function in Path.cs could use some minor code improvements:

1. move if (i == 0) before loop (possible performance improvement)
2. move some variables (t) into loop (same performance by C# compiler but 
better readability)
3. remove not needed prevLen variable by using: len += Vector3.Distance(p, 
prevP);

According to your code style you must be coming from c++ background I guess. 
Anyways could look like so but probably against your code style:

    inline Dictionary<float, float> GetTimeToArcLengthTable(int subdivisions, out float length)
    {
        length = 0;
        float increment = 1f / subdivisions;
        var timeLengthTable = new Dictionary<float, float>();

        Vector3 previousPoint = GetPoint(0);

        for (int i = 1; i < subdivisions + 1; ++i)
        {
            float time = increment * i;

            Vector3 currentPoint = GetPoint(time);
            length += Vector3.Distance(currentPoint, previousPoint);
            previousPoint = currentPoint;

            timeLengthTable.Add(time, length);
        }

        return timeLengthTable;
    }

Correct me if I am wrong

PS: Might be nice if you could turn on commit comments ;)

Original issue reported on code.google.com by stfxm...@gmail.com on 26 Mar 2012 at 10:19

GoogleCodeExporter commented 9 years ago
You're totally right, thanks for the insight. Keeping i == 0 and prevLen was a 
dumb move from me, while instead I thought that declaring variables outside a 
loop was more efficient (like in ActionScript, which is my background). It's 
great to know the C# compiler doesn't need that: will change everything I do 
from now on.

I just committed your changes (though I renamed some variable :P), though am 
waiting a little more to release a new build.

P.S. turned on commit comments :) Sorry, I'm new to Google Code, and didn't 
notice such a useful option.

Original comment by daniele....@gmail.com on 27 Mar 2012 at 9:40