diff --git a/.tests/Vector3/max.test.lua b/.tests/Vector3/max.test.lua index f8d3d2a..04f180c 100644 --- a/.tests/Vector3/max.test.lua +++ b/.tests/Vector3/max.test.lua @@ -19,6 +19,24 @@ describe("Vector3.max", function() Vector3.max(a, b) ) end) + it("should work with scalar numbers", function() + local a = Vector3.new(16, 1, 16) + local b = 2 + + assert.are.same( + Vector3.new(16, 2, 16), + Vector3.max(a, b) + ) + end) + it("should work with scalar numbers both ways around", function() + local a = Vector3.new(16, 1, 16) + local b = 2 + + assert.are.same( + Vector3.new(16, 2, 16), + Vector3.max(b, a) + ) + end) it("should work with negative vectors", function() local a = Vector3.new(-9, -16, -25) local b = Vector3.new(-3, -6, -2) diff --git a/.tests/Vector3/min.test.lua b/.tests/Vector3/min.test.lua index 332d74d..307ed79 100644 --- a/.tests/Vector3/min.test.lua +++ b/.tests/Vector3/min.test.lua @@ -19,6 +19,24 @@ describe("Vector3.min", function() Vector3.min(a, b) ) end) + it("should work with scalar numbers", function() + local a = Vector3.new(16, 1, 16) + local b = 2 + + assert.are.same( + Vector3.new(2, 1, 2), + Vector3.min(a, b) + ) + end) + it("should work with scalar numbers both ways around", function() + local a = Vector3.new(16, 1, 16) + local b = 2 + + assert.are.same( + Vector3.new(2, 1, 2), + Vector3.min(b, a) + ) + end) it("should work with negative vectors", function() local a = Vector3.new(-9, -16, -25) local b = Vector3.new(-3, -6, -2) diff --git a/worldeditadditions/utils/vector3.lua b/worldeditadditions/utils/vector3.lua index 6ec8811..5733279 100644 --- a/worldeditadditions/utils/vector3.lua +++ b/worldeditadditions/utils/vector3.lua @@ -317,8 +317,8 @@ end --- Returns the mean (average) of 2 positions. -- In other words, returns the centre of 2 points. --- @param pos1 Vector3 pos1 of the defined region. --- @param pos2 Vector3 pos2 of the defined region. +-- @param pos1 Vector3|number pos1 of the defined region. +-- @param pos2 Vector3|number pos2 of the defined region. -- @param target Vector3 Centre coordinates. function Vector3.mean(pos1, pos2) return (pos1 + pos2) / 2 @@ -326,10 +326,16 @@ end --- Returns a vector of the min components of 2 vectors. --- @param pos1 Vector3 The first vector to operate on. --- @param pos2 Vector3 The second vector to operate on. +-- @param pos1 Vector3|number The first vector to operate on. +-- @param pos2 Vector3|number The second vector to operate on. -- @return Vector3 The minimum values from the input vectors function Vector3.min(pos1, pos2) + if type(pos1) == "number" then + pos1 = Vector3.new(pos1, pos1, pos1) + end + if type(pos2) == "number" then + pos2 = Vector3.new(pos2, pos2, pos2) + end return Vector3.new( math.min(pos1.x, pos2.x), math.min(pos1.y, pos2.y), @@ -342,6 +348,12 @@ end -- @param pos2 Vector3 The second vector to operate on. -- @return Vector3 The maximum values from the input vectors. function Vector3.max(pos1, pos2) + if type(pos1) == "number" then + pos1 = Vector3.new(pos1, pos1, pos1) + end + if type(pos2) == "number" then + pos2 = Vector3.new(pos2, pos2, pos2) + end return Vector3.new( math.max(pos1.x, pos2.x), math.max(pos1.y, pos2.y),