Documentation
¶
Overview ¶
Package binpack2d implements a two-dimensional rectangle bin packing algorithm. It is loosely based on Jukka Jylänki's C++ implementation of RectangleBinPack->MaxRectsBinPack.
Index ¶
- Constants
- type Packer
- func (p *Packer) Clear()
- func (p *Packer) DeepCopy() *Packer
- func (p *Packer) GetHeight() int
- func (p *Packer) GetOccupancy() float32
- func (p *Packer) GetUsedRectangle(index int) Rectangle
- func (p *Packer) GetUsedRectanglesLength() int
- func (p *Packer) GetWidth() int
- func (p *Packer) Insert(width, height, rule int) (rect Rectangle, ok bool)
- func (p *Packer) PrintInfo()
- func (p *Packer) Reset(width, height int)
- func (p *Packer) ShrinkBin(binary bool)
- func (p *Packer) TryInsert(width, height, rule int) (rect Rectangle, ok bool)
- type Rectangle
Constants ¶
const ( RULE_BEST_SHORT_SIDE_FIT = iota RULE_BEST_LONG_SIDE_FIT RULE_BEST_AREA_FIT RULE_BOTTOM_LEFT RULE_CONTACT_POINT )
List of different heuristic rules that can be used when deciding where to place a new rectangle.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Packer ¶
type Packer struct {
// contains filtered or unexported fields
}
The Packer structure defines a single rectangular bin.
func (*Packer) Clear ¶
func (p *Packer) Clear()
Clear removes all items from the list of used rectangles.
func (*Packer) GetOccupancy ¶
GetOccupancy computes the ratio of used surface area to the total bin area.
func (*Packer) GetUsedRectangle ¶
GetUsedRectangle returns the stored rectangle at the specified index. Returns an empty rectangle if the index is out of range.
func (*Packer) GetUsedRectanglesLength ¶
GetUsedRectanglesLength returns the number of rectangles stored in the current bin.
func (*Packer) Insert ¶
Insert inserts a single rectangle to the bin by using the specified packing rule. Returns the packed Rectangle structure, or sets "ok" to false if no fit could be found.
func (*Packer) Reset ¶
Reset removes all rectangles in the packer object and sets the bin size to the given dimension.