Vector3: add area

This commit is contained in:
Starbeamrainbowlabs 2021-06-26 14:26:40 +01:00
parent 1e1112c34a
commit 57df2d045f
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
2 changed files with 42 additions and 0 deletions

View 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)

View File

@ -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))
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
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
-- ██ ██ ██████ █████ ██████ ███████ ██ ██ ██ ██████