Add vector.offset (#10321)
This commit is contained in:
parent
5d84294168
commit
3ec4ffeb05
|
@ -44,6 +44,10 @@ describe("vector", function()
|
||||||
assert.same({ x = 2, y = 4, z = 6 }, vector.add(vector.new(1, 2, 3), { x = 1, y = 2, z = 3 }))
|
assert.same({ x = 2, y = 4, z = 6 }, vector.add(vector.new(1, 2, 3), { x = 1, y = 2, z = 3 }))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
it("offset()", function()
|
||||||
|
assert.same({ x = 41, y = 52, z = 63 }, vector.offset(vector.new(1, 2, 3), 40, 50, 60))
|
||||||
|
end)
|
||||||
|
|
||||||
-- This function is needed because of floating point imprecision.
|
-- This function is needed because of floating point imprecision.
|
||||||
local function almost_equal(a, b)
|
local function almost_equal(a, b)
|
||||||
if type(a) == "number" then
|
if type(a) == "number" then
|
||||||
|
|
|
@ -137,6 +137,12 @@ function vector.divide(a, b)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function vector.offset(v, x, y, z)
|
||||||
|
return {x = v.x + x,
|
||||||
|
y = v.y + y,
|
||||||
|
z = v.z + z}
|
||||||
|
end
|
||||||
|
|
||||||
function vector.sort(a, b)
|
function vector.sort(a, b)
|
||||||
return {x = math.min(a.x, b.x), y = math.min(a.y, b.y), z = math.min(a.z, b.z)},
|
return {x = math.min(a.x, b.x), y = math.min(a.y, b.y), z = math.min(a.z, b.z)},
|
||||||
{x = math.max(a.x, b.x), y = math.max(a.y, b.y), z = math.max(a.z, b.z)}
|
{x = math.max(a.x, b.x), y = math.max(a.y, b.y), z = math.max(a.z, b.z)}
|
||||||
|
|
Loading…
Reference in New Issue