rectpack

package
v0.0.0-...-912d621 Latest Latest
Warning

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

Go to latest
Published: May 31, 2022 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package rectpack packs rectangles into larger rectangles.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AutoPackSingle

func AutoPackSingle(p Packer, size []Point) (bounds Point, pos []Point, err error)

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

type IndexPoint struct {
	Index int
	Pos   Point
}

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.

func (*MaxRects) PlaceRect

func (p *MaxRects) PlaceRect(r rect)

PlaceRect places a rectangle in the packing, removing the rectangle from free space.

func (*MaxRects) Reset

func (p *MaxRects) Reset(bounds Point)

Reset resets the structure to contain free space with the given bounds.

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

func (*MaxRectsBL) Name() string

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

func (Order) String

func (o Order) String() (s string)

String implements the Stringer interface.

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.

func New

func New() Packer

New returns the default packer algorithm.

type Point

type Point struct {
	X int32
	Y int32
}

A Point is a 2D point.

type SortedPacker

type SortedPacker struct {
	Packer
	Order Order
}

A SortedPacker sorts rectangles before packing them.

func (*SortedPacker) Name

func (p *SortedPacker) Name() string

Name implements the Packer interface.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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