use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.
the class ConvexHull method computeIndices.
/** Computes a hull the same as {@link #computePolygon(float[], int, int, boolean)} but returns indices of the specified points. */
public IntArray computeIndices(float[] points, int offset, int count, boolean sorted, boolean yDown) {
int end = offset + count;
if (!sorted) {
if (sortedPoints == null || sortedPoints.length < count)
sortedPoints = new float[count];
System.arraycopy(points, offset, sortedPoints, 0, count);
points = sortedPoints;
offset = 0;
sortWithIndices(points, count, yDown);
}
IntArray indices = this.indices;
indices.clear();
FloatArray hull = this.hull;
hull.clear();
// Lower hull.
for (int i = offset, index = i / 2; i < end; i += 2, index++) {
float x = points[i];
float y = points[i + 1];
while (hull.size >= 4 && ccw(x, y) <= 0) {
hull.size -= 2;
indices.size--;
}
hull.add(x);
hull.add(y);
indices.add(index);
}
// Upper hull.
for (int i = end - 4, index = i / 2, t = hull.size + 2; i >= offset; i -= 2, index--) {
float x = points[i];
float y = points[i + 1];
while (hull.size >= t && ccw(x, y) <= 0) {
hull.size -= 2;
indices.size--;
}
hull.add(x);
hull.add(y);
indices.add(index);
}
// Convert sorted to unsorted indices.
if (!sorted) {
short[] originalIndicesArray = originalIndices.items;
int[] indicesArray = indices.items;
for (int i = 0, n = indices.size; i < n; i++) indicesArray[i] = originalIndicesArray[indicesArray[i]];
}
return indices;
}
use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.
the class ConvexHull method sortWithIndices.
/** Sorts x,y pairs of values by the x value, then the y value and stores unsorted original indices.
* @param count Number of indices, must be even. */
private void sortWithIndices(float[] values, int count, boolean yDown) {
int pointCount = count / 2;
originalIndices.clear();
originalIndices.ensureCapacity(pointCount);
short[] originalIndicesArray = originalIndices.items;
for (short i = 0; i < pointCount; i++) originalIndicesArray[i] = i;
int lower = 0;
int upper = count - 1;
IntArray stack = quicksortStack;
stack.add(lower);
stack.add(upper - 1);
while (stack.size > 0) {
upper = stack.pop();
lower = stack.pop();
if (upper <= lower)
continue;
int i = quicksortPartitionWithIndices(values, lower, upper, yDown, originalIndicesArray);
if (i - lower > upper - i) {
stack.add(lower);
stack.add(i - 2);
}
stack.add(i + 2);
stack.add(upper);
if (upper - i >= i - lower) {
stack.add(lower);
stack.add(i - 2);
}
}
}
use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.
the class DelaunayTriangulator method sort.
/** Sorts x,y pairs of values by the x value.
* @param count Number of indices, must be even. */
private void sort(float[] values, int count) {
int pointCount = count / 2;
originalIndices.clear();
originalIndices.ensureCapacity(pointCount);
short[] originalIndicesArray = originalIndices.items;
for (short i = 0; i < pointCount; i++) originalIndicesArray[i] = i;
int lower = 0;
int upper = count - 1;
IntArray stack = quicksortStack;
stack.add(lower);
stack.add(upper - 1);
while (stack.size > 0) {
upper = stack.pop();
lower = stack.pop();
if (upper <= lower)
continue;
int i = quicksortPartition(values, lower, upper, originalIndicesArray);
if (i - lower > upper - i) {
stack.add(lower);
stack.add(i - 2);
}
stack.add(i + 2);
stack.add(upper);
if (upper - i >= i - lower) {
stack.add(lower);
stack.add(i - 2);
}
}
}
use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.
the class EarClippingTriangulator method computeTriangles.
/** Triangulates the given (convex or concave) simple polygon to a list of triangle vertices.
* @param vertices pairs describing vertices of the polygon, in either clockwise or counterclockwise order.
* @return triples of triangle indices in clockwise order. Note the returned array is reused for later calls to the same
* method. */
public ShortArray computeTriangles(float[] vertices, int offset, int count) {
this.vertices = vertices;
int vertexCount = this.vertexCount = count / 2;
int vertexOffset = offset / 2;
ShortArray indicesArray = this.indicesArray;
indicesArray.clear();
indicesArray.ensureCapacity(vertexCount);
indicesArray.size = vertexCount;
short[] indices = this.indices = indicesArray.items;
if (areVerticesClockwise(vertices, offset, count)) {
for (short i = 0; i < vertexCount; i++) indices[i] = (short) (vertexOffset + i);
} else {
for (int i = 0, n = vertexCount - 1; i < vertexCount; i++) // Reversed.
indices[i] = (short) (vertexOffset + n - i);
}
IntArray vertexTypes = this.vertexTypes;
vertexTypes.clear();
vertexTypes.ensureCapacity(vertexCount);
for (int i = 0, n = vertexCount; i < n; ++i) vertexTypes.add(classifyVertex(i));
// A polygon with n vertices has a triangulation of n-2 triangles.
ShortArray triangles = this.triangles;
triangles.clear();
triangles.ensureCapacity(Math.max(0, vertexCount - 2) * 3);
triangulate();
return triangles;
}
use of com.badlogic.gdx.utils.IntArray in project libgdx by libgdx.
the class ParticleControllerInfluencer method load.
@Override
public void load(AssetManager manager, ResourceData resources) {
SaveData data = resources.getSaveData();
Array<IntArray> effectsIndices = data.load("indices");
AssetDescriptor descriptor;
Iterator<IntArray> iterator = effectsIndices.iterator();
while ((descriptor = data.loadAsset()) != null) {
ParticleEffect effect = (ParticleEffect) manager.get(descriptor);
if (effect == null)
throw new RuntimeException("Template is null");
Array<ParticleController> effectControllers = effect.getControllers();
IntArray effectIndices = iterator.next();
for (int i = 0, n = effectIndices.size; i < n; i++) {
templates.add(effectControllers.get(effectIndices.get(i)));
}
}
}
Aggregations