User Tools

Site Tools


maxrects-lua

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
maxrects-lua [2021/02/13 08:10]
muragami [Rectangles]
maxrects-lua [2021/02/13 10:21]
muragami [:insertCollection(collect,sort)]
Line 78: Line 78:
   * **The field 'flipped' is set to true** if the rectangle was flipped to fit, assuming the algorithm allows that.   * **The field 'flipped' is set to true** if the rectangle was flipped to fit, assuming the algorithm allows that.
  
 +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 
 +</code> 
 + 
 +===== Functions (module) =====
  
 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:init(width,height,canflip) allows you to call later MaxRects:insert(), etc. The .new() is protected from changes you might make using MaxRects: calls and will always return a blank instance. Creates a new instance of a packing algorithm. This can be bypassed if you ever just need on instance, calling MaxRects:init(width,height,canflip) allows you to call later MaxRects:insert(), etc. The .new() is protected from changes you might make using MaxRects: calls and will always return a blank instance.
 +
 +==== 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) =====
  
 ==== :reset(width,height,canflip) ==== ==== :reset(width,height,canflip) ====
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.
  
 +==== :insertRect(rect) ====
 +
 +  * **rect**: The rectangle to insert. X/Y([0]/[1]) are ignored, only Width([3]) and Height([4]) count.
 +
 +  * **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.
 +
 +==== :insertCollection(collect,sort) ====
 +
 +  * **collect**: A table array of rectangles to insert into the collection (see [[#:insertRect(rect)]])
 +  * **//sort//**: //optional// A method to sort the rectangles before insert.
 +
 +  * **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: 'SortArea', 'SortShortSide', or 'SortLongSide' it will sort them from biggest to smallest using that method before inserting. If you pass anything else as sort, it'll throw an error. Note: **table.sort() is applied to collect, so it's order might/will be changed by this function.**
 ==== :occupancy() ==== ==== :occupancy() ====
  
Line 131: Line 167:
 </code> </code>
  
 +==== :setAlgorithm(algo) ====
 +
 +  * **algo**: The algorithm to use for this instance. Defaults to 'BestShortSideFit'.
 +
 +Applies a given algorithm to the packer. The options are: 'BestShortSideFit', 'BestLongSideFit', 'BestAreaFit', and 'ContactPointRule'. Passing any other value will throw an error.
 +
 +==== :algorithmName() ====
 +
 +  * **return**: The algorithm in use for this instance. Defaults to 'BestShortSideFit'.
 +
 +Returns the algorithm in use by the packer. The options are: 'BestShortSideFit', 'BestLongSideFit', 'BestAreaFit', and 'ContactPointRule'.
 +
 +===== Simple LÖVE Texture Packer =====
  
 +TODO!
maxrects-lua.txt · Last modified: 2021/02/13 10:21 by muragami