binpack2d

package
v0.1.24-mps Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2023 License: MIT Imports: 1 Imported by: 0

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

View Source
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 Create

func Create(width, height int) *Packer

Create creates a new empty BinPacker structure of given dimension.

func CreateWithName

func CreateWithName(width int, height int, name string) *Packer

func (*Packer) Clear

func (p *Packer) Clear()

Clear removes all items from the list of used rectangles.

func (*Packer) DeepCopy

func (p *Packer) DeepCopy() *Packer

func (*Packer) GetHeight

func (p *Packer) GetHeight() int

GetHeight returns the height of the current bin.

func (*Packer) GetOccupancy

func (p *Packer) GetOccupancy() float32

GetOccupancy computes the ratio of used surface area to the total bin area.

func (*Packer) GetUsedRectangle

func (p *Packer) GetUsedRectangle(index int) Rectangle

GetUsedRectangle returns the stored rectangle at the specified index. Returns an empty rectangle if the index is out of range.

func (*Packer) GetUsedRectanglesLength

func (p *Packer) GetUsedRectanglesLength() int

GetUsedRectanglesLength returns the number of rectangles stored in the current bin.

func (*Packer) GetWidth

func (p *Packer) GetWidth() int

GetWidth returns the width of the current bin.

func (*Packer) Insert

func (p *Packer) Insert(width, height, rule int) (rect Rectangle, ok bool)

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) PrintInfo

func (p *Packer) PrintInfo()

func (*Packer) Reset

func (p *Packer) Reset(width, height int)

Reset removes all rectangles in the packer object and sets the bin size to the given dimension.

func (*Packer) ShrinkBin

func (p *Packer) ShrinkBin(binary bool)

ShrinkBin attempts to shrink the current bin as much as possible. Use "binary" to specify whether to reduce dimensions by a fixed 50% per iteration.

func (*Packer) TryInsert

func (p *Packer) TryInsert(width, height, rule int) (rect Rectangle, ok bool)

type Rectangle

type Rectangle struct{ X, Y, W, H int }

The Rectangle structure defines position and size of a rectangle.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL