leef-math-cd2025/modules/_private_utils.lua
David Briscoe 4dc773865e Reference private.round instead of util.round
Fix "Error: src/lib/cpml/modules/_private_utils.lua:8: attempt to index
    global 'utils' (a nil value)"

Looks like when round was moved to _private_utils, this didn't get
replaced. There is no utils defined and utils.round just points to
private.round.

Add a test. This never triggered test failures because test don't pass
precision.

Test
A love2d program with main.lua:
    local Vec2 = require "cpml.modules.vec2"
    local v = Vec2(1.234, 3.5326)
    print(v:round(0.1))
2021-11-24 09:55:57 -08:00

13 lines
358 B
Lua

-- Functions exported by utils.lua but needed by vec2 or vec3 (which utils.lua requires)
local private = {}
local floor = math.floor
local ceil = math.ceil
function private.round(value, precision)
if precision then return private.round(value / precision) * precision end
return value >= 0 and floor(value+0.5) or ceil(value-0.5)
end
return private