Upgrade more old vector stuff in the corners

This commit is contained in:
Starbeamrainbowlabs 2022-09-19 18:54:53 +01:00
parent c3ae96548e
commit 44e6ba8e3c
No known key found for this signature in database
GPG Key ID: 1BE5172E637709C2
11 changed files with 17 additions and 153 deletions

@ -55,7 +55,7 @@ local function snowball(heightmap, normalmap, heightmap_size, startpos, params)
velocity.x = params.friction * velocity.x + normalmap[hi].x * params.speed
velocity.y = 0 -- Just in case
velocity.z = params.friction * velocity.z + normalmap[hi].y * params.speed
-- print("[snowball] now at ("..x..", "..z..") velocity "..wea.vector.lengthsquared(velocity)..", sediment "..sediment)
-- print("[snowball] now at ("..x..", "..z..") velocity "..velocity:length_squared()..", sediment "..sediment)
local new_vel_sq = velocity:length_squared()
if new_vel_sq > 1 then
-- print("[snowball] velocity squared over 1, normalising")

@ -64,9 +64,6 @@ function worldeditadditions.scale_down(pos1, pos2, scale, anchor)
for x = pos2.x, pos1.x, -1 do
local posi_rel = Vector3.new(x, y, z) - pos1
-- local posi_copy = wea_c.table.shallowcopy(posi_rel)
-- posi_copy = vector.floor(vector.divide(posi_rel/*, scale_down*/))
local posi_copy = posi_rel / scale_down
if anchor.x < 0 then posi_copy.x = size.x - posi_copy.x end

@ -25,8 +25,8 @@ function worldeditadditions.scale_up(pos1, pos2, scale, anchor)
local size = (pos2 - pos1) + 1
local pos1_big = Vector3.new(pos1)
local pos2_big = Vector3.new(pos2)
local pos1_big = Vector3.clone(pos1)
local pos2_big = Vector3.clone(pos2)
if anchor.x < 1 then pos1_big.x = pos1_big.x - (size.x * (scale.x - 1))
else pos2_big.x = pos2_big.x + (size.x * (scale.x - 1)) end

@ -36,10 +36,8 @@ worldeditadditions_core.register_command("line", {
-- Volume of a hemisphere
return math.ceil(math.pi
* radius * radius
* vector.distance(
vector.new(worldedit.pos1[name]),
vector.new(worldedit.pos2[name])
)) -- Volume of a cylinder
* (Vector3.clone(worldedit.pos2[name]) - Vector3.clone(worldedit.pos1[name])):length()
) -- Volume of a cylinder
end,
func = function(name, replace_node, radius)
local start_time = wea_c.get_ms_time()

@ -18,11 +18,11 @@ worldeditadditions_core.register_command("midpos", {
func = function(name, params_text)
local str = "The centre of the current selection is at "
local pos1 = Vector3.new(worldedit.pos1[name])
local pos2 = Vector3.new(worldedit.pos2[name])
local pos1 = Vector3.clone(worldedit.pos1[name])
local pos2 = Vector3.clone(worldedit.pos2[name])
local vec = wea_c.vector.mean(pos1, pos2)
local vec = Vector3.mean(pos1, pos2)
return true, str .. wea_c.table.tostring(vec)
end,

@ -19,8 +19,8 @@ worldeditadditions_core.register_command("msize", {
func = function(name, params_text)
local str = "The dimensions of the current selection are "
local pos1 = Vector3.new(worldedit.pos1[name])
local pos2 = Vector3.new(worldedit.pos2[name])
local pos1 = Vector3.clone(worldedit.pos1[name])
local pos2 = Vector3.clone(worldedit.pos2[name])
local vec = (pos2 - pos1):abs()

@ -15,8 +15,11 @@ worldeditadditions_core.register_command("scentre", {
return true
end,
func = function(name)
local mean = wea_c.vector.mean(worldedit.pos1[name],worldedit.pos2[name])
local pos1, pos2 = Vector3.new(mean), Vector3.new(mean)
local mean = Vector3.mean(
Vector3.clone(worldedit.pos1[name]),
Vector3.clone(worldedit.pos2[name])
)
local pos1, pos2 = Vector3.clone(mean), Vector3.clone(mean)
pos1 = pos1:floor()
pos2 = pos2:ceil()

@ -56,4 +56,4 @@ worldeditadditions_core.register_command("srect", {
-- /multi //fp set1 -63 19 -20 //srect -z 5
-- /multi //fp set1 -63 19 -20 //srect a -x 5
-- /multi //fp set1 -63 19 -20 //srect -x -a 5
-- lua vec = vector.new(15,-12,17); vec["len"] = 5; vec.get = true; vec2 = vector.add(vector.new(1,1,1),vec) print(vec2.x,vec2.y,vec2.z,vec2.len)
-- lua vec = Vector3.new(15,-12,17); vec["len"] = 5; vec.get = true; vec2 = Vector3.new(1,1,1) + vec; print(vec2.x,vec2.y,vec2.z,vec2.len)

@ -41,7 +41,6 @@ wea_c.bit = dofile(wea_c.modpath.."/utils/bit.lua")
wea_c.terrain = dofile(wea_c.modpath.."/utils/terrain/init.lua")
dofile(wea_c.modpath.."/utils/vector.lua")
dofile(wea_c.modpath.."/utils/strings/init.lua")
dofile(wea_c.modpath.."/utils/format/init.lua")
dofile(wea_c.modpath.."/utils/parse/init.lua")

@ -29,7 +29,7 @@ function wea_c.player_dir(name)
return dir
end
-- /lua print(wea_c.vector.tostring(minetest.get_player_by_name(myname):get_look_dir()))
-- /lua print(Vector3.clone(minetest.get_player_by_name(myname):get_look_dir()))
--- DEPRECATED =================================================================
-- TODO: Refactor commands that use the following functions to use player_dir then delete these functions

@ -1,133 +0,0 @@
worldeditadditions_core.vector = {}
-- -- @deprecated Use Vector3 instead.
-- function worldeditadditions_core.vector.tostring(v)
-- if not v then return "(nil)" end
-- return "(" .. v.x ..", " .. v.y ..", " .. v.z ..")"
-- end
-- --- Calculates the length squared of the given vector.
-- -- @deprecated Use Vector3 instead.
-- -- @param v Vector The vector to operate on
-- -- @return number The length of the given vector squared
-- function worldeditadditions_core.vector.lengthsquared(v)
-- if not v.y then return v.x*v.x + v.z*v.z end
-- return v.x*v.x + v.y*v.y + v.z*v.z
-- end
--- Normalises the given vector such that its length is 1.
-- Also known as calculating the unit vector.
-- This method does *not* mutate.
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to calculate from.
-- @return Vector A new normalised vector.
-- function worldeditadditions_core.vector.normalize(v)
-- local length = math.sqrt(worldeditadditions_core.vector.lengthsquared(v))
-- if not v.y then return {
-- x = v.x / length,
-- z = v.z / length
-- } end
-- return {
-- x = v.x / length,
-- y = v.y / length,
-- z = v.z / length
-- }
-- end
--- Rounds the values in a vector down.
-- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on
-- function worldeditadditions_core.vector.floor(v)
-- if v.x then v.x = math.floor(v.x) end
-- -- Some vectors are 2d, but on the x / z axes
-- if v.y then v.y = math.floor(v.y) end
-- -- Some vectors are 2d
-- if v.z then v.z = math.floor(v.z) end
-- end
--- Rounds the values in a vector up.
-- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on
-- function worldeditadditions_core.vector.ceil(v)
-- if v.x then v.x = math.ceil(v.x) end
-- -- Some vectors are 2d, but on the x / z axes
-- if v.y then v.y = math.ceil(v.y) end
-- -- Some vectors are 2d
-- if v.z then v.z = math.ceil(v.z) end
-- end
--- Sets the values in a vector to their absolute values.
-- Warning: This MUTATES the given vector!
-- @deprecated Use Vector3 instead.
-- @param v Vector The vector to operate on
-- function worldeditadditions_core.vector.abs(v)
-- if v.x then v.x = math.abs(v.x) end
-- -- Some vectors are 2d, but on the x / z axes
-- if v.y then v.y = math.abs(v.y) end
-- -- Some vectors are 2d
-- if v.z then v.z = math.abs(v.z) end
-- end
--- Determines if the target point is contained within the defined worldedit region.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to check.
-- @return boolean Whether the given target is contained within the defined worldedit region.
-- function worldeditadditions_core.vector.is_contained(pos1, pos2, target)
-- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
-- return pos1.x >= target.x
-- and pos1.y >= target.y
-- and pos1.z >= target.z
-- and pos2.x <= target.x
-- and pos2.y <= target.y
-- and pos2.z <= target.z
-- end
--- Expands the defined region to include the given point.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @param target Vector The target vector to include.
-- function worldeditadditions_core.vector.expand_region(pos1, pos2, target)
-- local pos1, pos2 = worldedit.sort_pos(pos1, pos2)
-- if target.x < pos1.x then pos1.x = target.x end
-- if target.y < pos1.y then pos1.y = target.y end
-- if target.z < pos1.z then pos1.z = target.z end
-- if target.x > pos2.x then pos2.x = target.x end
-- if target.y > pos2.y then pos2.y = target.y end
-- if target.z > pos2.z then pos2.z = target.z end
-- return pos1, pos2
-- end
--- Returns the mean (average) of 2 positions to give you the centre.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @param target Vector Centre coordinates.
function worldeditadditions_core.vector.mean(pos1, pos2)
return vector.new((pos1.x + pos2.x)/2, (pos1.y + pos2.y)/2, (pos1.z + pos2.z)/2)
end
--- Returns a vector of the min values of 2 positions.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @return Vector Min values from input vectors.
-- function worldeditadditions_core.vector.min(pos1, pos2)
-- return vector.new(math.min(pos1.x, pos2.x), math.min(pos1.y, pos2.y), math.min(pos1.z, pos2.z))
-- end
--- Returns a vector of the max values of 2 positions.
-- @deprecated Use Vector3 instead.
-- @param pos1 Vector pos1 of the defined region.
-- @param pos2 Vector pos2 of the defined region.
-- @return Vector Max values from input vectors.
-- function worldeditadditions_core.vector.max(pos1, pos2)
-- return vector.new(math.max(pos1.x, pos2.x), math.max(pos1.y, pos2.y), math.max(pos1.z, pos2.z))
-- end