当前位置: 首页>>代码示例>>Java>>正文


Java MathUtils.nextPowerOfTwo方法代码示例

本文整理汇总了Java中com.badlogic.gdx.math.MathUtils.nextPowerOfTwo方法的典型用法代码示例。如果您正苦于以下问题:Java MathUtils.nextPowerOfTwo方法的具体用法?Java MathUtils.nextPowerOfTwo怎么用?Java MathUtils.nextPowerOfTwo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.badlogic.gdx.math.MathUtils的用法示例。


在下文中一共展示了MathUtils.nextPowerOfTwo方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ObjectMap

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before
 * growing the backing table.
 * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
public ObjectMap (int initialCapacity, float loadFactor) {
	if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
	initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
	if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
	capacity = initialCapacity;

	if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
	this.loadFactor = loadFactor;

	threshold = (int)(capacity * loadFactor);
	mask = capacity - 1;
	hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
	stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2);
	pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8);

	keyTable = (K[])new Object[capacity + stashCapacity];
	valueTable = (V[])new Object[keyTable.length];
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:22,代码来源:ObjectMap.java

示例2: ObjectSet

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Creates a new set with the specified initial capacity and load factor. This set will hold initialCapacity items before
 * growing the backing table.
 * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
public ObjectSet (int initialCapacity, float loadFactor) {
	if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
	initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
	if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
	capacity = initialCapacity;

	if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
	this.loadFactor = loadFactor;

	threshold = (int)(capacity * loadFactor);
	mask = capacity - 1;
	hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
	stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2);
	pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8);

	keyTable = (T[])new Object[capacity + stashCapacity];
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:21,代码来源:ObjectSet.java

示例3: IntMap

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Creates a new map with the specified initial capacity and load factor. This map will hold initialCapacity items before
 * growing the backing table.
 * @param initialCapacity If not a power of two, it is increased to the next nearest power of two. */
public IntMap (int initialCapacity, float loadFactor) {
	if (initialCapacity < 0) throw new IllegalArgumentException("initialCapacity must be >= 0: " + initialCapacity);
	initialCapacity = MathUtils.nextPowerOfTwo((int)Math.ceil(initialCapacity / loadFactor));
	if (initialCapacity > 1 << 30) throw new IllegalArgumentException("initialCapacity is too large: " + initialCapacity);
	capacity = initialCapacity;

	if (loadFactor <= 0) throw new IllegalArgumentException("loadFactor must be > 0: " + loadFactor);
	this.loadFactor = loadFactor;

	threshold = (int)(capacity * loadFactor);
	mask = capacity - 1;
	hashShift = 31 - Integer.numberOfTrailingZeros(capacity);
	stashCapacity = Math.max(3, (int)Math.ceil(Math.log(capacity)) * 2);
	pushIterations = Math.max(Math.min(capacity, 8), (int)Math.sqrt(capacity) / 8);

	keyTable = new int[capacity + stashCapacity];
	valueTable = (V[])new Object[keyTable.length];
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:22,代码来源:IntMap.java

示例4: createTextureFromBytes

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/**
 * Transforms byte[] to Texture Region.
 * <p>
 * If you are going to call this method inside firebase callback remember to wrap it<p>
 * into {@code Gdx.app.postRunnable(Runnable)}.
 * The texture will be changed so that it has sides with length of power of 2.
 *
 * @param bytes Byte array with image description
 * @return Texture region representation of given byte array
 */
public static TextureRegion createTextureFromBytes(byte[] bytes)
{
    Pixmap pixmap = new Pixmap(bytes, 0, bytes.length);
    final int orgWidth = pixmap.getWidth();
    final int orgHeight = pixmap.getHeight();
    int width = MathUtils.nextPowerOfTwo(orgWidth);
    int height = MathUtils.nextPowerOfTwo(orgHeight);
    final Pixmap potPixmap = new Pixmap(width, height, pixmap.getFormat());
    potPixmap.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight());
    pixmap.dispose();
    TextureRegion region = new TextureRegion(new Texture(potPixmap), 0, 0, orgWidth, orgHeight);
    potPixmap.dispose();
    return region;
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:25,代码来源:ImageHelper.java

示例5: shrink

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Reduces the size of the backing arrays to be the specified capacity or less. If the capacity is already less, nothing is
 * done. If the map contains more items than the specified capacity, the next highest power of two capacity is used instead. */
public void shrink (int maximumCapacity) {
	if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
	if (size > maximumCapacity) maximumCapacity = size;
	if (capacity <= maximumCapacity) return;
	maximumCapacity = MathUtils.nextPowerOfTwo(maximumCapacity);
	resize(maximumCapacity);
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:10,代码来源:ObjectMap.java

示例6: shrink

import com.badlogic.gdx.math.MathUtils; //导入方法依赖的package包/类
/** Reduces the size of the backing arrays to be the specified capacity or less. If the capacity is already less, nothing is
 * done. If the set contains more items than the specified capacity, the next highest power of two capacity is used instead. */
public void shrink (int maximumCapacity) {
	if (maximumCapacity < 0) throw new IllegalArgumentException("maximumCapacity must be >= 0: " + maximumCapacity);
	if (size > maximumCapacity) maximumCapacity = size;
	if (capacity <= maximumCapacity) return;
	maximumCapacity = MathUtils.nextPowerOfTwo(maximumCapacity);
	resize(maximumCapacity);
}
 
开发者ID:Guerra24,项目名称:NanoUI,代码行数:10,代码来源:ObjectSet.java


注:本文中的com.badlogic.gdx.math.MathUtils.nextPowerOfTwo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。