package com.srbenoit.geom;

import com.srbenoit.sparsearray.SparseArray;

/**
 * An array of vectors that supports addition and deletion of vectors, but will not change the
 * index of a vector once added. That is, deleting vectors makes the array sparse, and adding new
 * vectors may fill in gaps left by deleting vectors before appending to the end of the array.
 * Storage is allocated in blocks of fixed size as needed to add vectors.
 */
public class Vector3Array extends SparseArray<Vector3Int> {

    /**
     * Constructs a new <code>Vector3Array</code> with a default capacity.
     */
    public Vector3Array() {

        this(16);
    }

    /**
     * Constructs a new <code>Vector3Array</code> with capacity for a specified number of vectors.
     * Use this constructor if you know how many vectors will ultimately be added to the array.
     *
     * @param  initialSize  the initial capacity of array to allocate
     */
    public Vector3Array(final int initialSize) {

        super(Vector3Int.class, initialSize);
    }

    /**
     * Transforms the vectors in this list into another list using a given transformation matrix.
     * It is assumed that the target array contains the same number and arrangement of vectors as
     * this list.
     *
     * @param  target     the array into which to transform the vectors
     * @param  transform  the transformation matrix
     */
    public void transformInto(final Vector3Array target, final Transform3 transform) {

        int len;

        len = capacity();

        for (int i = 0; i < len; i++) {

            if (isFilled(i)) {
                transform.transformVec(get(i), target.get(i));
            }
        }
    }
}
