mirror of
https://github.com/sbrl/Minetest-WorldEditAdditions.git
synced 2024-11-27 17:43:53 +01:00
Vector3: add min_component, max_component
This commit is contained in:
parent
0a3680aa7d
commit
88214aef57
39
.tests/Vector3/max_component.test.lua
Normal file
39
.tests/Vector3/max_component.test.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
|
describe("Vector3.max_component", function()
|
||||||
|
it("should work with a positive vector x", function()
|
||||||
|
local a = Vector3.new(30, 4, 5)
|
||||||
|
assert.are.equal(
|
||||||
|
30,
|
||||||
|
a:max_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a positive vector y", function()
|
||||||
|
local a = Vector3.new(3, 10, 5)
|
||||||
|
assert.are.equal(
|
||||||
|
10,
|
||||||
|
a:max_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a positive vector z", function()
|
||||||
|
local a = Vector3.new(3, 1, 50.5)
|
||||||
|
assert.are.equal(
|
||||||
|
50.5,
|
||||||
|
a:max_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a negative vector", function()
|
||||||
|
local a = Vector3.new(-4, -5, -1)
|
||||||
|
assert.are.equal(
|
||||||
|
-1,
|
||||||
|
a:max_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a mixed vector", function()
|
||||||
|
local a = Vector3.new(-30, 3, -3)
|
||||||
|
assert.are.equal(
|
||||||
|
3,
|
||||||
|
a:max_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end)
|
39
.tests/Vector3/min_component.test.lua
Normal file
39
.tests/Vector3/min_component.test.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
local Vector3 = require("worldeditadditions.utils.vector3")
|
||||||
|
|
||||||
|
describe("Vector3.min_component", function()
|
||||||
|
it("should work with a positive vector x", function()
|
||||||
|
local a = Vector3.new(3, 4, 5)
|
||||||
|
assert.are.equal(
|
||||||
|
3,
|
||||||
|
a:min_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a positive vector y", function()
|
||||||
|
local a = Vector3.new(3, 1, 5)
|
||||||
|
assert.are.equal(
|
||||||
|
1,
|
||||||
|
a:min_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a positive vector z", function()
|
||||||
|
local a = Vector3.new(3, 1, 0.5)
|
||||||
|
assert.are.equal(
|
||||||
|
0.5,
|
||||||
|
a:min_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a negative vector", function()
|
||||||
|
local a = Vector3.new(-4, -5, -46)
|
||||||
|
assert.are.equal(
|
||||||
|
-46,
|
||||||
|
a:min_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
it("should work with a mixed vector", function()
|
||||||
|
local a = Vector3.new(-30, 3, -3)
|
||||||
|
assert.are.equal(
|
||||||
|
-30,
|
||||||
|
a:min_component()
|
||||||
|
)
|
||||||
|
end)
|
||||||
|
end)
|
@ -229,6 +229,22 @@ function Vector3.move_towards(a, b, amount)
|
|||||||
return a + (b - a):limit_to(amount)
|
return a + (b - a):limit_to(amount)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Returns the value of the minimum component of the vector.
|
||||||
|
-- Returns a scalar value.
|
||||||
|
-- @param a Vector3 The vector to operate on.
|
||||||
|
-- @returns number The value of the minimum component of the vector.
|
||||||
|
function Vector3.min_component(a)
|
||||||
|
return math.min(a.x, a.y, a.z)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Returns the value of the maximum component of the vector.
|
||||||
|
-- Returns a scalar value.
|
||||||
|
-- @param a Vector3 The vector to operate on.
|
||||||
|
-- @returns number The value of the maximum component of the vector.
|
||||||
|
function Vector3.max_component(a)
|
||||||
|
return math.max(a.x, a.y, a.z)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
-- ██████ ██████ ███████ ██████ █████ ████████ ██████ ██████
|
||||||
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
-- ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██
|
||||||
|
Loading…
Reference in New Issue
Block a user