local assertArgs = include "assertArgs" local util = include "util" local Bounds = lib "class" ("Bounds") Bounds:include(mixin "Position") Bounds:include(mixin "Dimensions") function Bounds:initialize(args) assertArgs(args, "x", "y", "z", "width", "height", "depth") self:setPosition(args.x, args.y, args.z) self:setDimensions(args.width, args.height, args.depth) return self end function Bounds:isWithin(x, y, z) local minX, maxX, minY, maxY, minZ, maxZ = self:unpack() return (x >= minX and x <= maxX) and (y >= minY and y <= maxY) and (z >= minZ and z <= maxZ) end function Bounds:unpack() local halfW, halfH, halfD = self:getWidth() / 2, self:getHeight() / 2, self:getDepth() / 2 return self:getX() - halfW, self:getX() + halfW, self:getY() - halfH, self:getY() + halfH, self:getZ() - halfD, self:getZ() + halfD end return Bounds