Top Description Inners Fields Constructors Methods
com.jogamp.opengl.util.packrect

public Class RectanglePacker

extends Object
Class Inheritance
Imports
java.util.*

Packs rectangles supplied by the user (typically representing image regions) into a larger backing store rectangle (typically representing a large texture). Supports automatic compaction of the space on the backing store, and automatic expansion of the backing store, when necessary.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Object
private static final float
private final int
private final int
private LevelSet
private final BackingStoreManager
private int
private int
private static final Comparator<Rect>
private static final float

Constructor Summary

AccessConstructor and Description
public
RectanglePacker(final BackingStoreManager manager, final int initialWidth, final int initialHeight)

Method Summary

Modifier and TypeMethod and Description
public void
add(final Rect rect)

Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged) and places it on the backing store.

public void
clear()

Clears all Rects contained in this RectanglePacker.

public void
compact()

Forces a compaction cycle, which typically results in allocating a new backing store and copying all entries to it.

private void
compactImpl(final Rect cause)

public void
dispose()

Disposes the backing store allocated by the BackingStoreManager.

public Object
public void
remove(final Rect rect)

Removes the given rectangle from this RectanglePacker.

public void
setMaxSize(final int maxWidth, final int maxHeight)

Sets up a maximum width and height for the backing store.

public float
verticalFragmentationRatio()

Returns the vertical fragmentation ratio of this RectanglePacker.

public void
visit(final RectVisitor visitor)

Visits all Rects contained in this RectanglePacker.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

backingStoreback to summary
private Object backingStore
EXPANSION_FACTORback to summary
private static final float EXPANSION_FACTOR
initialHeightback to summary
private final int initialHeight
initialWidthback to summary
private final int initialWidth
levelsback to summary
private LevelSet levels
managerback to summary
private final BackingStoreManager manager
maxHeightback to summary
private int maxHeight
maxWidthback to summary
private int maxWidth
rectHComparatorback to summary
private static final Comparator<Rect> rectHComparator
SHRINK_FACTORback to summary
private static final float SHRINK_FACTOR

Constructor Detail

RectanglePackerback to summary
public RectanglePacker(final BackingStoreManager manager, final int initialWidth, final int initialHeight)

Method Detail

addback to summary
public void add(final Rect rect) throws RuntimeException

Decides upon an (x, y) position for the given rectangle (leaving its width and height unchanged) and places it on the backing store. May provoke re-layout of other Rects already added. If the BackingStoreManager does not support compaction, and BackingStoreManager.preExpand does not clear enough space for the incoming rectangle, then this method will throw a RuntimeException.

clearback to summary
public void clear()

Clears all Rects contained in this RectanglePacker.

compactback to summary
public void compact()

Forces a compaction cycle, which typically results in allocating a new backing store and copying all entries to it.

compactImplback to summary
private void compactImpl(final Rect cause)
disposeback to summary
public void dispose()

Disposes the backing store allocated by the BackingStoreManager. This RectanglePacker may no longer be used after calling this method.

getBackingStoreback to summary
public Object getBackingStore()
removeback to summary
public void remove(final Rect rect)

Removes the given rectangle from this RectanglePacker.

setMaxSizeback to summary
public void setMaxSize(final int maxWidth, final int maxHeight)

Sets up a maximum width and height for the backing store. These are optional and if not specified the backing store will grow as necessary. Setting up a maximum width and height introduces the possibility that additions will fail; these are handled with the BackingStoreManager's allocationFailed notification.

verticalFragmentationRatioback to summary
public float verticalFragmentationRatio()

Returns the vertical fragmentation ratio of this RectanglePacker. This is defined as the ratio of the sum of the heights of all completely empty Levels divided by the overall used height of the LevelSet. A high vertical fragmentation ratio indicates that it may be profitable to perform a compaction.

visitback to summary
public void visit(final RectVisitor visitor)

Visits all Rects contained in this RectanglePacker.

com.jogamp.opengl.util.packrect back to summary

pack-priv Class RectanglePacker.RectHComparator

extends Object
implements Comparator<Rect>
Class Inheritance
  • java.lang.Object
  • com.jogamp.opengl.util.packrect.RectanglePacker.RectHComparator
All Implemented Interfaces
java.util.Comparator

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public int
compare(final Rect
the first object to be compared.
r1
,
final Rect
the second object to be compared.
r2
)

Implements java.util.Comparator.compare.

Compares its two arguments for order.
public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Indicates whether some other object is "equal to" this comparator.
Inherited from java.lang.Object:
clonefinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

RectHComparatorback to summary
pack-priv RectHComparator()

Method Detail

compareback to summary
public int compare(final Rect r1, final Rect r2)

Implements java.util.Comparator.compare.

Doc from java.util.Comparator.compare.

Compares its two arguments for order. Returns a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

The implementor must ensure that signum(compare(x, y)) == -signum(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)

The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0.

Finally, the implementor must ensure that compare(x, y)==0 implies that signum(compare(x, z))==signum(compare(y, z)) for all z.

Parameters
r1:Rect

the first object to be compared.

r2:Rect

the second object to be compared.

Returns:int

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

Annotations
@Override
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Implements java.util.Comparator.equals.

Doc from java.util.Comparator.equals.

Indicates whether some other object is "equal to" this comparator. This method must obey the general contract of Object#equals(Object). Additionally, this method can return true only if the specified object is also a comparator and it imposes the same ordering as this comparator. Thus, comp1.equals(comp2) implies that signum(comp1.compare(o1, o2))==signum(comp2.compare(o1, o2)) for every object reference o1 and o2.

Note that it is always safe not to override Object.equals(Object). However, overriding this method may, in some cases, improve performance by allowing programs to determine that two distinct comparators impose the same order.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true only if the specified object is also a comparator and it imposes the same ordering as this comparator.

Annotations
@Override