mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-21 14:04:06 +02:00
Vector3: add clone
This commit is contained in:
parent
7549b0eaea
commit
6d0447a02f
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.area", function()
|
describe("Vector3.area", function()
|
||||||
it("should work with a positive vector", function()
|
it("should work with a positive vector", function()
|
||||||
local a = Vector3.new(3, 3, 3)
|
local a = Vector3.new(3, 3, 3)
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.ceil", function()
|
describe("Vector3.ceil", function()
|
||||||
it("should ceil a positive vector", function()
|
it("should ceil a positive vector", function()
|
||||||
local a = Vector3.new(3.1, 4.2, 5.8)
|
local a = Vector3.new(3.1, 4.2, 5.8)
|
||||||
|
24
.tests/Vector3/clone.test.lua
Normal file
24
.tests/Vector3/clone.test.lua
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
|
describe("Vector3.clone", function()
|
||||||
|
it("should return a new Vector3 instance", function()
|
||||||
|
local a = Vector3.new(3, 4, 5)
|
||||||
|
|
||||||
|
local result = a:clone()
|
||||||
|
assert.are.same(
|
||||||
|
Vector3.new(3, 4, 5),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
assert.are_not.equal(result, a)
|
||||||
|
end)
|
||||||
|
it("should return a new Vector3 instance for a different vector", function()
|
||||||
|
local a = Vector3.new(-99, 66, 88)
|
||||||
|
|
||||||
|
local result = a:clone()
|
||||||
|
assert.are.same(
|
||||||
|
Vector3.new(-99, 66, 88),
|
||||||
|
result
|
||||||
|
)
|
||||||
|
assert.are_not.equal(result, a)
|
||||||
|
end)
|
||||||
|
end)
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.floor", function()
|
describe("Vector3.floor", function()
|
||||||
it("should floor a positive vector", function()
|
it("should floor a positive vector", function()
|
||||||
local a = Vector3.new(3.1, 4.75, 5.9)
|
local a = Vector3.new(3.1, 4.75, 5.9)
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
-- To find these numbers, in Javascript:
|
-- To find these numbers, in Javascript:
|
||||||
-- function t(x) { return Math.sqrt((x*x)*3); }
|
-- function t(x) { return Math.sqrt((x*x)*3); }
|
||||||
-- for(let i = 0; i < 1000000000; i++) { let r = t(i); if(Math.floor(r) === r) console.log(`i ${i}, r ${r}`); }
|
-- for(let i = 0; i < 1000000000; i++) { let r = t(i); if(Math.floor(r) === r) console.log(`i ${i}, r ${r}`); }
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.length_squared", function()
|
describe("Vector3.length_squared", function()
|
||||||
it("should work with a positive vector", function()
|
it("should work with a positive vector", function()
|
||||||
local a = Vector3.new(3, 3, 3)
|
local a = Vector3.new(3, 3, 3)
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.round", function()
|
describe("Vector3.round", function()
|
||||||
it("should round a positive vector", function()
|
it("should round a positive vector", function()
|
||||||
local a = Vector3.new(3.1, 4.75, 5.9)
|
local a = Vector3.new(3.1, 4.75, 5.9)
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.sqrt", function()
|
describe("Vector3.sqrt", function()
|
||||||
it("should sqrt a positive vector", function()
|
it("should sqrt a positive vector", function()
|
||||||
local a = Vector3.new(16, 64, 16)
|
local a = Vector3.new(16, 64, 16)
|
||||||
|
@ -1,14 +1,5 @@
|
|||||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
local function format_map(map)
|
|
||||||
local result = {}
|
|
||||||
for key, value in pairs(map) do
|
|
||||||
table.insert(result, key.."\t"..tostring(value))
|
|
||||||
end
|
|
||||||
return table.concat(result, "\n")
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
describe("Vector3.__tostring", function()
|
describe("Vector3.__tostring", function()
|
||||||
it("should stringify a Vector3", function()
|
it("should stringify a Vector3", function()
|
||||||
local a = Vector3.new(3, 4, 5)
|
local a = Vector3.new(3, 4, 5)
|
||||||
|
@ -21,6 +21,13 @@ function Vector3.new(x, y, z)
|
|||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns a new instance of this vector.
|
||||||
|
-- @param a Vector3 The vector to clone.
|
||||||
|
-- @returns Vector3 A new vector whose values are identical to those of the original vector.
|
||||||
|
function Vector3.clone(a)
|
||||||
|
return Vector3.new(a.x, a.y, a.z)
|
||||||
|
end
|
||||||
|
|
||||||
--- Adds the specified vectors or numbers together.
|
--- Adds the specified vectors or numbers together.
|
||||||
-- Returns the result as a new vector.
|
-- Returns the result as a new vector.
|
||||||
-- If 1 of the inputs is a number and the other a vector, then the number will
|
-- If 1 of the inputs is a number and the other a vector, then the number will
|
||||||
|
Loading…
Reference in New Issue
Block a user