Page 1 of 1

minor code improvement

Posted: Sun Apr 27, 2014 7:53 pm
by Zul
In
game/modules/tome/data/timed_effects/physical.lua
I found the following code:

Code: Select all

local normalize_direction = function(direction)
    local pi2 = math.pi * 2
    while direction > pi2 do
        direction = direction - pi2
    end
    while direction < 0 do
        direction = direction + pi2
    end
    return direction
end
Using the builtin % operator, this can be rewritten in a more efficient and concise way:

Code: Select all

local normalize_direction = function(direction)
    return direction % (2*math.pi)
end

Re: minor code improvement

Posted: Tue May 06, 2014 9:43 pm
by darkgod
done