UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

81 lines 2.78 kB
/** * Packs rectangles into a finite area, packer is incremental and supports both insertions and removals of rectangles. * Implementation of "max rectangles" packing algorithm. * Useful for packing texture atlases. * * @see "A Thousand Ways to Pack the Bin - A Practical Approach to Two-Dimensional Rectangle Bin Packing" 2010 Jukka Jylänki */ export class MaxRectanglesPacker { /** * * @param {number} width * @param {number} height */ constructor(width: number, height: number); size: Vector2; /** * * @type {QuadTreeNode} */ free: QuadTreeNode<any>; /** * Currently held boxes. * Managed internally, do not modify. * @readonly * @type {AABB2[]} */ readonly boxes: AABB2[]; /** * * @param {AABB2} box exact box to remove * @returns {boolean} true when box is removed, false if not found */ remove(box: AABB2): boolean; /** * * @param {AABB2[]} boxes * @returns {number} How many failed to be removed. Each failure represents a box which was not packed in the first place. */ removeMany(boxes: AABB2[]): number; /** * Pack a given box. * Atomic, if box fails packing - the existing data structure is unchanged. * @param {AABB2} box * @returns {boolean} true if box was successfully added into the packing, false otherwise */ add(box: AABB2): boolean; /** * Tests whether a rectangle of given dimensions can be packed into remaining space * Essentially, if this method succeeds - insertion will succeed as well, and if it fails - insertion will fail too * @param {number} w * @param {number} h * @return {boolean} */ canAdd(w: number, h: number): boolean; /** * Method is transactional, if one box fails to be packed, all fail and packer is reverted to original state * @param {AABB2[]} boxes * @returns {boolean} */ addMany(boxes: AABB2[]): boolean; /** * Re-packs all rectangles. If repack fails - all boxes are removed. * * @returns {boolean} true if successful, false if there was not enough space found during packing */ repack(): boolean; /** * Clear out all the data from the packer */ clear(): void; /** * Resize the packer canvas, may trigger repacking if new dimensions are smaller than the existing ones * @param {number} width * @param {number} height * @returns {boolean} false if packing fails after resize, true otherwise */ resize(width: number, height: number): boolean; } import Vector2 from "../../Vector2.js"; import { QuadTreeNode } from "../../2d/quad-tree/QuadTreeNode.js"; //# sourceMappingURL=MaxRectanglesPacker.d.ts.map