packing

package
v0.0.0-...-b8a6a29 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: Unlicense Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInputTooLarge = errors.New("input too large, can not be processed")

ErrInputTooLarge means that a given block was larger than the max size of the packer - it can not possibly fit

View Source
var ErrOutOfRoom = errors.New("out of room")

ErrOutOfRoom indicates that the packer does not have enough room left for the block to be packed successfully.

Functions

This section is empty.

Types

type BinPacker

type BinPacker struct {
	// contains filtered or unexported fields
}

func NewBinPacker

func NewBinPacker(width, height int) *BinPacker

NewBinPacker returns a packer with the given width and height

func (*BinPacker) Height

func (b *BinPacker) Height() int

Height returns the height of the BinPacker (immutable)

func (*BinPacker) Pack

func (b *BinPacker) Pack(block Block) error

Pack implements the Packer interface

func (*BinPacker) Size

func (b *BinPacker) Size() (int, int)

Size returns the width and height of the BinPacker

func (*BinPacker) Width

func (b *BinPacker) Width() int

Width returns the width of the BinPacker (immutable)

type Block

type Block interface {
	Size() (w int, h int)
	Place(x int, y int)
}

Block is the interface that represents a unit of space that can be packed alongside other Blocks.

Size returns the width and height of the block.

Place is called by the packer to indicate that the block has successfully been placed at the given position.

type ByArea

type ByArea []Block

ByArea implements sort Interface for []Block based on the Area of each block.

func (ByArea) Len

func (a ByArea) Len() int

func (ByArea) Less

func (a ByArea) Less(i, j int) bool

func (ByArea) Swap

func (a ByArea) Swap(i, j int)

type ByMaxSide

type ByMaxSide []Block

ByMaxSide implements sort interface for []Block by comparing the maximum side (width or height) of each block

func (ByMaxSide) Len

func (a ByMaxSide) Len() int

func (ByMaxSide) Less

func (a ByMaxSide) Less(i, j int) bool

func (ByMaxSide) Swap

func (a ByMaxSide) Swap(i, j int)

type GrowingPacker

type GrowingPacker struct {
	// contains filtered or unexported fields
}

type Packer

type Packer interface {
	Pack(block Block) error
}

Packer is the interface that wraps the Pack method.

Jump to

Keyboard shortcuts

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