maxrect

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2018 License: MIT Imports: 1 Imported by: 2

Documentation

Overview

maxrect implements MaxRects packing algorithm

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonInterval

func CommonInterval(a0, a1, b0, b1 int) int

func FindBest

func FindBest(frees []image.Rectangle, size image.Point, rotate bool, score ScoreFn) (image.Rectangle, int, int)

FindBest finds the best position for size, rotating when allowed

func FitsInto

func FitsInto(free image.Rectangle, size image.Point) bool

FitsInto checks whether size can be fit into free

Types

type Context

type Context struct {
	Size   image.Point
	Rotate bool
	Score  func(size image.Point) (image.Rectangle, int, int)

	Used []image.Rectangle
	Free []image.Rectangle

	DebugPlace func(r image.Rectangle)
}

func New

func New(size image.Point) *Context

func (*Context) Add

func (context *Context) Add(size image.Point) (r image.Rectangle, ok bool)

func (*Context) Adds

func (context *Context) Adds(size ...image.Point) (r []image.Rectangle, ok bool)

func (*Context) Area

func (context *Context) Area(size image.Point) (image.Rectangle, int, int)

func (*Context) BottomLeft

func (context *Context) BottomLeft(size image.Point) (image.Rectangle, int, int)

func (*Context) ContactPoint

func (context *Context) ContactPoint(size image.Point) (image.Rectangle, int, int)

func (*Context) LongSide

func (context *Context) LongSide(size image.Point) (image.Rectangle, int, int)

func (*Context) PlaceRect

func (context *Context) PlaceRect(rect image.Rectangle)

func (*Context) SetRule

func (context *Context) SetRule(rule Rule)

func (*Context) ShortSide

func (context *Context) ShortSide(size image.Point) (image.Rectangle, int, int)

type Rule

type Rule byte
const (
	Automatic Rule = iota
	ShortSide
	LongSide
	BottomLeft
	Area
	ContactPoint
)

func ParseRule

func ParseRule(s string) Rule

type ScoreFn

type ScoreFn func(free image.Rectangle, size image.Point) (int, int)

ScoreFn scores how well size can be placed into free

(maxInt, maxInt) - worst
(0, 0)           - best

Jump to

Keyboard shortcuts

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