szalloc

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const MaxIters = 100

MaxIters is maximum number of iterations for adapting sizes to fit constraints

Variables

This section is empty.

Functions

func Area

func Area(sz image.Point) int

func PointsClone

func PointsClone(pts []image.Point) []image.Point

PointsClone returns clone of []image.Point list

func SizeGroups

func SizeGroups(sizes []int, maxN int) []int

SizeGroups returns evenly spaced size groups of max N -- could be less

func UniqSortedInts

func UniqSortedInts(vals []int) []int

UniqSortedInts returns the ints in sorted order with only unique vals

func XYFromGpIndex added in v0.0.10

func XYFromGpIndex(gi, nxi int) (xi, yi int)

XYFromGpIndex returns x, y indexes from gp index

Types

type Indexes added in v0.0.10

type Indexes struct {

	// percent size of this image relative to max size allocated
	PctSize math32.Vector2

	// group index
	GpIndex int

	// item index within group (e.g., Layer)
	ItemIndex int
}

Indexes contains the indexes where a given item image size is allocated there is one of these per each ItemSizes

func NewIndexes added in v0.0.10

func NewIndexes(gpi, itmi int, sz, mxsz image.Point) *Indexes

func (*Indexes) Set added in v0.0.10

func (ii *Indexes) Set(gpi, itmi int, sz, mxsz image.Point)

type SzAlloc

type SzAlloc struct {

	// true if configured and ready to use
	On bool

	// maximum number of groups in X and Y dimensions
	MaxGps image.Point

	// maximum number of groups = X * Y
	MaxNGps int

	// maximum number of items per group -- constraint is enforced in addition to MaxGps
	MaxItemsPerGp int

	// original list of item sizes to be allocated
	ItemSizes []image.Point

	// list of all unique sizes -- operate on this for grouping
	UniqSizes []image.Point

	// map of all unique sizes, with group index as value
	UniqSzMap map[image.Point]int

	// indexes into UniqSizes slice, ordered by ItemSizes indexes
	UniqSzItems []int

	// list of allocated group sizes
	GpSizes []image.Point

	// allocation of image indexes by group -- first index is group, second is list of items for that group
	GpAllocs [][]int

	// allocation image value indexes to image indexes
	ItemIndexes []*Indexes

	// sorted list of all unique sizes
	XSizes []int

	// sorted list of all unique sizes
	YSizes []int

	// number of items in each dimension group (X, Y)
	GpNs image.Point

	// list of x group indexes
	XGpIndexes []int

	// list of y group indexes
	YGpIndexes []int
}

SzAlloc manages allocation of sizes to a spec'd maximum number of groups. Used for allocating texture images to image arrays under the severe constraints of only 16 images. Only a maximum of MaxItemsPerGp items can be allocated per grouping.

func (*SzAlloc) Alloc

func (sa *SzAlloc) Alloc()

Alloc allocates items as a function of size

func (*SzAlloc) AllocGpItems

func (sa *SzAlloc) AllocGpItems()

AllocGpItems allocates items in groups based on final GpAllocs

func (*SzAlloc) AllocGps

func (sa *SzAlloc) AllocGps(xgpi, ygpi []int) (allocs [][]int, maxItems int)

AllocGps allocates groups based on given indexes into XSizes, YSizes. returns allocs = indexes of items per each group, and max number of items per group

func (*SzAlloc) AllocItemsNoGps

func (sa *SzAlloc) AllocItemsNoGps()

AllocItemsNoGps directly allocate items each to their own group -- all fits

func (*SzAlloc) AllocItemsUniqGps

func (sa *SzAlloc) AllocItemsUniqGps()

AllocItemsUniqGps directly allocate items each to their own unique-sized group

func (*SzAlloc) LimitGpNs

func (sa *SzAlloc) LimitGpNs()

LimitGpNs updates group sizes to ensure that the MaxItemsPerGp limit is not exceeded.

func (*SzAlloc) PrintGps

func (sa *SzAlloc) PrintGps()

PrintGps prints the group allocations

func (*SzAlloc) SetSizes

func (sa *SzAlloc) SetSizes(gps image.Point, itmsPerGp int, itms []image.Point)

SetSizes sets the max number of groups along each dimension (X, Y), so total number of groups is X*Y, and max items per group, and item sizes to organize -- directly uses the given slice so it should not be something that is reallocated.

func (*SzAlloc) SizesFromIndexes added in v0.0.10

func (sa *SzAlloc) SizesFromIndexes(xgpi, ygpi []int) []image.Point

SizesFromIndexes returns X,Y sizes from X,Y indexes in image.Point into XSizes, YSizes arrays

func (*SzAlloc) UniqSz

func (sa *SzAlloc) UniqSz()

UniqSz computes unique sizes

func (*SzAlloc) UpdateGpMaxSz

func (sa *SzAlloc) UpdateGpMaxSz()

UpdateGpMaxSz updates the group sizes based on actual max sizes of items

func (*SzAlloc) XYSizeFromIndex added in v0.0.10

func (sa *SzAlloc) XYSizeFromIndex(idx image.Point) image.Point

XYSizeFromIndex returns X,Y sizes from X,Y indexes in image.Point into XSizes, YSizes

Jump to

Keyboard shortcuts

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