This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
|
maxrects-lua [2021/02/13 08:10] muragami [Rectangles] |
maxrects-lua [2021/02/13 10:21] (current) muragami [:insertCollection(collect,sort)] |
||
|---|---|---|---|
| Line 78: | Line 78: | ||
| * **The field ' | * **The field ' | ||
| + | This format was chosen for ease of use, see these examples: | ||
| - | ===== Functions ===== | + | <code lua> |
| + | -- create a rectangle | ||
| + | MyRect = { 0, 0, 32, 32 } -- as simple as that { X, Y, Width, Height } | ||
| + | -- area of a rectangle | ||
| + | Area = MyRect[3] * MyRect[4] -- Width x Height | ||
| + | -- copy a rectangle | ||
| + | MyOtherRect = MaxRects.copy(MyRect) -- shallow copy of just the 4 indexes and two fields | ||
| + | </ | ||
| + | |||
| + | ===== Functions | ||
| All the exposed functions of this module, with in-depth explanations. | All the exposed functions of this module, with in-depth explanations. | ||
| Line 91: | Line 101: | ||
| Creates a new instance of a packing algorithm. This can be bypassed if you ever just need on instance, calling MaxRects: | Creates a new instance of a packing algorithm. This can be bypassed if you ever just need on instance, calling MaxRects: | ||
| + | |||
| + | ==== MaxRects.copy(rect) ==== | ||
| + | |||
| + | * **rect**: The rectangle to duplicate. | ||
| + | |||
| + | * **return**: A table containing the new copied rectangle. | ||
| + | |||
| + | Creates a shallow copy of a rectangle. Does not duplicate .data for instance, but copies the reference. Explicitly only copies: [1], [2], [3], [4], .data, and .flip. | ||
| + | |||
| + | ===== Functions (instance) ===== | ||
| ==== : | ==== : | ||
| Line 110: | Line 130: | ||
| Inserts a rectangle into the collection, using the algorithm to assign a location. If the rectangle can't fit, returns false. | Inserts a rectangle into the collection, using the algorithm to assign a location. If the rectangle can't fit, returns false. | ||
| + | ==== : | ||
| + | |||
| + | * **rect**: The rectangle to insert. X/ | ||
| + | |||
| + | * **return**: Boolean. True if the rectangle was inserted, False if it didn't fit. | ||
| + | |||
| + | Inserts a rectangle into the collection, using the algorithm to assign a location. If the rectangle can't fit, returns false. Copies .data into the stored node in the collection. | ||
| + | |||
| + | ==== : | ||
| + | |||
| + | * **collect**: | ||
| + | * **// | ||
| + | |||
| + | * **return**: Boolean, Number. True if all were inserted, False if only some fit. The number is the amount added. | ||
| + | |||
| + | Inserts rectangles into the collection, from an array table. If you define sort to one of: ' | ||
| ==== : | ==== : | ||
| Line 131: | Line 167: | ||
| </ | </ | ||
| + | ==== : | ||
| + | |||
| + | * **algo**: The algorithm to use for this instance. Defaults to ' | ||
| + | |||
| + | Applies a given algorithm to the packer. The options are: ' | ||
| + | |||
| + | ==== : | ||
| + | |||
| + | * **return**: The algorithm in use for this instance. Defaults to ' | ||
| + | |||
| + | Returns the algorithm in use by the packer. The options are: ' | ||
| + | |||
| + | ===== Simple LÖVE Texture Packer ===== | ||
| + | TODO! | ||