mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-09-12 08:08:30 +02:00
Vector3: add area
This commit is contained in:
parent
1e1112c34a
commit
57df2d045f
34
.tests/Vector3/area.test.lua
Normal file
34
.tests/Vector3/area.test.lua
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
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()
|
||||||
|
it("should work with a positive vector", function()
|
||||||
|
local a = Vector3.new(3, 3, 3)
|
||||||
|
assert.are.equal(
|
||||||
|
a:area(),
|
||||||
|
27
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a negative vector", function()
|
||||||
|
local a = Vector3.new(-4, -4, -4)
|
||||||
|
assert.are.equal(
|
||||||
|
a:area(),
|
||||||
|
-64
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a mixed vector", function()
|
||||||
|
local a = Vector3.new(-3, 3, -3)
|
||||||
|
assert.are.equal(
|
||||||
|
a:area(),
|
||||||
|
27
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end)
|
@ -116,6 +116,14 @@ function Vector3.round(a)
|
|||||||
return Vector3.new(math.floor(a.x+0.5), math.floor(a.y+0.5), math.floor(a.z+0.5))
|
return Vector3.new(math.floor(a.x+0.5), math.floor(a.y+0.5), math.floor(a.z+0.5))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the area of this vector.
|
||||||
|
-- In other words, multiplies all the components together and returns a scalar value.
|
||||||
|
-- @param a Vector3 The vector to return the area of.
|
||||||
|
-- @returns number The area of this vector.
|
||||||
|
function Vector3.area(a)
|
||||||
|
return a.x * a.y * a.z
|
||||||
|
end
|
||||||
|
|
||||||
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
-- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████
|
-- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████
|
||||||
|
Loading…
Reference in New Issue
Block a user