stbrp

package
v0.0.0-...-c17e622 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	STBRP_HEURISTIC_Skyline_default       = 0
	STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default
	STBRP_HEURISTIC_Skyline_BF_sortHeight = 1
)
View Source
const STBRP_LARGE_RECTS = false
View Source
const (
	STBRP__INIT_skyline = 1
)
View Source
const STBRP__MAXVAL = 0xffff
View Source
const STB_RECT_PACK_VERSION = 1

Variables

This section is empty.

Functions

func InitTarget

func InitTarget(context *Context, width, height int, nodes []Node, num_nodes int)

InitTarget Initialize a rectangle packer to:

pack a rectangle that is 'width' by 'height' in dimensions
using temporary storage provided by the array 'nodes', which is 'num_nodes' long

You must call this function every time you start packing into a new target.

There is no "shutdown" function. The 'nodes' memory must stay valid for the following stbrp_pack_rects() call (or calls), but can be freed after the call (or calls) finish.

Note: to guarantee best results, either:

  1. make sure 'num_nodes' >= 'width' or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'

If you don't do either of the above things, widths will be quantized to multiples of small integers to guarantee the algorithm doesn't run out of temporary storage.

If you do #2, then the non-quantized algorithm will be used, but the algorithm may run out of temporary storage and be unable to pack some rectangles.

func PackRects

func PackRects(context *Context, rects []Rect, num_rects int) int

PackRects Assign packed locations to rectangles. The rectangles are of type 'stbrp_rect' defined below, stored in the array 'rects', and there are 'num_rects' many of them.

Rectangles which are successfully packed have the 'was_packed' flag set to a non-zero value and 'x' and 'y' store the minimum location on each axis (i.e. bottom-left in cartesian coordinates, top-left if you imagine y increasing downwards). Rectangles which do not fit have the 'was_packed' flag set to 0.

You should not try to access the 'rects' array from another thread while this function is running, as the function temporarily reorders the array while it executes.

To pack into another rectangle, you need to call stbrp_init_target again. To continue packing into the same rectangle, you can call this function again. Calling this multiple times with multiple rect arrays will probably produce worse packing results than calling it a single time with the full rectangle array, but the option is available.

The function returns 1 if all of the rectangles were successfully packed and 0 otherwise.

func STBRP_ASSERT

func STBRP_ASSERT(cond bool)

func STBRP_SORT

func STBRP_SORT(slice any, _ int, _ uintptr, compare func(a, b any) int)

Types

type Context

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

type Coord

type Coord uint16

type Node

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

type Rect

type Rect struct {
	// reserved for your use:
	ID int

	// input:
	W, H Coord

	// output:
	X, Y Coord

	WasPacked int
}

Jump to

Keyboard shortcuts

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