mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-08-20 21:44:06 +02:00
Vector3: add abs
This commit is contained in:
parent
88214aef57
commit
91b77c981b
35
.tests/Vector3/abs.test.lua
Normal file
35
.tests/Vector3/abs.test.lua
Normal file
@ -0,0 +1,35 @@
|
||||
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||
|
||||
describe("Vector3.abs", function()
|
||||
it("should work with a positive vector", function()
|
||||
local a = Vector3.new(16, 64, 16)
|
||||
assert.are.same(
|
||||
Vector3.new(16, 64, 16),
|
||||
a:abs()
|
||||
)
|
||||
end)
|
||||
it("should abs another positive vector", function()
|
||||
local a = Vector3.new(9, 16, 25)
|
||||
assert.are.same(
|
||||
Vector3.new(9, 16, 25),
|
||||
a:abs()
|
||||
)
|
||||
end)
|
||||
it("should abs a negative vector", function()
|
||||
local a = Vector3.new(-9, -16, -25)
|
||||
assert.are.same(
|
||||
Vector3.new(9, 16, 25),
|
||||
a:abs()
|
||||
)
|
||||
end)
|
||||
it("should return a new Vector3 instance", function()
|
||||
local a = Vector3.new(9, -16, 25)
|
||||
|
||||
local result = a:abs()
|
||||
assert.are.same(
|
||||
Vector3.new(9, 16, 25),
|
||||
result
|
||||
)
|
||||
assert.are_not.equal(result, a)
|
||||
end)
|
||||
end)
|
@ -245,6 +245,14 @@ function Vector3.max_component(a)
|
||||
return math.max(a.x, a.y, a.z)
|
||||
end
|
||||
|
||||
--- Returns the absolute form of this vector.
|
||||
-- In other words, it removes the minus sign from all components of the vector.
|
||||
-- @param a Vector3 The vector to operate on.
|
||||
-- @returns Vector3 The absolute form of the given vector.
|
||||
function Vector3.abs(a)
|
||||
return Vector3.new(math.abs(a.x), math.abs(a.y), math.abs(a.z))
|
||||
end
|
||||
|
||||
|
||||
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||
|
Loading…
Reference in New Issue
Block a user