Example usage for com.badlogic.gdx.utils Array addAll

List of usage examples for com.badlogic.gdx.utils Array addAll

Introduction

In this page you can find the example usage for com.badlogic.gdx.utils Array addAll.

Prototype

public void addAll(T[] array, int offset, int length) 

Source Link

Usage

From source file:com.infunity.isometricgame.shared.utils.dermetfan.GeometryUtils.java

License:Apache License

/** @param vertices the vertices to arrange in clockwise order */
public static void arrangeClockwise(Array<Vector2> vertices) {
    // http://www.emanueleferonato.com/2011/08/05/slicing-splitting-and-cutting-objects-with-box2d-part-4-using-real-graphics
    int n = vertices.size, i1 = 1, i2 = vertices.size - 1;

    if (tmpVecArr == null || tmpVecArr.length < n)
        tmpVecArr = new Vector2[vertices.size];
    System.arraycopy(vertices.items, 0, tmpVecArr, 0, n);
    Arrays.sort(tmpVecArr, arrangeClockwiseComparator);

    tmpVecArr[0] = vertices.get(0);// w  w  w  .j  ava  2 s  . c  o  m
    Vector2 C = vertices.get(0);
    Vector2 D = vertices.get(n - 1);

    float det;
    for (int i = 1; i < n - 1; i++) {
        det = det(C.x, C.y, D.x, D.y, vertices.get(i).x, vertices.get(i).y);
        if (det < 0)
            tmpVecArr[i1++] = vertices.get(i);
        else
            tmpVecArr[i2--] = vertices.get(i);
    }

    tmpVecArr[i1] = vertices.get(n - 1);

    vertices.clear();
    vertices.addAll(tmpVecArr, 0, n);
}