--- Compiles a list of rotations into something we can iteratively pass to Vector3.rotate3d.
-- This function is called internally. You are unlikely to need to call this function unless you are implementing something like worldeditadditions.rotate() or similar.
--
-- TODO Learn Quaternions.
-- @internal
-- @param rotlist table<{axis: string|Vector3, rad: number}> The list of rotations. Rotations will be processed in order. Each rotation is a table with a SINGLE axis as a string (x, y, z, -x, -y, or -z; the axis parameter) or a Vector3 (only a SINGLE AXIS set to anything other than 0, and ONLY with a value of 1 or -1), and an amount in radians to rotate by (the rad parameter.
-- @returns Vector3[] The list of the compiled rotations, in a form that Vector3.rotate3d understands.
localfunctionrotlist_compile(rotlist)
returnweac.table.map(rotlist,function(rot)
--- 1: Construct a Vector3 to represent which axis we want to rotate on
localrotval=Vector3.new(0,0,0)
-- Assume that if it's a table, it's a Vector3 instance
iftype(rot)=="table"then
rotval=rot.axis:clone()
else
-- Otherwise, treat it as a string
ifrot.axis:find("x",1,true)then
rotval.x=1
elseifrot.axis:find("y",1,true)then
rotval.y=1
elseifrot.axis:find("z",1,true)then
rotval.z=1
end
ifrot.axis:sub(1,1)=="-"then
rotval=rotval*-1
end
end
--- 2: Rotate & apply amount of rotation to apply in radians
returnrotval*rot.rad
end)
end
--- Applies a given list of rotatiosn rotlist to rotate pos1 and pos2 around a given origin, and returns a pos1/pos2 pair of a region that bounds the rotated area.
-- The returned pos1/pos2 are guaranteed to be integer values that fully enclose the rotated region. This function is designed to be used to e.g. find the bounds of a region to pass to a VoxelManip to ensure we grab everything.
-- @param pos1 Vector3 Position 1 to rotate.
-- @param pos2 Vector3 Position 2 to rotate.
-- @param origin Vector3 The position to rotate pos1 and pos2 around. May be a decimal value.
-- @param rotlist table<{axis: string, rad: number}> The list of rotations. Rotations will be processed in order. Each rotation is a table with a SINGLE axis as a string (x, y, z, -x, -y, or -z; the axis parameter), and an amount in radians to rotate by (the rad parameter). See worldeditadditions.rotate() for more information.
-- @returns Vector3,Vector3 A pos1 & pos2 that fully enclose the rotated region as described above.