Documentation
¶
Overview ¶
Package rectpack packs rectangles into larger rectangles.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AutoPackSingle ¶
AutoPackSingle packs the given rectangles into a single bin, making the bin as large as necessary to contain all rectangles. Tries to minimize wasted space when the bounds are increased to powers of two. Returns the size of the bin and the location of each rectangle.
Types ¶
type IndexPoint ¶
An IndexPoint is a point in one of multiple possible bins. The index identifies which bin it is in.
func AutoPackMultiple ¶
func AutoPackMultiple(p Packer, bounds Point, size []Point) (count int, pos []IndexPoint, err error)
AutoPackMultiple packes the given rectangels into multiple bins of the same size, using as many bins as necessary to contain all the rectangles. Returns the number of bins and the locations of the rectangles.
type MaxRects ¶
type MaxRects struct {
// contains filtered or unexported fields
}
A MaxRects is a structure that tracks free space in a rectangle.
type MaxRectsBL ¶
type MaxRectsBL struct {
// contains filtered or unexported fields
}
MaxRectsBL (MaxRects, bottom-left) packer packs rectangles into a rectangle, minimizing the Y coordinate of each rect.
func (*MaxRectsBL) AddRect ¶
func (p *MaxRectsBL) AddRect(size Point) (pos Point, ok bool)
AddRect implements the Packer interface.
func (*MaxRectsBL) Reset ¶
func (p *MaxRectsBL) Reset(bounds Point)
Reset implements the Packer interface.
type Order ¶
type Order uint32
An Order is a rectangle sort order.
const ( // Unsorted does not sort rectangles. Unsorted Order = iota // WidthDesc sorts widest rectangle first. WidthDesc // WidthAsc sorts widest rectangle last. WidthAsc // HeightDesc sorts tallest rectangle first. HeightDesc // HeightAsc sorts tallest rectangle last. HeightAsc // AreaDesc sorts largest area rectangle first. AreaDesc // AreaAsc sorts largest area rectangle last. AreaAsc // PerimeterDesc sorts largest perimeter first. PerimeterDesc // PerimeterAsc sorts largest perimeter last. PerimeterAsc // DifferenceDesc sorts largest difference between width and height first. DifferenceDesc // DifferenceAsc sorts largest difference between width and height last. DifferenceAsc // RatioDesc sorts largest aspect ratio first. RatioDesc // RatioAsc sorts largest aspect ratio last. RatioAsc )
type Packer ¶
type Packer interface { // Name returns the name of the algorithm. Name() string // Reset resets the packer to contain free space with the given bounds. Reset(bounds Point) // AddRect adds a rectangle to the packing and returns the minimum // coordinate of the rectangle. Returns false if no space can be found. AddRect(size Point) (pos Point, ok bool) // contains filtered or unexported methods }
A Packer is an algorithm which packs rectangles into larger bounds.
func AllAlgorithms ¶
func AllAlgorithms() []Packer
AllAlgorithms returns implementations of all supported algorithms.
type SortedPacker ¶
A SortedPacker sorts rectangles before packing them.
func (*SortedPacker) Name ¶
func (p *SortedPacker) Name() string
Name implements the Packer interface.