clone() overhaul / fix missing steps in line()
This commit is contained in:
parent
2834245229
commit
2574f487bb
@ -4,7 +4,7 @@ local function round(n)
|
||||
end
|
||||
|
||||
function mtscad.Context:line(x, y, z)
|
||||
local steps = math.sqrt( (x*x) + (y*y) + (z*z) )
|
||||
local steps = math.ceil( math.sqrt( (x*x) + (y*y) + (z*z) ) )
|
||||
for step=0,steps do
|
||||
local xi = round(x / steps * step)
|
||||
local yi = round(y / steps * step)
|
||||
|
@ -3,16 +3,16 @@ local Context_mt = { __index = mtscad.Context }
|
||||
|
||||
-- copy the current context
|
||||
function mtscad.Context:clone()
|
||||
return mtscad.create_context(self.pos, self.rotation, self.nodefactory, self.param2)
|
||||
return mtscad.create_context(self)
|
||||
end
|
||||
|
||||
-- create a new context with given (optional) params
|
||||
function mtscad.create_context(pos, rotation, nodefactory, param2)
|
||||
function mtscad.create_context(opts)
|
||||
local self = {
|
||||
pos = pos and vector.copy(pos) or vector.zero(),
|
||||
rotation = rotation and vector.copy(rotation) or vector.zero(),
|
||||
nodefactory = nodefactory,
|
||||
param2 = param2 or 0
|
||||
pos = opts.pos and vector.copy(opts.pos) or vector.zero(),
|
||||
rotation = opts.rotation and vector.copy(opts.rotation) or vector.zero(),
|
||||
nodefactory = opts.nodefactory,
|
||||
param2 = opts.param2 or 0
|
||||
}
|
||||
return setmetatable(self, Context_mt)
|
||||
end
|
||||
|
4
load.lua
4
load.lua
@ -34,7 +34,9 @@ minetest.register_chatcommand("scad", {
|
||||
func = function(name, modulename)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
local ppos = player:get_pos()
|
||||
local ctx = mtscad.create_context(vector.round(ppos))
|
||||
local ctx = mtscad.create_context({
|
||||
pos = vector.round(ppos)
|
||||
})
|
||||
|
||||
local fn, options
|
||||
local success, exec_err = pcall(function()
|
||||
|
Loading…
x
Reference in New Issue
Block a user