2013-01-05 13:09:31 +00:00
|
|
|
|
|
|
|
local ffi = require("ffi")
|
|
|
|
local ffiC = ffi.C
|
|
|
|
|
|
|
|
local sector = sector
|
|
|
|
local inside = inside
|
|
|
|
|
|
|
|
local math = require("math")
|
2013-06-28 14:07:41 +00:00
|
|
|
local xmath = require("xmath")
|
2013-01-05 13:09:31 +00:00
|
|
|
local stat = require("stat")
|
|
|
|
|
|
|
|
local function resetseed()
|
|
|
|
math.randomseed(834572183572)
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getmapbounds()
|
|
|
|
local inf = 1/0
|
|
|
|
local min = { x=inf, y=inf }
|
|
|
|
local max = { x=-inf, y=-inf }
|
|
|
|
|
|
|
|
for i=0,ffiC.numsectors-1 do
|
|
|
|
for w in wallsofsect(i) do
|
|
|
|
local wal = wall[w]
|
|
|
|
|
|
|
|
min.x = math.min(wal.x, min.x)
|
|
|
|
max.x = math.max(wal.x, max.x)
|
|
|
|
min.y = math.min(wal.y, min.y)
|
|
|
|
max.y = math.max(wal.y, max.y)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return min, max
|
|
|
|
end
|
|
|
|
|
|
|
|
local function getpoints(n, min, max)
|
|
|
|
local posns, sects = {}, {}
|
|
|
|
|
|
|
|
resetseed()
|
|
|
|
for i=1,n do
|
|
|
|
local x = math.random(min.x, max.x)
|
|
|
|
local y= math.random(min.y, max.y)
|
2013-06-28 14:07:41 +00:00
|
|
|
posns[i] = xmath.vec2(x, y)
|
2013-01-05 13:09:31 +00:00
|
|
|
sects[i] = math.random(0, ffiC.numsectors-1)
|
|
|
|
end
|
|
|
|
|
|
|
|
return posns, sects
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Compare 'inside' implementations
|
|
|
|
--
|
|
|
|
-- N: number of calls
|
|
|
|
function compinside(n)
|
|
|
|
if (type(n) ~= "number") then
|
|
|
|
error("N must be a number")
|
|
|
|
end
|
|
|
|
|
|
|
|
local sti = stat.new()
|
|
|
|
local sts = stat.new()
|
|
|
|
|
|
|
|
local min, max = getmapbounds()
|
|
|
|
local posns, sects = getpoints(n, min, max)
|
|
|
|
|
|
|
|
local isi, iss = {}, {}
|
|
|
|
|
|
|
|
for i=1,n do
|
2013-07-07 20:59:05 +00:00
|
|
|
local t = ffiC.gethiticks()
|
2013-01-05 13:09:31 +00:00
|
|
|
isi[i] = inside(posns[i], sects[i])
|
2013-07-07 20:59:05 +00:00
|
|
|
t = ffiC.gethiticks()-t
|
2013-01-05 13:09:31 +00:00
|
|
|
sti:add(t)
|
|
|
|
|
2013-07-07 20:59:05 +00:00
|
|
|
local t = ffiC.gethiticks()
|
2013-01-05 13:09:31 +00:00
|
|
|
iss[i] = sector[sects[i]]:contains(posns[i])
|
2013-07-07 20:59:05 +00:00
|
|
|
t = ffiC.gethiticks()-t
|
2013-01-05 13:09:31 +00:00
|
|
|
sts:add(t)
|
|
|
|
|
|
|
|
-- if (isi[i]~=iss[i]) then
|
|
|
|
-- print("unequal: "..i.." "..sects[i].." "..posns[i].x.." "..posns[i].y.." ("..tostring(isi[i])..","..tostring(iss[i])..")")
|
|
|
|
-- end
|
|
|
|
assert(isi[i]==iss[i])
|
|
|
|
end
|
|
|
|
|
|
|
|
print("====================")
|
2013-01-06 18:56:45 +00:00
|
|
|
print("inside(): " .. sti:getstatstr())
|
|
|
|
print("contains(): " .. sts:getstatstr())
|
2013-01-05 13:09:31 +00:00
|
|
|
end
|