List of usage examples for com.badlogic.gdx.utils BooleanArray removeIndex
public boolean removeIndex(int index)
From source file:com.esotericsoftware.spine.utils.Triangulator.java
License:Open Source License
public ShortArray triangulate(FloatArray verticesArray) { float[] vertices = verticesArray.items; int vertexCount = verticesArray.size >> 1; ShortArray indicesArray = this.indicesArray; indicesArray.clear();//from www. ja v a 2 s.c o m short[] indices = indicesArray.setSize(vertexCount); for (short i = 0; i < vertexCount; i++) indices[i] = i; BooleanArray isConcaveArray = this.isConcaveArray; boolean[] isConcave = isConcaveArray.setSize(vertexCount); for (int i = 0, n = vertexCount; i < n; ++i) isConcave[i] = isConcave(i, vertexCount, vertices, indices); ShortArray triangles = this.triangles; triangles.clear(); triangles.ensureCapacity(Math.max(0, vertexCount - 2) << 2); while (vertexCount > 3) { // Find ear tip. int previous = vertexCount - 1, i = 0, next = 1; while (true) { outer: if (!isConcave[i]) { int p1 = indices[previous] << 1, p2 = indices[i] << 1, p3 = indices[next] << 1; float p1x = vertices[p1], p1y = vertices[p1 + 1]; float p2x = vertices[p2], p2y = vertices[p2 + 1]; float p3x = vertices[p3], p3y = vertices[p3 + 1]; for (int ii = (next + 1) % vertexCount; ii != previous; ii = (ii + 1) % vertexCount) { if (!isConcave[ii]) continue; int v = indices[ii] << 1; float vx = vertices[v], vy = vertices[v + 1]; if (positiveArea(p3x, p3y, p1x, p1y, vx, vy)) { if (positiveArea(p1x, p1y, p2x, p2y, vx, vy)) { if (positiveArea(p2x, p2y, p3x, p3y, vx, vy)) break outer; } } } break; } if (next == 0) { do { if (!isConcave[i]) break; i--; } while (i > 0); break; } previous = i; i = next; next = (next + 1) % vertexCount; } // Cut ear tip. triangles.add(indices[(vertexCount + i - 1) % vertexCount]); triangles.add(indices[i]); triangles.add(indices[(i + 1) % vertexCount]); indicesArray.removeIndex(i); isConcaveArray.removeIndex(i); vertexCount--; int previousIndex = (vertexCount + i - 1) % vertexCount; int nextIndex = i == vertexCount ? 0 : i; isConcave[previousIndex] = isConcave(previousIndex, vertexCount, vertices, indices); isConcave[nextIndex] = isConcave(nextIndex, vertexCount, vertices, indices); } if (vertexCount == 3) { triangles.add(indices[2]); triangles.add(indices[0]); triangles.add(indices[1]); } return triangles; }