local vector3d = require("vector3d")
local sector_t = (function()
local this = {}
local draw
function this:calc_all()
self.data = { [0] = 1 }
local step = {
x = (self.max.x - self.min.x) / self.div,
y = (self.max.y - self.min.y) / self.div
}
for i = 0, self.div do
local x = self.min.x + step.x * i
for j = 0, self.div do
local y = self.min.y + step.y * j
table.insert(self.data, vector3d(x, y, self.max.z))
end
end
for i = 0, self.div do
local y = self.min.y + step.y * i
for j = 0, self.div do
local x = self.min.x + step.x * j
table.insert(self.data, vector3d(x, y, self.max.z))
end
end
end
function this:calc_raw()
self.data = { [0] = 0 }
local step = {
x = (self.max.x - self.min.x) / self.div,
y = (self.max.y - self.min.y) / self.div
}
for i = 0, self.div do
local x = self.min.x + step.x * i
local y = self.min.y + step.y * i
table.insert(self.data, vector3d(x, self.min.y, self.max.z))
table.insert(self.data, vector3d(x, self.max.y, self.max.z))
table.insert(self.data, vector3d(self.min.x, y, self.max.z))
table.insert(self.data, vector3d(self.max.x, y, self.max.z))
end
end
function this:draw_all(func)
local old
for i, v in ipairs(self.data) do
local r, x, y = convert3DCoordsToScreenEx(v.x, v.y, v.z, true, true)
if r then
if old then
local cur = { x = x, y = y }
func(old, cur)
old = cur
else
old = { x = x, y = y }
end
end
if i % (self.div + 1) == 0 then
old = false
end
end
end
function this:draw_raw(func)
local t = self.data
for i = 1, #t, 2 do
local r1, x1, y1 = convert3DCoordsToScreenEx(t[i].x, t[i].y, t[i].z, true, true)
local r2, x2, y2 = convert3DCoordsToScreenEx(t[i + 1].x, t[i + 1].y, t[i + 1].z, true, true)
if r1 and r2 then
func({ x = x1, y = y1 }, { x = x2, y = y2 })
end
end
end
function this:draw(func)
local f = self.data and draw[(self.data[0])]
if f then
f(self, func)
end
end
draw = {
[0] = this.draw_raw,
[1] = this.draw_all
}
local function constructor(_, min, max, div)
return setmetatable({ min = min, max = max, div = div }, { __index = this })
end
return setmetatable(this, { __call = constructor })
end)()